Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(345)

Side by Side Diff: components/omnibox/browser/scored_history_match_unittest.cc

Issue 2541143002: Omnibox - Boost Frequency Scores Based on Number of Matching Pages (Closed)
Patch Set: improved comments and formatting Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/omnibox/browser/scored_history_match.h" 5 #include "components/omnibox/browser/scored_history_match.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // Find the first word start. 115 // Find the first word start.
116 while (iter.Advance() && !iter.IsWord()) { 116 while (iter.Advance() && !iter.IsWord()) {
117 } 117 }
118 term_word_starts[0] = iter.prev(); 118 term_word_starts[0] = iter.prev();
119 } 119 }
120 RowWordStarts row_word_starts; 120 RowWordStarts row_word_starts;
121 String16SetFromString16(url, &row_word_starts.url_word_starts_); 121 String16SetFromString16(url, &row_word_starts.url_word_starts_);
122 String16SetFromString16(title, &row_word_starts.title_word_starts_); 122 String16SetFromString16(title, &row_word_starts.title_word_starts_);
123 ScoredHistoryMatch scored_match(history::URLRow(GURL(url)), VisitInfoVector(), 123 ScoredHistoryMatch scored_match(history::URLRow(GURL(url)), VisitInfoVector(),
124 term, term_vector, term_word_starts, 124 term, term_vector, term_word_starts,
125 row_word_starts, false, base::Time::Max()); 125 row_word_starts, false, 1, base::Time::Max());
126 scored_match.url_matches = MatchTermInString(term, url, 0); 126 scored_match.url_matches = MatchTermInString(term, url, 0);
127 scored_match.title_matches = MatchTermInString(term, title, 0); 127 scored_match.title_matches = MatchTermInString(term, title, 0);
128 scored_match.topicality_threshold_ = -1; 128 scored_match.topicality_threshold_ = -1;
129 return scored_match.GetTopicalityScore(1, url, term_word_starts, 129 return scored_match.GetTopicalityScore(1, url, term_word_starts,
130 row_word_starts); 130 row_word_starts);
131 } 131 }
132 132
133 TEST_F(ScoredHistoryMatchTest, Scoring) { 133 TEST_F(ScoredHistoryMatchTest, Scoring) {
134 // We use NowFromSystemTime() because MakeURLRow uses the same function 134 // We use NowFromSystemTime() because MakeURLRow uses the same function
135 // to calculate last visit time when building a row. 135 // to calculate last visit time when building a row.
136 base::Time now = base::Time::NowFromSystemTime(); 136 base::Time now = base::Time::NowFromSystemTime();
137 137
138 history::URLRow row_a(MakeURLRow("http://fedcba", "abcd bcd", 3, 30, 1)); 138 history::URLRow row_a(MakeURLRow("http://fedcba", "abcd bcd", 3, 30, 1));
139 RowWordStarts word_starts_a; 139 RowWordStarts word_starts_a;
140 PopulateWordStarts(row_a, &word_starts_a); 140 PopulateWordStarts(row_a, &word_starts_a);
141 WordStarts one_word_no_offset(1, 0u); 141 WordStarts one_word_no_offset(1, 0u);
142 VisitInfoVector visits_a = CreateVisitInfoVector(3, 30, now); 142 VisitInfoVector visits_a = CreateVisitInfoVector(3, 30, now);
143 // Mark one visit as typed. 143 // Mark one visit as typed.
144 visits_a[0].second = ui::PAGE_TRANSITION_TYPED; 144 visits_a[0].second = ui::PAGE_TRANSITION_TYPED;
145 ScoredHistoryMatch scored_a(row_a, visits_a, ASCIIToUTF16("abc"), 145 ScoredHistoryMatch scored_a(row_a, visits_a, ASCIIToUTF16("abc"),
146 Make1Term("abc"), one_word_no_offset, 146 Make1Term("abc"), one_word_no_offset,
147 word_starts_a, false, now); 147 word_starts_a, false, 1, now);
148 148
149 // Test scores based on visit_count. 149 // Test scores based on visit_count.
150 history::URLRow row_b(MakeURLRow("http://abcdef", "abcd bcd", 10, 30, 1)); 150 history::URLRow row_b(MakeURLRow("http://abcdef", "abcd bcd", 10, 30, 1));
151 RowWordStarts word_starts_b; 151 RowWordStarts word_starts_b;
152 PopulateWordStarts(row_b, &word_starts_b); 152 PopulateWordStarts(row_b, &word_starts_b);
153 VisitInfoVector visits_b = CreateVisitInfoVector(10, 30, now); 153 VisitInfoVector visits_b = CreateVisitInfoVector(10, 30, now);
154 visits_b[0].second = ui::PAGE_TRANSITION_TYPED; 154 visits_b[0].second = ui::PAGE_TRANSITION_TYPED;
155 ScoredHistoryMatch scored_b(row_b, visits_b, ASCIIToUTF16("abc"), 155 ScoredHistoryMatch scored_b(row_b, visits_b, ASCIIToUTF16("abc"),
156 Make1Term("abc"), one_word_no_offset, 156 Make1Term("abc"), one_word_no_offset,
157 word_starts_b, false, now); 157 word_starts_b, false, 1, now);
158 EXPECT_GT(scored_b.raw_score, scored_a.raw_score); 158 EXPECT_GT(scored_b.raw_score, scored_a.raw_score);
159 159
160 // Test scores based on last_visit. 160 // Test scores based on last_visit.
161 history::URLRow row_c(MakeURLRow("http://abcdef", "abcd bcd", 3, 10, 1)); 161 history::URLRow row_c(MakeURLRow("http://abcdef", "abcd bcd", 3, 10, 1));
162 RowWordStarts word_starts_c; 162 RowWordStarts word_starts_c;
163 PopulateWordStarts(row_c, &word_starts_c); 163 PopulateWordStarts(row_c, &word_starts_c);
164 VisitInfoVector visits_c = CreateVisitInfoVector(3, 10, now); 164 VisitInfoVector visits_c = CreateVisitInfoVector(3, 10, now);
165 visits_c[0].second = ui::PAGE_TRANSITION_TYPED; 165 visits_c[0].second = ui::PAGE_TRANSITION_TYPED;
166 ScoredHistoryMatch scored_c(row_c, visits_c, ASCIIToUTF16("abc"), 166 ScoredHistoryMatch scored_c(row_c, visits_c, ASCIIToUTF16("abc"),
167 Make1Term("abc"), one_word_no_offset, 167 Make1Term("abc"), one_word_no_offset,
168 word_starts_c, false, now); 168 word_starts_c, false, 1, now);
169 EXPECT_GT(scored_c.raw_score, scored_a.raw_score); 169 EXPECT_GT(scored_c.raw_score, scored_a.raw_score);
170 170
171 // Test scores based on typed_count. 171 // Test scores based on typed_count.
172 history::URLRow row_d(MakeURLRow("http://abcdef", "abcd bcd", 3, 30, 3)); 172 history::URLRow row_d(MakeURLRow("http://abcdef", "abcd bcd", 3, 30, 3));
173 RowWordStarts word_starts_d; 173 RowWordStarts word_starts_d;
174 PopulateWordStarts(row_d, &word_starts_d); 174 PopulateWordStarts(row_d, &word_starts_d);
175 VisitInfoVector visits_d = CreateVisitInfoVector(3, 30, now); 175 VisitInfoVector visits_d = CreateVisitInfoVector(3, 30, now);
176 visits_d[0].second = ui::PAGE_TRANSITION_TYPED; 176 visits_d[0].second = ui::PAGE_TRANSITION_TYPED;
177 visits_d[1].second = ui::PAGE_TRANSITION_TYPED; 177 visits_d[1].second = ui::PAGE_TRANSITION_TYPED;
178 visits_d[2].second = ui::PAGE_TRANSITION_TYPED; 178 visits_d[2].second = ui::PAGE_TRANSITION_TYPED;
179 ScoredHistoryMatch scored_d(row_d, visits_d, ASCIIToUTF16("abc"), 179 ScoredHistoryMatch scored_d(row_d, visits_d, ASCIIToUTF16("abc"),
180 Make1Term("abc"), one_word_no_offset, 180 Make1Term("abc"), one_word_no_offset,
181 word_starts_d, false, now); 181 word_starts_d, false, 1, now);
182 EXPECT_GT(scored_d.raw_score, scored_a.raw_score); 182 EXPECT_GT(scored_d.raw_score, scored_a.raw_score);
183 183
184 // Test scores based on a terms appearing multiple times. 184 // Test scores based on a terms appearing multiple times.
185 history::URLRow row_e(MakeURLRow( 185 history::URLRow row_e(MakeURLRow(
186 "http://csi.csi.csi/csi_csi", 186 "http://csi.csi.csi/csi_csi",
187 "CSI Guide to CSI Las Vegas, CSI New York, CSI Provo", 3, 30, 3)); 187 "CSI Guide to CSI Las Vegas, CSI New York, CSI Provo", 3, 30, 3));
188 RowWordStarts word_starts_e; 188 RowWordStarts word_starts_e;
189 PopulateWordStarts(row_e, &word_starts_e); 189 PopulateWordStarts(row_e, &word_starts_e);
190 const VisitInfoVector visits_e = visits_d; 190 const VisitInfoVector visits_e = visits_d;
191 ScoredHistoryMatch scored_e(row_e, visits_e, ASCIIToUTF16("csi"), 191 ScoredHistoryMatch scored_e(row_e, visits_e, ASCIIToUTF16("csi"),
192 Make1Term("csi"), one_word_no_offset, 192 Make1Term("csi"), one_word_no_offset,
193 word_starts_e, false, now); 193 word_starts_e, false, 1, now);
194 EXPECT_LT(scored_e.raw_score, 1400); 194 EXPECT_LT(scored_e.raw_score, 1400);
195 195
196 // Test that a result with only a mid-term match (i.e., not at a word 196 // Test that a result with only a mid-term match (i.e., not at a word
197 // boundary) scores 0. 197 // boundary) scores 0.
198 ScoredHistoryMatch scored_f(row_a, visits_a, ASCIIToUTF16("cd"), 198 ScoredHistoryMatch scored_f(row_a, visits_a, ASCIIToUTF16("cd"),
199 Make1Term("cd"), one_word_no_offset, 199 Make1Term("cd"), one_word_no_offset,
200 word_starts_a, false, now); 200 word_starts_a, false, 1, now);
201 EXPECT_EQ(scored_f.raw_score, 0); 201 EXPECT_EQ(scored_f.raw_score, 0);
202 } 202 }
203 203
204 TEST_F(ScoredHistoryMatchTest, ScoringBookmarks) { 204 TEST_F(ScoredHistoryMatchTest, ScoringBookmarks) {
205 // We use NowFromSystemTime() because MakeURLRow uses the same function 205 // We use NowFromSystemTime() because MakeURLRow uses the same function
206 // to calculate last visit time when building a row. 206 // to calculate last visit time when building a row.
207 base::Time now = base::Time::NowFromSystemTime(); 207 base::Time now = base::Time::NowFromSystemTime();
208 208
209 std::string url_string("http://fedcba"); 209 std::string url_string("http://fedcba");
210 const GURL url(url_string); 210 const GURL url(url_string);
211 history::URLRow row(MakeURLRow(url_string.c_str(), "abcd bcd", 8, 3, 1)); 211 history::URLRow row(MakeURLRow(url_string.c_str(), "abcd bcd", 8, 3, 1));
212 RowWordStarts word_starts; 212 RowWordStarts word_starts;
213 PopulateWordStarts(row, &word_starts); 213 PopulateWordStarts(row, &word_starts);
214 WordStarts one_word_no_offset(1, 0u); 214 WordStarts one_word_no_offset(1, 0u);
215 VisitInfoVector visits = CreateVisitInfoVector(8, 3, now); 215 VisitInfoVector visits = CreateVisitInfoVector(8, 3, now);
216 ScoredHistoryMatch scored(row, visits, ASCIIToUTF16("abc"), Make1Term("abc"), 216 ScoredHistoryMatch scored(row, visits, ASCIIToUTF16("abc"), Make1Term("abc"),
217 one_word_no_offset, word_starts, false, now); 217 one_word_no_offset, word_starts, false, 1, now);
218 // Now check that if URL is bookmarked then its score increases. 218 // Now check that if URL is bookmarked then its score increases.
219 base::AutoReset<float> reset(&ScoredHistoryMatch::bookmark_value_, 5); 219 base::AutoReset<float> reset(&ScoredHistoryMatch::bookmark_value_, 5);
220 ScoredHistoryMatch scored_with_bookmark(row, visits, ASCIIToUTF16("abc"), 220 ScoredHistoryMatch scored_with_bookmark(row, visits, ASCIIToUTF16("abc"),
221 Make1Term("abc"), one_word_no_offset, 221 Make1Term("abc"), one_word_no_offset,
222 word_starts, true, now); 222 word_starts, true, 1, now);
223 EXPECT_GT(scored_with_bookmark.raw_score, scored.raw_score); 223 EXPECT_GT(scored_with_bookmark.raw_score, scored.raw_score);
224 } 224 }
225 225
226 TEST_F(ScoredHistoryMatchTest, ScoringTLD) { 226 TEST_F(ScoredHistoryMatchTest, ScoringTLD) {
227 // We use NowFromSystemTime() because MakeURLRow uses the same function 227 // We use NowFromSystemTime() because MakeURLRow uses the same function
228 // to calculate last visit time when building a row. 228 // to calculate last visit time when building a row.
229 base::Time now = base::Time::NowFromSystemTime(); 229 base::Time now = base::Time::NowFromSystemTime();
230 230
231 // By default the URL should not be returned for a query that includes "com". 231 // By default the URL should not be returned for a query that includes "com".
232 std::string url_string("http://fedcba.com/"); 232 std::string url_string("http://fedcba.com/");
233 const GURL url(url_string); 233 const GURL url(url_string);
234 history::URLRow row(MakeURLRow(url_string.c_str(), "", 8, 3, 1)); 234 history::URLRow row(MakeURLRow(url_string.c_str(), "", 8, 3, 1));
235 RowWordStarts word_starts; 235 RowWordStarts word_starts;
236 PopulateWordStarts(row, &word_starts); 236 PopulateWordStarts(row, &word_starts);
237 WordStarts two_words_no_offsets(2, 0u); 237 WordStarts two_words_no_offsets(2, 0u);
238 VisitInfoVector visits = CreateVisitInfoVector(8, 3, now); 238 VisitInfoVector visits = CreateVisitInfoVector(8, 3, now);
239 ScoredHistoryMatch scored(row, visits, ASCIIToUTF16("fed com"), 239 ScoredHistoryMatch scored(row, visits, ASCIIToUTF16("fed com"),
240 Make2Terms("fed", "com"), two_words_no_offsets, 240 Make2Terms("fed", "com"), two_words_no_offsets,
241 word_starts, false, now); 241 word_starts, false, 1, now);
242 EXPECT_EQ(0, scored.raw_score); 242 EXPECT_EQ(0, scored.raw_score);
243 243
244 // Now allow credit for the match in the TLD. 244 // Now allow credit for the match in the TLD.
245 base::AutoReset<bool> reset(&ScoredHistoryMatch::allow_tld_matches_, true); 245 base::AutoReset<bool> reset(&ScoredHistoryMatch::allow_tld_matches_, true);
246 ScoredHistoryMatch scored_with_tld( 246 ScoredHistoryMatch scored_with_tld(
247 row, visits, ASCIIToUTF16("fed com"), Make2Terms("fed", "com"), 247 row, visits, ASCIIToUTF16("fed com"), Make2Terms("fed", "com"),
248 two_words_no_offsets, word_starts, false, now); 248 two_words_no_offsets, word_starts, false, 1, now);
249 EXPECT_GT(scored_with_tld.raw_score, 0); 249 EXPECT_GT(scored_with_tld.raw_score, 0);
250 } 250 }
251 251
252 TEST_F(ScoredHistoryMatchTest, ScoringScheme) { 252 TEST_F(ScoredHistoryMatchTest, ScoringScheme) {
253 // We use NowFromSystemTime() because MakeURLRow uses the same function 253 // We use NowFromSystemTime() because MakeURLRow uses the same function
254 // to calculate last visit time when building a row. 254 // to calculate last visit time when building a row.
255 base::Time now = base::Time::NowFromSystemTime(); 255 base::Time now = base::Time::NowFromSystemTime();
256 256
257 // By default the URL should not be returned for a query that includes "http". 257 // By default the URL should not be returned for a query that includes "http".
258 std::string url_string("http://fedcba/"); 258 std::string url_string("http://fedcba/");
259 const GURL url(url_string); 259 const GURL url(url_string);
260 history::URLRow row(MakeURLRow(url_string.c_str(), "", 8, 3, 1)); 260 history::URLRow row(MakeURLRow(url_string.c_str(), "", 8, 3, 1));
261 RowWordStarts word_starts; 261 RowWordStarts word_starts;
262 PopulateWordStarts(row, &word_starts); 262 PopulateWordStarts(row, &word_starts);
263 WordStarts two_words_no_offsets(2, 0u); 263 WordStarts two_words_no_offsets(2, 0u);
264 VisitInfoVector visits = CreateVisitInfoVector(8, 3, now); 264 VisitInfoVector visits = CreateVisitInfoVector(8, 3, now);
265 ScoredHistoryMatch scored(row, visits, ASCIIToUTF16("fed http"), 265 ScoredHistoryMatch scored(row, visits, ASCIIToUTF16("fed http"),
266 Make2Terms("fed", "http"), two_words_no_offsets, 266 Make2Terms("fed", "http"), two_words_no_offsets,
267 word_starts, false, now); 267 word_starts, false, 1, now);
268 EXPECT_EQ(0, scored.raw_score); 268 EXPECT_EQ(0, scored.raw_score);
269 269
270 // Now allow credit for the match in the scheme. 270 // Now allow credit for the match in the scheme.
271 base::AutoReset<bool> reset(&ScoredHistoryMatch::allow_scheme_matches_, true); 271 base::AutoReset<bool> reset(&ScoredHistoryMatch::allow_scheme_matches_, true);
272 ScoredHistoryMatch scored_with_scheme( 272 ScoredHistoryMatch scored_with_scheme(
273 row, visits, ASCIIToUTF16("fed http"), Make2Terms("fed", "http"), 273 row, visits, ASCIIToUTF16("fed http"), Make2Terms("fed", "http"),
274 two_words_no_offsets, word_starts, false, now); 274 two_words_no_offsets, word_starts, false, 1, now);
275 EXPECT_GT(scored_with_scheme.raw_score, 0); 275 EXPECT_GT(scored_with_scheme.raw_score, 0);
276 } 276 }
277 277
278 TEST_F(ScoredHistoryMatchTest, Inlining) { 278 TEST_F(ScoredHistoryMatchTest, Inlining) {
279 // We use NowFromSystemTime() because MakeURLRow uses the same function 279 // We use NowFromSystemTime() because MakeURLRow uses the same function
280 // to calculate last visit time when building a row. 280 // to calculate last visit time when building a row.
281 base::Time now = base::Time::NowFromSystemTime(); 281 base::Time now = base::Time::NowFromSystemTime();
282 RowWordStarts word_starts; 282 RowWordStarts word_starts;
283 WordStarts one_word_no_offset(1, 0u); 283 WordStarts one_word_no_offset(1, 0u);
284 VisitInfoVector visits; 284 VisitInfoVector visits;
285 285
286 { 286 {
287 history::URLRow row( 287 history::URLRow row(
288 MakeURLRow("http://www.google.com", "abcdef", 3, 30, 1)); 288 MakeURLRow("http://www.google.com", "abcdef", 3, 30, 1));
289 PopulateWordStarts(row, &word_starts); 289 PopulateWordStarts(row, &word_starts);
290 ScoredHistoryMatch scored_a(row, visits, ASCIIToUTF16("g"), Make1Term("g"), 290 ScoredHistoryMatch scored_a(row, visits, ASCIIToUTF16("g"), Make1Term("g"),
291 one_word_no_offset, word_starts, false, now); 291 one_word_no_offset, word_starts, false, 1, now);
292 EXPECT_FALSE(scored_a.match_in_scheme); 292 EXPECT_FALSE(scored_a.match_in_scheme);
293 ScoredHistoryMatch scored_b(row, visits, ASCIIToUTF16("w"), Make1Term("w"), 293 ScoredHistoryMatch scored_b(row, visits, ASCIIToUTF16("w"), Make1Term("w"),
294 one_word_no_offset, word_starts, false, now); 294 one_word_no_offset, word_starts, false, 1, now);
295 EXPECT_FALSE(scored_b.match_in_scheme); 295 EXPECT_FALSE(scored_b.match_in_scheme);
296 ScoredHistoryMatch scored_c(row, visits, ASCIIToUTF16("h"), Make1Term("h"), 296 ScoredHistoryMatch scored_c(row, visits, ASCIIToUTF16("h"), Make1Term("h"),
297 one_word_no_offset, word_starts, false, now); 297 one_word_no_offset, word_starts, false, 1, now);
298 EXPECT_TRUE(scored_c.match_in_scheme); 298 EXPECT_TRUE(scored_c.match_in_scheme);
299 ScoredHistoryMatch scored_d(row, visits, ASCIIToUTF16("o"), Make1Term("o"), 299 ScoredHistoryMatch scored_d(row, visits, ASCIIToUTF16("o"), Make1Term("o"),
300 one_word_no_offset, word_starts, false, now); 300 one_word_no_offset, word_starts, false, 1, now);
301 EXPECT_FALSE(scored_d.match_in_scheme); 301 EXPECT_FALSE(scored_d.match_in_scheme);
302 } 302 }
303 303
304 { 304 {
305 history::URLRow row(MakeURLRow("http://teams.foo.com", "abcdef", 3, 30, 1)); 305 history::URLRow row(MakeURLRow("http://teams.foo.com", "abcdef", 3, 30, 1));
306 PopulateWordStarts(row, &word_starts); 306 PopulateWordStarts(row, &word_starts);
307 ScoredHistoryMatch scored_a(row, visits, ASCIIToUTF16("t"), Make1Term("t"), 307 ScoredHistoryMatch scored_a(row, visits, ASCIIToUTF16("t"), Make1Term("t"),
308 one_word_no_offset, word_starts, false, now); 308 one_word_no_offset, word_starts, false, 1, now);
309 EXPECT_FALSE(scored_a.match_in_scheme); 309 EXPECT_FALSE(scored_a.match_in_scheme);
310 ScoredHistoryMatch scored_b(row, visits, ASCIIToUTF16("f"), Make1Term("f"), 310 ScoredHistoryMatch scored_b(row, visits, ASCIIToUTF16("f"), Make1Term("f"),
311 one_word_no_offset, word_starts, false, now); 311 one_word_no_offset, word_starts, false, 1, now);
312 EXPECT_FALSE(scored_b.match_in_scheme); 312 EXPECT_FALSE(scored_b.match_in_scheme);
313 ScoredHistoryMatch scored_c(row, visits, ASCIIToUTF16("o"), Make1Term("o"), 313 ScoredHistoryMatch scored_c(row, visits, ASCIIToUTF16("o"), Make1Term("o"),
314 one_word_no_offset, word_starts, false, now); 314 one_word_no_offset, word_starts, false, 1, now);
315 EXPECT_FALSE(scored_c.match_in_scheme); 315 EXPECT_FALSE(scored_c.match_in_scheme);
316 } 316 }
317 317
318 { 318 {
319 history::URLRow row( 319 history::URLRow row(
320 MakeURLRow("https://www.testing.com", "abcdef", 3, 30, 1)); 320 MakeURLRow("https://www.testing.com", "abcdef", 3, 30, 1));
321 PopulateWordStarts(row, &word_starts); 321 PopulateWordStarts(row, &word_starts);
322 ScoredHistoryMatch scored_a(row, visits, ASCIIToUTF16("t"), Make1Term("t"), 322 ScoredHistoryMatch scored_a(row, visits, ASCIIToUTF16("t"), Make1Term("t"),
323 one_word_no_offset, word_starts, false, now); 323 one_word_no_offset, word_starts, false, 1, now);
324 EXPECT_FALSE(scored_a.match_in_scheme); 324 EXPECT_FALSE(scored_a.match_in_scheme);
325 ScoredHistoryMatch scored_b(row, visits, ASCIIToUTF16("h"), Make1Term("h"), 325 ScoredHistoryMatch scored_b(row, visits, ASCIIToUTF16("h"), Make1Term("h"),
326 one_word_no_offset, word_starts, false, now); 326 one_word_no_offset, word_starts, false, 1, now);
327 EXPECT_TRUE(scored_b.match_in_scheme); 327 EXPECT_TRUE(scored_b.match_in_scheme);
328 ScoredHistoryMatch scored_c(row, visits, ASCIIToUTF16("w"), Make1Term("w"), 328 ScoredHistoryMatch scored_c(row, visits, ASCIIToUTF16("w"), Make1Term("w"),
329 one_word_no_offset, word_starts, false, now); 329 one_word_no_offset, word_starts, false, 1, now);
330 EXPECT_FALSE(scored_c.match_in_scheme); 330 EXPECT_FALSE(scored_c.match_in_scheme);
331 } 331 }
332 332
333 { 333 {
334 history::URLRow row( 334 history::URLRow row(
335 MakeURLRow("http://www.xn--1lq90ic7f1rc.cn/xnblah", "abcd", 3, 30, 1)); 335 MakeURLRow("http://www.xn--1lq90ic7f1rc.cn/xnblah", "abcd", 3, 30, 1));
336 PopulateWordStarts(row, &word_starts); 336 PopulateWordStarts(row, &word_starts);
337 ScoredHistoryMatch scored_a(row, visits, ASCIIToUTF16("x"), Make1Term("x"), 337 ScoredHistoryMatch scored_a(row, visits, ASCIIToUTF16("x"), Make1Term("x"),
338 one_word_no_offset, word_starts, false, now); 338 one_word_no_offset, word_starts, false, 1, now);
339 EXPECT_FALSE(scored_a.match_in_scheme); 339 EXPECT_FALSE(scored_a.match_in_scheme);
340 ScoredHistoryMatch scored_b(row, visits, ASCIIToUTF16("xn"), 340 ScoredHistoryMatch scored_b(row, visits, ASCIIToUTF16("xn"),
341 Make1Term("xn"), one_word_no_offset, 341 Make1Term("xn"), one_word_no_offset,
342 word_starts, false, now); 342 word_starts, false, 1, now);
343 EXPECT_FALSE(scored_b.match_in_scheme); 343 EXPECT_FALSE(scored_b.match_in_scheme);
344 ScoredHistoryMatch scored_c(row, visits, ASCIIToUTF16("w"), Make1Term("w"), 344 ScoredHistoryMatch scored_c(row, visits, ASCIIToUTF16("w"), Make1Term("w"),
345 one_word_no_offset, word_starts, false, now); 345 one_word_no_offset, word_starts, false, 1, now);
346 EXPECT_FALSE(scored_c.match_in_scheme); 346 EXPECT_FALSE(scored_c.match_in_scheme);
347 } 347 }
348 } 348 }
349 349
350 TEST_F(ScoredHistoryMatchTest, GetTopicalityScoreTrailingSlash) { 350 TEST_F(ScoredHistoryMatchTest, GetTopicalityScoreTrailingSlash) {
351 const float hostname = GetTopicalityScoreOfTermAgainstURLAndTitle( 351 const float hostname = GetTopicalityScoreOfTermAgainstURLAndTitle(
352 ASCIIToUTF16("def"), ASCIIToUTF16("http://abc.def.com/"), 352 ASCIIToUTF16("def"), ASCIIToUTF16("http://abc.def.com/"),
353 ASCIIToUTF16("Non-Matching Title")); 353 ASCIIToUTF16("Non-Matching Title"));
354 const float hostname_no_slash = GetTopicalityScoreOfTermAgainstURLAndTitle( 354 const float hostname_no_slash = GetTopicalityScoreOfTermAgainstURLAndTitle(
355 ASCIIToUTF16("def"), ASCIIToUTF16("http://abc.def.com"), 355 ASCIIToUTF16("def"), ASCIIToUTF16("http://abc.def.com"),
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 } 474 }
475 475
476 TEST_F(ScoredHistoryMatchTest, GetFrequency) { 476 TEST_F(ScoredHistoryMatchTest, GetFrequency) {
477 // Build a fake ScoredHistoryMatch, which we'll then reuse multiple times. 477 // Build a fake ScoredHistoryMatch, which we'll then reuse multiple times.
478 history::URLRow row(GURL("http://foo")); 478 history::URLRow row(GURL("http://foo"));
479 RowWordStarts row_word_starts; 479 RowWordStarts row_word_starts;
480 PopulateWordStarts(row, &row_word_starts); 480 PopulateWordStarts(row, &row_word_starts);
481 base::Time now(base::Time::Max()); 481 base::Time now(base::Time::Max());
482 VisitInfoVector visits; 482 VisitInfoVector visits;
483 ScoredHistoryMatch match(row, visits, ASCIIToUTF16("foo"), Make1Term("foo"), 483 ScoredHistoryMatch match(row, visits, ASCIIToUTF16("foo"), Make1Term("foo"),
484 WordStarts{0}, row_word_starts, false, now); 484 WordStarts{0}, row_word_starts, false, 1, now);
485 485
486 // Record the score for one untyped visit. 486 // Record the score for one untyped visit.
487 visits = {{now, ui::PAGE_TRANSITION_LINK}}; 487 visits = {{now, ui::PAGE_TRANSITION_LINK}};
488 const float one_untyped_score = match.GetFrequency(now, false, visits); 488 const float one_untyped_score = match.GetFrequency(now, false, visits);
489 489
490 // The score for one typed visit should be larger. 490 // The score for one typed visit should be larger.
491 visits = VisitInfoVector{{now, ui::PAGE_TRANSITION_TYPED}}; 491 visits = VisitInfoVector{{now, ui::PAGE_TRANSITION_TYPED}};
492 const float one_typed_score = match.GetFrequency(now, false, visits); 492 const float one_typed_score = match.GetFrequency(now, false, visits);
493 EXPECT_GT(one_typed_score, one_untyped_score); 493 EXPECT_GT(one_typed_score, one_untyped_score);
494 494
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 EXPECT_EQ(two_visits_score_uses_sum, 574 EXPECT_EQ(two_visits_score_uses_sum,
575 match.GetFrequency(now, false, visits)); 575 match.GetFrequency(now, false, visits));
576 576
577 // Check again with the third visit being typed. 577 // Check again with the third visit being typed.
578 visits[2].second = ui::PAGE_TRANSITION_TYPED; 578 visits[2].second = ui::PAGE_TRANSITION_TYPED;
579 EXPECT_EQ(two_visits_score_uses_sum, 579 EXPECT_EQ(two_visits_score_uses_sum,
580 match.GetFrequency(now, false, visits)); 580 match.GetFrequency(now, false, visits));
581 } 581 }
582 } 582 }
583 583
584 TEST_F(ScoredHistoryMatchTest, GetDocumentSpecificityScore) {
585 // Build a fake ScoredHistoryMatch, which we'll then reuse multiple times.
586 history::URLRow row(GURL("http://foo"));
587 RowWordStarts row_word_starts;
588 PopulateWordStarts(row, &row_word_starts);
589 base::Time now(base::Time::Max());
590 VisitInfoVector visits;
591 ScoredHistoryMatch match(row, visits, ASCIIToUTF16("foo"), Make1Term("foo"),
592 WordStarts{0}, row_word_starts, false, 1, now);
593
594 EXPECT_EQ(1.0, match.GetDocumentSpecificityScore(1));
595 EXPECT_EQ(1.0, match.GetDocumentSpecificityScore(5));
596 EXPECT_EQ(1.0, match.GetDocumentSpecificityScore(50));
597
598 {
599 base::AutoReset<OmniboxFieldTrial::NumMatchesScores> tmp(
600 ScoredHistoryMatch::num_matches_to_document_specificity_score_,
601 OmniboxFieldTrial::NumMatchesScores{{1, 3.0}});
602 EXPECT_EQ(3.0, match.GetDocumentSpecificityScore(1));
603 EXPECT_EQ(1.0, match.GetDocumentSpecificityScore(5));
604 }
605
606 {
607 base::AutoReset<OmniboxFieldTrial::NumMatchesScores> tmp(
608 ScoredHistoryMatch::num_matches_to_document_specificity_score_,
609 OmniboxFieldTrial::NumMatchesScores{{1, 3.0}, {3, 1.5}});
610 EXPECT_EQ(3.0, match.GetDocumentSpecificityScore(1));
611 EXPECT_EQ(1.5, match.GetDocumentSpecificityScore(2));
612 EXPECT_EQ(1.5, match.GetDocumentSpecificityScore(3));
613 EXPECT_EQ(1.0, match.GetDocumentSpecificityScore(4));
614 }
615 }
616
584 // This function only tests scoring of single terms that match exactly 617 // This function only tests scoring of single terms that match exactly
585 // once somewhere in the URL or title. 618 // once somewhere in the URL or title.
586 TEST_F(ScoredHistoryMatchTest, GetTopicalityScore) { 619 TEST_F(ScoredHistoryMatchTest, GetTopicalityScore) {
587 base::string16 url = ASCIIToUTF16( 620 base::string16 url = ASCIIToUTF16(
588 "http://abc.def.com/path1/path2?" 621 "http://abc.def.com/path1/path2?"
589 "arg1=val1&arg2=val2#hash_component"); 622 "arg1=val1&arg2=val2#hash_component");
590 base::string16 title = ASCIIToUTF16("here is a title"); 623 base::string16 title = ASCIIToUTF16("here is a title");
591 auto Score = [&](const char* term) { 624 auto Score = [&](const char* term) {
592 return GetTopicalityScoreOfTermAgainstURLAndTitle(ASCIIToUTF16(term), url, 625 return GetTopicalityScoreOfTermAgainstURLAndTitle(ASCIIToUTF16(term), url,
593 title); 626 title);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 // hqp_relevance_buckets = "0.0:100,1.0:200,4.0:500,8.0:900,10.0:1000"; 683 // hqp_relevance_buckets = "0.0:100,1.0:200,4.0:500,8.0:900,10.0:1000";
651 std::vector<ScoredHistoryMatch::ScoreMaxRelevance> hqp_buckets; 684 std::vector<ScoredHistoryMatch::ScoreMaxRelevance> hqp_buckets;
652 hqp_buckets.push_back(std::make_pair(0.0, 100)); 685 hqp_buckets.push_back(std::make_pair(0.0, 100));
653 hqp_buckets.push_back(std::make_pair(1.0, 200)); 686 hqp_buckets.push_back(std::make_pair(1.0, 200));
654 hqp_buckets.push_back(std::make_pair(4.0, 500)); 687 hqp_buckets.push_back(std::make_pair(4.0, 500));
655 hqp_buckets.push_back(std::make_pair(8.0, 900)); 688 hqp_buckets.push_back(std::make_pair(8.0, 900));
656 hqp_buckets.push_back(std::make_pair(10.0, 1000)); 689 hqp_buckets.push_back(std::make_pair(10.0, 1000));
657 // Check when topicality score is zero. 690 // Check when topicality score is zero.
658 float topicality_score = 0.0; 691 float topicality_score = 0.0;
659 float frequency_score = 10.0; 692 float frequency_score = 10.0;
660 // intermediate_score = 0.0 * 10.0 = 0.0. 693 float specificity_score = 1.0;
694 // intermediate_score = 0.0 * 10.0 * 1.0 = 0.0.
661 EXPECT_EQ(0, ScoredHistoryMatch::GetFinalRelevancyScore( 695 EXPECT_EQ(0, ScoredHistoryMatch::GetFinalRelevancyScore(
662 topicality_score, frequency_score, hqp_buckets)); 696 topicality_score, frequency_score, specificity_score,
697 hqp_buckets));
663 698
664 // Check when intermediate score falls at the border range. 699 // Check when intermediate score falls at the border range.
665 topicality_score = 0.4f; 700 topicality_score = 0.4f;
666 frequency_score = 10.0f; 701 frequency_score = 10.0f;
667 // intermediate_score = 0.5 * 10.0 = 4.0. 702 // intermediate_score = 0.4 * 10.0 * 1.0 = 4.0.
668 EXPECT_EQ(500, ScoredHistoryMatch::GetFinalRelevancyScore( 703 EXPECT_EQ(500, ScoredHistoryMatch::GetFinalRelevancyScore(
669 topicality_score, frequency_score, hqp_buckets)); 704 topicality_score, frequency_score, specificity_score,
705 hqp_buckets));
670 706
671 // Checking the score that falls into one of the buckets. 707 // Checking the score that falls into one of the buckets.
672 topicality_score = 0.5f; 708 topicality_score = 0.5f;
673 frequency_score = 10.0f; 709 frequency_score = 10.0f;
674 // intermediate_score = 0.5 * 10.0 = 5.0. 710 // intermediate_score = 0.5 * 10.0 * 1.0 = 5.0.
675 EXPECT_EQ(600, // 500 + (((900 - 500)/(8 -4)) * 1) = 600. 711 EXPECT_EQ(
676 ScoredHistoryMatch::GetFinalRelevancyScore( 712 600, // 500 + (((900 - 500)/(8 -4)) * 1) = 600.
677 topicality_score, frequency_score, hqp_buckets)); 713 ScoredHistoryMatch::GetFinalRelevancyScore(
714 topicality_score, frequency_score, specificity_score, hqp_buckets));
678 715
679 // Never give the score greater than maximum specified. 716 // Never give the score greater than maximum specified.
680 topicality_score = 0.5f; 717 topicality_score = 0.5f;
681 frequency_score = 22.0f; 718 frequency_score = 22.0f;
682 // intermediate_score = 0.5 * 22.0 = 11.0 719 // intermediate_score = 0.5 * 22.0 * 1.0 = 11.0
683 EXPECT_EQ(1000, ScoredHistoryMatch::GetFinalRelevancyScore( 720 EXPECT_EQ(1000, ScoredHistoryMatch::GetFinalRelevancyScore(
684 topicality_score, frequency_score, hqp_buckets)); 721 topicality_score, frequency_score, specificity_score,
722 hqp_buckets));
685 } 723 }
686 724
687 // Test the function GetHQPBucketsFromString(). 725 // Test the function GetHQPBucketsFromString().
688 TEST_F(ScoredHistoryMatchTest, GetHQPBucketsFromString) { 726 TEST_F(ScoredHistoryMatchTest, GetHQPBucketsFromString) {
689 std::string buckets_str = "0.0:400,1.5:600,12.0:1300,20.0:1399"; 727 std::string buckets_str = "0.0:400,1.5:600,12.0:1300,20.0:1399";
690 std::vector<ScoredHistoryMatch::ScoreMaxRelevance> hqp_buckets; 728 std::vector<ScoredHistoryMatch::ScoreMaxRelevance> hqp_buckets;
691 729
692 EXPECT_TRUE( 730 EXPECT_TRUE(
693 ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str, &hqp_buckets)); 731 ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str, &hqp_buckets));
694 EXPECT_THAT(hqp_buckets, ElementsAre(Pair(0.0, 400), Pair(1.5, 600), 732 EXPECT_THAT(hqp_buckets, ElementsAre(Pair(0.0, 400), Pair(1.5, 600),
695 Pair(12.0, 1300), Pair(20.0, 1399))); 733 Pair(12.0, 1300), Pair(20.0, 1399)));
696 // invalid string. 734 // invalid string.
697 buckets_str = "0.0,400,1.5,600"; 735 buckets_str = "0.0,400,1.5,600";
698 EXPECT_FALSE( 736 EXPECT_FALSE(
699 ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str, &hqp_buckets)); 737 ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str, &hqp_buckets));
700 } 738 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698