1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/omnibox/browser/scored_history_match.h"
9 #include "base/auto_reset.h"
10 #include "base/bind.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string16.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 using base::ASCIIToUTF16
;
18 using testing::ElementsAre
;
23 // Returns a VisitInfoVector that includes |num_visits| spread over the
24 // last |frequency|*|num_visits| days (relative to |now|). A frequency of
25 // one means one visit each day, two means every other day, etc.
26 VisitInfoVector
CreateVisitInfoVector(int num_visits
,
29 VisitInfoVector visits
;
30 for (int i
= 0; i
< num_visits
; ++i
) {
32 std::make_pair(now
- base::TimeDelta::FromDays(i
* frequency
),
33 ui::PAGE_TRANSITION_LINK
));
40 class ScoredHistoryMatchTest
: public testing::Test
{
42 // Convenience function to create a history::URLRow with basic data for |url|,
43 // |title|, |visit_count|, and |typed_count|. |days_since_last_visit| gives
44 // the number of days ago to which to set the URL's last_visit.
45 history::URLRow
MakeURLRow(const char* url
,
48 int days_since_last_visit
,
51 // Convenience function to set the word starts information from a
52 // history::URLRow's URL and title.
53 void PopulateWordStarts(const history::URLRow
& url_row
,
54 RowWordStarts
* word_starts
);
56 // Convenience functions for easily creating vectors of search terms.
57 String16Vector
Make1Term(const char* term
) const;
58 String16Vector
Make2Terms(const char* term_1
, const char* term_2
) const;
60 // Convenience function for GetTopicalityScore() that builds the term match
61 // and word break information automatically that are needed to call
62 // GetTopicalityScore(). It only works for scoring a single term, not
64 float GetTopicalityScoreOfTermAgainstURLAndTitle(const base::string16
& term
,
65 const base::string16
& url
,
66 const base::string16
& title
);
69 history::URLRow
ScoredHistoryMatchTest::MakeURLRow(const char* url
,
72 int days_since_last_visit
,
74 history::URLRow
row(GURL(url
), 0);
75 row
.set_title(ASCIIToUTF16(title
));
76 row
.set_visit_count(visit_count
);
77 row
.set_typed_count(typed_count
);
78 row
.set_last_visit(base::Time::NowFromSystemTime() -
79 base::TimeDelta::FromDays(days_since_last_visit
));
83 void ScoredHistoryMatchTest::PopulateWordStarts(const history::URLRow
& url_row
,
84 RowWordStarts
* word_starts
) {
85 String16SetFromString16(ASCIIToUTF16(url_row
.url().spec()),
86 &word_starts
->url_word_starts_
);
87 String16SetFromString16(url_row
.title(), &word_starts
->title_word_starts_
);
90 String16Vector
ScoredHistoryMatchTest::Make1Term(const char* term
) const {
91 String16Vector original_terms
;
92 original_terms
.push_back(ASCIIToUTF16(term
));
93 return original_terms
;
96 String16Vector
ScoredHistoryMatchTest::Make2Terms(const char* term_1
,
97 const char* term_2
) const {
98 String16Vector original_terms
;
99 original_terms
.push_back(ASCIIToUTF16(term_1
));
100 original_terms
.push_back(ASCIIToUTF16(term_2
));
101 return original_terms
;
104 float ScoredHistoryMatchTest::GetTopicalityScoreOfTermAgainstURLAndTitle(
105 const base::string16
& term
,
106 const base::string16
& url
,
107 const base::string16
& title
) {
108 // Make an empty match and simply populate the fields we need in order
109 // to call GetTopicalityScore().
110 ScoredHistoryMatch scored_match
;
111 scored_match
.url_matches
= MatchTermInString(term
, url
, 0);
112 scored_match
.title_matches
= MatchTermInString(term
, title
, 0);
113 scored_match
.topicality_threshold_
= -1;
114 RowWordStarts word_starts
;
115 String16SetFromString16(url
, &word_starts
.url_word_starts_
);
116 String16SetFromString16(title
, &word_starts
.title_word_starts_
);
117 WordStarts
one_word_no_offset(1, 0u);
118 return scored_match
.GetTopicalityScore(1, url
, one_word_no_offset
,
122 TEST_F(ScoredHistoryMatchTest
, Scoring
) {
123 // We use NowFromSystemTime() because MakeURLRow uses the same function
124 // to calculate last visit time when building a row.
125 base::Time now
= base::Time::NowFromSystemTime();
127 history::URLRow
row_a(MakeURLRow("http://fedcba", "abcd bcd", 3, 30, 1));
128 RowWordStarts word_starts_a
;
129 PopulateWordStarts(row_a
, &word_starts_a
);
130 WordStarts
one_word_no_offset(1, 0u);
131 VisitInfoVector visits_a
= CreateVisitInfoVector(3, 30, now
);
132 // Mark one visit as typed.
133 visits_a
[0].second
= ui::PAGE_TRANSITION_TYPED
;
134 ScoredHistoryMatch
scored_a(row_a
, visits_a
, std::string(),
135 ASCIIToUTF16("abc"), Make1Term("abc"),
136 one_word_no_offset
, word_starts_a
, false, now
);
138 // Test scores based on visit_count.
139 history::URLRow
row_b(MakeURLRow("http://abcdef", "abcd bcd", 10, 30, 1));
140 RowWordStarts word_starts_b
;
141 PopulateWordStarts(row_b
, &word_starts_b
);
142 VisitInfoVector visits_b
= CreateVisitInfoVector(10, 30, now
);
143 visits_b
[0].second
= ui::PAGE_TRANSITION_TYPED
;
144 ScoredHistoryMatch
scored_b(row_b
, visits_b
, std::string(),
145 ASCIIToUTF16("abc"), Make1Term("abc"),
146 one_word_no_offset
, word_starts_b
, false, now
);
147 EXPECT_GT(scored_b
.raw_score
, scored_a
.raw_score
);
149 // Test scores based on last_visit.
150 history::URLRow
row_c(MakeURLRow("http://abcdef", "abcd bcd", 3, 10, 1));
151 RowWordStarts word_starts_c
;
152 PopulateWordStarts(row_c
, &word_starts_c
);
153 VisitInfoVector visits_c
= CreateVisitInfoVector(3, 10, now
);
154 visits_c
[0].second
= ui::PAGE_TRANSITION_TYPED
;
155 ScoredHistoryMatch
scored_c(row_c
, visits_c
, std::string(),
156 ASCIIToUTF16("abc"), Make1Term("abc"),
157 one_word_no_offset
, word_starts_c
, false, now
);
158 EXPECT_GT(scored_c
.raw_score
, scored_a
.raw_score
);
160 // Test scores based on typed_count.
161 history::URLRow
row_d(MakeURLRow("http://abcdef", "abcd bcd", 3, 30, 3));
162 RowWordStarts word_starts_d
;
163 PopulateWordStarts(row_d
, &word_starts_d
);
164 VisitInfoVector visits_d
= CreateVisitInfoVector(3, 30, now
);
165 visits_d
[0].second
= ui::PAGE_TRANSITION_TYPED
;
166 visits_d
[1].second
= ui::PAGE_TRANSITION_TYPED
;
167 visits_d
[2].second
= ui::PAGE_TRANSITION_TYPED
;
168 ScoredHistoryMatch
scored_d(row_d
, visits_d
, std::string(),
169 ASCIIToUTF16("abc"), Make1Term("abc"),
170 one_word_no_offset
, word_starts_d
, false, now
);
171 EXPECT_GT(scored_d
.raw_score
, scored_a
.raw_score
);
173 // Test scores based on a terms appearing multiple times.
174 history::URLRow
row_e(MakeURLRow(
175 "http://csi.csi.csi/csi_csi",
176 "CSI Guide to CSI Las Vegas, CSI New York, CSI Provo", 3, 30, 3));
177 RowWordStarts word_starts_e
;
178 PopulateWordStarts(row_e
, &word_starts_e
);
179 const VisitInfoVector visits_e
= visits_d
;
180 ScoredHistoryMatch
scored_e(row_e
, visits_e
, std::string(),
181 ASCIIToUTF16("csi"), Make1Term("csi"),
182 one_word_no_offset
, word_starts_e
, false, now
);
183 EXPECT_LT(scored_e
.raw_score
, 1400);
185 // Test that a result with only a mid-term match (i.e., not at a word
186 // boundary) scores 0.
187 ScoredHistoryMatch
scored_f(row_a
, visits_a
, std::string(),
188 ASCIIToUTF16("cd"), Make1Term("cd"),
189 one_word_no_offset
, word_starts_a
, false, now
);
190 EXPECT_EQ(scored_f
.raw_score
, 0);
193 TEST_F(ScoredHistoryMatchTest
, ScoringBookmarks
) {
194 // We use NowFromSystemTime() because MakeURLRow uses the same function
195 // to calculate last visit time when building a row.
196 base::Time now
= base::Time::NowFromSystemTime();
198 std::string
url_string("http://fedcba");
199 const GURL
url(url_string
);
200 history::URLRow
row(MakeURLRow(url_string
.c_str(), "abcd bcd", 8, 3, 1));
201 RowWordStarts word_starts
;
202 PopulateWordStarts(row
, &word_starts
);
203 WordStarts
one_word_no_offset(1, 0u);
204 VisitInfoVector visits
= CreateVisitInfoVector(8, 3, now
);
205 ScoredHistoryMatch
scored(row
, visits
, std::string(), ASCIIToUTF16("abc"),
206 Make1Term("abc"), one_word_no_offset
, word_starts
,
208 // Now check that if URL is bookmarked then its score increases.
209 base::AutoReset
<int> reset(&ScoredHistoryMatch::bookmark_value_
, 5);
210 ScoredHistoryMatch
scored_with_bookmark(
211 row
, visits
, std::string(), ASCIIToUTF16("abc"), Make1Term("abc"),
212 one_word_no_offset
, word_starts
, true, now
);
213 EXPECT_GT(scored_with_bookmark
.raw_score
, scored
.raw_score
);
216 TEST_F(ScoredHistoryMatchTest
, ScoringTLD
) {
217 // We use NowFromSystemTime() because MakeURLRow uses the same function
218 // to calculate last visit time when building a row.
219 base::Time now
= base::Time::NowFromSystemTime();
221 // By default the URL should not be returned for a query that includes "com".
222 std::string
url_string("http://fedcba.com/");
223 const GURL
url(url_string
);
224 history::URLRow
row(MakeURLRow(url_string
.c_str(), "", 8, 3, 1));
225 RowWordStarts word_starts
;
226 PopulateWordStarts(row
, &word_starts
);
227 WordStarts
two_words_no_offsets(2, 0u);
228 VisitInfoVector visits
= CreateVisitInfoVector(8, 3, now
);
229 ScoredHistoryMatch
scored(row
, visits
, std::string(), ASCIIToUTF16("fed com"),
230 Make2Terms("fed", "com"), two_words_no_offsets
,
231 word_starts
, false, now
);
232 EXPECT_EQ(0, scored
.raw_score
);
234 // Now allow credit for the match in the TLD.
235 base::AutoReset
<bool> reset(&ScoredHistoryMatch::allow_tld_matches_
, true);
236 ScoredHistoryMatch
scored_with_tld(
237 row
, visits
, std::string(), ASCIIToUTF16("fed com"),
238 Make2Terms("fed", "com"), two_words_no_offsets
, word_starts
, false, now
);
239 EXPECT_GT(scored_with_tld
.raw_score
, 0);
242 TEST_F(ScoredHistoryMatchTest
, ScoringScheme
) {
243 // We use NowFromSystemTime() because MakeURLRow uses the same function
244 // to calculate last visit time when building a row.
245 base::Time now
= base::Time::NowFromSystemTime();
247 // By default the URL should not be returned for a query that includes "http".
248 std::string
url_string("http://fedcba/");
249 const GURL
url(url_string
);
250 history::URLRow
row(MakeURLRow(url_string
.c_str(), "", 8, 3, 1));
251 RowWordStarts word_starts
;
252 PopulateWordStarts(row
, &word_starts
);
253 WordStarts
two_words_no_offsets(2, 0u);
254 VisitInfoVector visits
= CreateVisitInfoVector(8, 3, now
);
255 ScoredHistoryMatch
scored(row
, visits
, std::string(),
256 ASCIIToUTF16("fed http"), Make2Terms("fed", "http"),
257 two_words_no_offsets
, word_starts
, false, now
);
258 EXPECT_EQ(0, scored
.raw_score
);
260 // Now allow credit for the match in the scheme.
261 base::AutoReset
<bool> reset(&ScoredHistoryMatch::allow_scheme_matches_
, true);
262 ScoredHistoryMatch
scored_with_scheme(
263 row
, visits
, std::string(), ASCIIToUTF16("fed http"),
264 Make2Terms("fed", "http"), two_words_no_offsets
, word_starts
, false, now
);
265 EXPECT_GT(scored_with_scheme
.raw_score
, 0);
268 TEST_F(ScoredHistoryMatchTest
, Inlining
) {
269 // We use NowFromSystemTime() because MakeURLRow uses the same function
270 // to calculate last visit time when building a row.
271 base::Time now
= base::Time::NowFromSystemTime();
272 RowWordStarts word_starts
;
273 WordStarts
one_word_no_offset(1, 0u);
274 VisitInfoVector visits
;
278 MakeURLRow("http://www.google.com", "abcdef", 3, 30, 1));
279 PopulateWordStarts(row
, &word_starts
);
280 ScoredHistoryMatch
scored_a(row
, visits
, std::string(), ASCIIToUTF16("g"),
281 Make1Term("g"), one_word_no_offset
, word_starts
,
283 EXPECT_TRUE(scored_a
.can_inline
);
284 EXPECT_FALSE(scored_a
.match_in_scheme
);
285 ScoredHistoryMatch
scored_b(row
, visits
, std::string(), ASCIIToUTF16("w"),
286 Make1Term("w"), one_word_no_offset
, word_starts
,
288 EXPECT_TRUE(scored_b
.can_inline
);
289 EXPECT_FALSE(scored_b
.match_in_scheme
);
290 ScoredHistoryMatch
scored_c(row
, visits
, std::string(), ASCIIToUTF16("h"),
291 Make1Term("h"), one_word_no_offset
, word_starts
,
293 EXPECT_TRUE(scored_c
.can_inline
);
294 EXPECT_TRUE(scored_c
.match_in_scheme
);
295 ScoredHistoryMatch
scored_d(row
, visits
, std::string(), ASCIIToUTF16("o"),
296 Make1Term("o"), one_word_no_offset
, word_starts
,
298 EXPECT_FALSE(scored_d
.can_inline
);
299 EXPECT_FALSE(scored_d
.match_in_scheme
);
303 history::URLRow
row(MakeURLRow("http://teams.foo.com", "abcdef", 3, 30, 1));
304 PopulateWordStarts(row
, &word_starts
);
305 ScoredHistoryMatch
scored_a(row
, visits
, std::string(), ASCIIToUTF16("t"),
306 Make1Term("t"), one_word_no_offset
, word_starts
,
308 EXPECT_TRUE(scored_a
.can_inline
);
309 EXPECT_FALSE(scored_a
.match_in_scheme
);
310 ScoredHistoryMatch
scored_b(row
, visits
, std::string(), ASCIIToUTF16("f"),
311 Make1Term("f"), one_word_no_offset
, word_starts
,
313 EXPECT_FALSE(scored_b
.can_inline
);
314 EXPECT_FALSE(scored_b
.match_in_scheme
);
315 ScoredHistoryMatch
scored_c(row
, visits
, std::string(), ASCIIToUTF16("o"),
316 Make1Term("o"), one_word_no_offset
, word_starts
,
318 EXPECT_FALSE(scored_c
.can_inline
);
319 EXPECT_FALSE(scored_c
.match_in_scheme
);
324 MakeURLRow("https://www.testing.com", "abcdef", 3, 30, 1));
325 PopulateWordStarts(row
, &word_starts
);
326 ScoredHistoryMatch
scored_a(row
, visits
, std::string(), ASCIIToUTF16("t"),
327 Make1Term("t"), one_word_no_offset
, word_starts
,
329 EXPECT_TRUE(scored_a
.can_inline
);
330 EXPECT_FALSE(scored_a
.match_in_scheme
);
331 ScoredHistoryMatch
scored_b(row
, visits
, std::string(), ASCIIToUTF16("h"),
332 Make1Term("h"), one_word_no_offset
, word_starts
,
334 EXPECT_TRUE(scored_b
.can_inline
);
335 EXPECT_TRUE(scored_b
.match_in_scheme
);
336 ScoredHistoryMatch
scored_c(row
, visits
, std::string(), ASCIIToUTF16("w"),
337 Make1Term("w"), one_word_no_offset
, word_starts
,
339 EXPECT_TRUE(scored_c
.can_inline
);
340 EXPECT_FALSE(scored_c
.match_in_scheme
);
345 MakeURLRow("http://www.xn--1lq90ic7f1rc.cn/xnblah", "abcd", 3, 30, 1));
346 PopulateWordStarts(row
, &word_starts
);
347 ScoredHistoryMatch
scored_a(row
, visits
, "zh-CN", ASCIIToUTF16("x"),
348 Make1Term("x"), one_word_no_offset
, word_starts
,
350 EXPECT_FALSE(scored_a
.can_inline
);
351 EXPECT_FALSE(scored_a
.match_in_scheme
);
352 ScoredHistoryMatch
scored_b(row
, visits
, "zh-CN", ASCIIToUTF16("xn"),
353 Make1Term("xn"), one_word_no_offset
,
354 word_starts
, false, now
);
355 EXPECT_FALSE(scored_b
.can_inline
);
356 EXPECT_FALSE(scored_b
.match_in_scheme
);
357 ScoredHistoryMatch
scored_c(row
, visits
, "zh-CN", ASCIIToUTF16("w"),
358 Make1Term("w"), one_word_no_offset
,
359 word_starts
, false, now
);
360 EXPECT_TRUE(scored_c
.can_inline
);
361 EXPECT_FALSE(scored_c
.match_in_scheme
);
365 TEST_F(ScoredHistoryMatchTest
, GetTopicalityScoreTrailingSlash
) {
366 const float hostname
= GetTopicalityScoreOfTermAgainstURLAndTitle(
367 ASCIIToUTF16("def"), ASCIIToUTF16("http://abc.def.com/"),
368 ASCIIToUTF16("Non-Matching Title"));
369 const float hostname_no_slash
= GetTopicalityScoreOfTermAgainstURLAndTitle(
370 ASCIIToUTF16("def"), ASCIIToUTF16("http://abc.def.com"),
371 ASCIIToUTF16("Non-Matching Title"));
372 EXPECT_EQ(hostname_no_slash
, hostname
);
375 // This function only tests scoring of single terms that match exactly
376 // once somewhere in the URL or title.
377 TEST_F(ScoredHistoryMatchTest
, GetTopicalityScore
) {
378 base::string16 url
= ASCIIToUTF16(
379 "http://abc.def.com/path1/path2?"
380 "arg1=val1&arg2=val2#hash_component");
381 base::string16 title
= ASCIIToUTF16("here is a title");
382 const float hostname_score
= GetTopicalityScoreOfTermAgainstURLAndTitle(
383 ASCIIToUTF16("abc"), url
, title
);
384 const float hostname_mid_word_score
=
385 GetTopicalityScoreOfTermAgainstURLAndTitle(ASCIIToUTF16("bc"), url
,
387 const float domain_name_score
= GetTopicalityScoreOfTermAgainstURLAndTitle(
388 ASCIIToUTF16("def"), url
, title
);
389 const float domain_name_mid_word_score
=
390 GetTopicalityScoreOfTermAgainstURLAndTitle(ASCIIToUTF16("ef"), url
,
392 const float tld_score
= GetTopicalityScoreOfTermAgainstURLAndTitle(
393 ASCIIToUTF16("com"), url
, title
);
394 const float tld_mid_word_score
= GetTopicalityScoreOfTermAgainstURLAndTitle(
395 ASCIIToUTF16("om"), url
, title
);
396 const float path_score
= GetTopicalityScoreOfTermAgainstURLAndTitle(
397 ASCIIToUTF16("path1"), url
, title
);
398 const float path_mid_word_score
= GetTopicalityScoreOfTermAgainstURLAndTitle(
399 ASCIIToUTF16("ath1"), url
, title
);
400 const float arg_score
= GetTopicalityScoreOfTermAgainstURLAndTitle(
401 ASCIIToUTF16("arg2"), url
, title
);
402 const float arg_mid_word_score
= GetTopicalityScoreOfTermAgainstURLAndTitle(
403 ASCIIToUTF16("rg2"), url
, title
);
404 const float protocol_score
= GetTopicalityScoreOfTermAgainstURLAndTitle(
405 ASCIIToUTF16("htt"), url
, title
);
406 const float protocol_mid_word_score
=
407 GetTopicalityScoreOfTermAgainstURLAndTitle(ASCIIToUTF16("tt"), url
,
409 const float title_score
= GetTopicalityScoreOfTermAgainstURLAndTitle(
410 ASCIIToUTF16("her"), url
, title
);
411 const float title_mid_word_score
= GetTopicalityScoreOfTermAgainstURLAndTitle(
412 ASCIIToUTF16("er"), url
, title
);
413 // Verify hostname and domain name > path > arg.
414 EXPECT_GT(hostname_score
, path_score
);
415 EXPECT_GT(domain_name_score
, path_score
);
416 EXPECT_GT(path_score
, arg_score
);
417 // Verify that domain name > path and domain name > arg for non-word
419 EXPECT_GT(hostname_mid_word_score
, path_mid_word_score
);
420 EXPECT_GT(domain_name_mid_word_score
, path_mid_word_score
);
421 EXPECT_GT(domain_name_mid_word_score
, arg_mid_word_score
);
422 EXPECT_GT(hostname_mid_word_score
, arg_mid_word_score
);
423 // Also verify that the matches at non-word-boundaries all score
424 // worse than the matches at word boundaries. These three sets suffice.
425 EXPECT_GT(arg_score
, hostname_mid_word_score
);
426 EXPECT_GT(arg_score
, domain_name_mid_word_score
);
427 EXPECT_GT(title_score
, title_mid_word_score
);
428 // Check that title matches fit somewhere reasonable compared to the
429 // various types of URL matches.
430 EXPECT_GT(title_score
, arg_score
);
431 EXPECT_GT(arg_score
, title_mid_word_score
);
432 // Finally, verify that protocol matches and top level domain name
433 // matches (.com, .net, etc.) score worse than some of the mid-word
434 // matches that actually count.
435 EXPECT_GT(hostname_mid_word_score
, protocol_score
);
436 EXPECT_GT(hostname_mid_word_score
, protocol_mid_word_score
);
437 EXPECT_GT(hostname_mid_word_score
, tld_score
);
438 EXPECT_GT(hostname_mid_word_score
, tld_mid_word_score
);
441 // Test the function GetFinalRelevancyScore().
442 TEST_F(ScoredHistoryMatchTest
, GetFinalRelevancyScore
) {
443 // hqp_relevance_buckets = "0.0:100,1.0:200,4.0:500,8.0:900,10.0:1000";
444 std::vector
<ScoredHistoryMatch::ScoreMaxRelevance
> hqp_buckets
;
445 hqp_buckets
.push_back(std::make_pair(0.0, 100));
446 hqp_buckets
.push_back(std::make_pair(1.0, 200));
447 hqp_buckets
.push_back(std::make_pair(4.0, 500));
448 hqp_buckets
.push_back(std::make_pair(8.0, 900));
449 hqp_buckets
.push_back(std::make_pair(10.0, 1000));
450 // Check when topicality score is zero.
451 float topicality_score
= 0.0;
452 float frequency_score
= 10.0;
453 // intermediate_score = 0.0 * 10.0 = 0.0.
454 EXPECT_EQ(0, ScoredHistoryMatch::GetFinalRelevancyScore(
455 topicality_score
, frequency_score
, hqp_buckets
));
457 // Check when intermediate score falls at the border range.
458 topicality_score
= 0.4f
;
459 frequency_score
= 10.0f
;
460 // intermediate_score = 0.5 * 10.0 = 4.0.
461 EXPECT_EQ(500, ScoredHistoryMatch::GetFinalRelevancyScore(
462 topicality_score
, frequency_score
, hqp_buckets
));
464 // Checking the score that falls into one of the buckets.
465 topicality_score
= 0.5f
;
466 frequency_score
= 10.0f
;
467 // intermediate_score = 0.5 * 10.0 = 5.0.
468 EXPECT_EQ(600, // 500 + (((900 - 500)/(8 -4)) * 1) = 600.
469 ScoredHistoryMatch::GetFinalRelevancyScore(
470 topicality_score
, frequency_score
, hqp_buckets
));
472 // Never give the score greater than maximum specified.
473 topicality_score
= 0.5f
;
474 frequency_score
= 22.0f
;
475 // intermediate_score = 0.5 * 22.0 = 11.0
476 EXPECT_EQ(1000, ScoredHistoryMatch::GetFinalRelevancyScore(
477 topicality_score
, frequency_score
, hqp_buckets
));
480 // Test the function GetHQPBucketsFromString().
481 TEST_F(ScoredHistoryMatchTest
, GetHQPBucketsFromString
) {
482 std::string buckets_str
= "0.0:400,1.5:600,12.0:1300,20.0:1399";
483 std::vector
<ScoredHistoryMatch::ScoreMaxRelevance
> hqp_buckets
;
486 ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str
, &hqp_buckets
));
487 EXPECT_THAT(hqp_buckets
, ElementsAre(Pair(0.0, 400), Pair(1.5, 600),
488 Pair(12.0, 1300), Pair(20.0, 1399)));
490 buckets_str
= "0.0,400,1.5,600";
492 ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str
, &hqp_buckets
));