Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/autocomplete/search_provider.h" | 5 #include "chrome/browser/autocomplete/search_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 if (i.IsWord()) { | 95 if (i.IsWord()) { |
| 96 if (found_word) | 96 if (found_word) |
| 97 return true; | 97 return true; |
| 98 found_word = true; | 98 found_word = true; |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 return false; | 102 return false; |
| 103 } | 103 } |
| 104 | 104 |
| 105 // Builds the match contents and classification for the contents, and updates | |
|
Mark P
2014/01/04 00:26:17
This function moved to CalculateContentsClass() wi
| |
| 106 // the given |AutocompleteMatch|. | |
| 107 void SetAndClassifyMatchContents(const base::string16& query_string, | |
| 108 const base::string16& input_text, | |
| 109 const base::string16& match_contents, | |
| 110 AutocompleteMatch* match) { | |
| 111 match->contents = match_contents.empty() ? query_string : match_contents; | |
| 112 | |
| 113 // We do intra-string highlighting for suggestions - the suggested segment | |
| 114 // will be highlighted, e.g. for input_text = "you" the suggestion may be | |
| 115 // "youtube", so we'll bold the "tube" section: you*tube*. | |
| 116 if (input_text != match_contents) { | |
| 117 size_t input_position = match->contents.find(input_text); | |
| 118 if (input_position == base::string16::npos) { | |
| 119 // The input text is not a substring of the query string, e.g. input | |
| 120 // text is "slasdot" and the query string is "slashdot", so we bold the | |
| 121 // whole thing. | |
| 122 match->contents_class.push_back(ACMatchClassification( | |
| 123 0, ACMatchClassification::MATCH)); | |
| 124 } else { | |
| 125 // TODO(beng): ACMatchClassification::MATCH now seems to just mean | |
| 126 // "bold" this. Consider modifying the terminology. | |
| 127 // We don't iterate over the string here annotating all matches because | |
| 128 // it looks odd to have every occurrence of a substring that may be as | |
| 129 // short as a single character highlighted in a query suggestion result, | |
| 130 // e.g. for input text "s" and query string "southwest airlines", it | |
| 131 // looks odd if both the first and last s are highlighted. | |
| 132 if (input_position != 0) { | |
| 133 match->contents_class.push_back(ACMatchClassification( | |
| 134 0, ACMatchClassification::MATCH)); | |
| 135 } | |
| 136 match->contents_class.push_back( | |
| 137 ACMatchClassification(input_position, ACMatchClassification::NONE)); | |
| 138 size_t next_fragment_position = input_position + input_text.length(); | |
| 139 if (next_fragment_position < query_string.length()) { | |
| 140 match->contents_class.push_back(ACMatchClassification( | |
| 141 next_fragment_position, ACMatchClassification::MATCH)); | |
| 142 } | |
| 143 } | |
| 144 } else { | |
| 145 // Otherwise, |match| is a verbatim (what-you-typed) match, either for the | |
| 146 // default provider or a keyword search provider. | |
| 147 match->contents_class.push_back(ACMatchClassification( | |
| 148 0, ACMatchClassification::NONE)); | |
| 149 } | |
| 150 } | |
| 151 | |
| 152 AutocompleteMatchType::Type GetAutocompleteMatchType(const std::string& type) { | 105 AutocompleteMatchType::Type GetAutocompleteMatchType(const std::string& type) { |
| 153 if (type == "ENTITY") | 106 if (type == "ENTITY") |
| 154 return AutocompleteMatchType::SEARCH_SUGGEST_ENTITY; | 107 return AutocompleteMatchType::SEARCH_SUGGEST_ENTITY; |
| 155 if (type == "INFINITE") | 108 if (type == "INFINITE") |
| 156 return AutocompleteMatchType::SEARCH_SUGGEST_INFINITE; | 109 return AutocompleteMatchType::SEARCH_SUGGEST_INFINITE; |
| 157 if (type == "PERSONALIZED") | 110 if (type == "PERSONALIZED") |
| 158 return AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED; | 111 return AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED; |
| 159 if (type == "PROFILE") | 112 if (type == "PROFILE") |
| 160 return AutocompleteMatchType::SEARCH_SUGGEST_PROFILE; | 113 return AutocompleteMatchType::SEARCH_SUGGEST_PROFILE; |
| 161 return AutocompleteMatchType::SEARCH_SUGGEST; | 114 return AutocompleteMatchType::SEARCH_SUGGEST; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 SearchProvider::SuggestResult::SuggestResult( | 208 SearchProvider::SuggestResult::SuggestResult( |
| 256 const base::string16& suggestion, | 209 const base::string16& suggestion, |
| 257 AutocompleteMatchType::Type type, | 210 AutocompleteMatchType::Type type, |
| 258 const base::string16& match_contents, | 211 const base::string16& match_contents, |
| 259 const base::string16& annotation, | 212 const base::string16& annotation, |
| 260 const std::string& suggest_query_params, | 213 const std::string& suggest_query_params, |
| 261 const std::string& deletion_url, | 214 const std::string& deletion_url, |
| 262 bool from_keyword_provider, | 215 bool from_keyword_provider, |
| 263 int relevance, | 216 int relevance, |
| 264 bool relevance_from_server, | 217 bool relevance_from_server, |
| 265 bool should_prefetch) | 218 bool should_prefetch, |
| 219 const base::string16& input_text) | |
| 266 : Result(from_keyword_provider, relevance, relevance_from_server), | 220 : Result(from_keyword_provider, relevance, relevance_from_server), |
| 267 suggestion_(suggestion), | 221 suggestion_(suggestion), |
| 268 type_(type), | 222 type_(type), |
| 269 match_contents_(match_contents), | 223 match_contents_(match_contents), |
| 270 annotation_(annotation), | 224 annotation_(annotation), |
| 271 suggest_query_params_(suggest_query_params), | 225 suggest_query_params_(suggest_query_params), |
| 272 deletion_url_(deletion_url), | 226 deletion_url_(deletion_url), |
| 273 should_prefetch_(should_prefetch) { | 227 should_prefetch_(should_prefetch) { |
| 228 DCHECK(!match_contents_.empty()); | |
| 229 CalculateContentsClass(true, input_text); | |
| 274 } | 230 } |
| 275 | 231 |
| 276 SearchProvider::SuggestResult::~SuggestResult() { | 232 SearchProvider::SuggestResult::~SuggestResult() { |
| 277 } | 233 } |
| 278 | 234 |
| 235 void SearchProvider::SuggestResult::CalculateContentsClass( | |
| 236 const bool allow_bolding_all, | |
| 237 const base::string16& input_text) { | |
| 238 size_t input_position = match_contents_.find(input_text); | |
| 239 if (!allow_bolding_all && (input_text != match_contents_) && | |
|
msw
2014/01/06 21:09:00
nit: remove the unnecessary input_text != match_co
Mark P
2014/01/06 22:20:16
Right you are. Done.
| |
| 240 (input_position == base::string16::npos)) { | |
| 241 // Bail if the code below to update the bolding would bold the whole | |
| 242 // string. Note that the string may already be entirely bolded; if | |
| 243 // so, leave it as is. | |
| 244 return; | |
| 245 } | |
| 246 match_contents_class_.clear(); | |
| 247 // We do intra-string highlighting for suggestions - the suggested segment | |
| 248 // will be highlighted, e.g. for input_text = "you" the suggestion may be | |
| 249 // "youtube", so we'll bold the "tube" section: you*tube*. | |
| 250 if (input_text != match_contents_) { | |
| 251 size_t input_position = match_contents_.find(input_text); | |
|
msw
2014/01/06 21:09:00
Remove this, use the above duplicated identifier..
Mark P
2014/01/06 22:20:16
Stupid resolve error re-introduced this. I had it
| |
| 252 if (input_position == base::string16::npos) { | |
| 253 // The input text is not a substring of the query string, e.g. input | |
| 254 // text is "slasdot" and the query string is "slashdot", so we bold the | |
| 255 // whole thing. | |
| 256 match_contents_class_.push_back(ACMatchClassification( | |
| 257 0, ACMatchClassification::MATCH)); | |
| 258 } else { | |
| 259 // TODO(beng): ACMatchClassification::MATCH now seems to just mean | |
| 260 // "bold" this. Consider modifying the terminology. | |
| 261 // We don't iterate over the string here annotating all matches because | |
| 262 // it looks odd to have every occurrence of a substring that may be as | |
| 263 // short as a single character highlighted in a query suggestion result, | |
| 264 // e.g. for input text "s" and query string "southwest airlines", it | |
| 265 // looks odd if both the first and last s are highlighted. | |
| 266 if (input_position != 0) { | |
| 267 match_contents_class_.push_back(ACMatchClassification( | |
| 268 0, ACMatchClassification::MATCH)); | |
| 269 } | |
| 270 match_contents_class_.push_back( | |
| 271 ACMatchClassification(input_position, ACMatchClassification::NONE)); | |
| 272 size_t next_fragment_position = input_position + input_text.length(); | |
| 273 if (next_fragment_position < match_contents_.length()) { | |
| 274 match_contents_class_.push_back(ACMatchClassification( | |
| 275 next_fragment_position, ACMatchClassification::MATCH)); | |
| 276 } | |
| 277 } | |
| 278 } else { | |
| 279 // Otherwise, match_contents_ is a verbatim (what-you-typed) match, either | |
| 280 // for the default provider or a keyword search provider. | |
| 281 match_contents_class_.push_back(ACMatchClassification( | |
| 282 0, ACMatchClassification::NONE)); | |
| 283 } | |
| 284 } | |
| 285 | |
| 279 bool SearchProvider::SuggestResult::IsInlineable( | 286 bool SearchProvider::SuggestResult::IsInlineable( |
| 280 const base::string16& input) const { | 287 const base::string16& input) const { |
| 281 return StartsWith(suggestion_, input, false); | 288 return StartsWith(suggestion_, input, false); |
| 282 } | 289 } |
| 283 | 290 |
| 284 int SearchProvider::SuggestResult::CalculateRelevance( | 291 int SearchProvider::SuggestResult::CalculateRelevance( |
| 285 const AutocompleteInput& input, | 292 const AutocompleteInput& input, |
| 286 bool keyword_provider_requested) const { | 293 bool keyword_provider_requested) const { |
| 287 if (!from_keyword_provider_ && keyword_provider_requested) | 294 if (!from_keyword_provider_ && keyword_provider_requested) |
| 288 return 100; | 295 return 100; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 const TemplateURL* template_url, | 410 const TemplateURL* template_url, |
| 404 int accepted_suggestion, | 411 int accepted_suggestion, |
| 405 int omnibox_start_margin, | 412 int omnibox_start_margin, |
| 406 bool append_extra_query_params) { | 413 bool append_extra_query_params) { |
| 407 AutocompleteMatch match(autocomplete_provider, suggestion.relevance(), false, | 414 AutocompleteMatch match(autocomplete_provider, suggestion.relevance(), false, |
| 408 suggestion.type()); | 415 suggestion.type()); |
| 409 | 416 |
| 410 if (!template_url) | 417 if (!template_url) |
| 411 return match; | 418 return match; |
| 412 match.keyword = template_url->keyword(); | 419 match.keyword = template_url->keyword(); |
| 413 | 420 |
|
msw
2014/01/06 21:09:00
nit: remove blank line (or swap with line above.)
Mark P
2014/01/06 22:20:16
Done.
| |
| 414 SetAndClassifyMatchContents(suggestion.suggestion(), input_text, | 421 match.contents = suggestion.match_contents(); |
| 415 suggestion.match_contents(), &match); | 422 match.contents_class = suggestion.match_contents_class(); |
| 416 | 423 |
| 417 if (!suggestion.annotation().empty()) | 424 if (!suggestion.annotation().empty()) |
| 418 match.description = suggestion.annotation(); | 425 match.description = suggestion.annotation(); |
| 419 | 426 |
| 420 match.allowed_to_be_default_match = | 427 match.allowed_to_be_default_match = |
| 421 (input_text == suggestion.match_contents()); | 428 (input_text == suggestion.match_contents()); |
| 422 | 429 |
| 423 // When the user forced a query, we need to make sure all the fill_into_edit | 430 // When the user forced a query, we need to make sure all the fill_into_edit |
| 424 // values preserve that property. Otherwise, if the user starts editing a | 431 // values preserve that property. Otherwise, if the user starts editing a |
| 425 // suggestion, non-Search results will suddenly appear. | 432 // suggestion, non-Search results will suddenly appear. |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 563 } else { | 570 } else { |
| 564 // The current top result is a navigational suggestion. | 571 // The current top result is a navigational suggestion. |
| 565 if (nav_it->IsInlineable(input)) | 572 if (nav_it->IsInlineable(input)) |
| 566 break; | 573 break; |
| 567 nav_it = navigation_results->erase(nav_it); | 574 nav_it = navigation_results->erase(nav_it); |
| 568 } | 575 } |
| 569 } | 576 } |
| 570 } | 577 } |
| 571 | 578 |
| 572 // static | 579 // static |
| 580 void SearchProvider::RecalculateBolding( | |
| 581 const base::string16& input_text, SuggestResults* suggest_results) { | |
|
msw
2014/01/06 21:09:00
nit: one param per line.
Mark P
2014/01/06 22:20:16
Done.
| |
| 582 for (SuggestResults::iterator sug_it = suggest_results->begin(); | |
| 583 sug_it != suggest_results->end(); ++sug_it) { | |
| 584 sug_it->CalculateContentsClass(false, input_text); | |
| 585 } | |
| 586 } | |
| 587 | |
| 588 // static | |
| 573 int SearchProvider::CalculateRelevanceForKeywordVerbatim( | 589 int SearchProvider::CalculateRelevanceForKeywordVerbatim( |
| 574 AutocompleteInput::Type type, | 590 AutocompleteInput::Type type, |
| 575 bool prefer_keyword) { | 591 bool prefer_keyword) { |
| 576 // This function is responsible for scoring verbatim query matches | 592 // This function is responsible for scoring verbatim query matches |
| 577 // for non-extension keywords. KeywordProvider::CalculateRelevance() | 593 // for non-extension keywords. KeywordProvider::CalculateRelevance() |
| 578 // scores verbatim query matches for extension keywords, as well as | 594 // scores verbatim query matches for extension keywords, as well as |
| 579 // for keyword matches (i.e., suggestions of a keyword itself, not a | 595 // for keyword matches (i.e., suggestions of a keyword itself, not a |
| 580 // suggestion of a query on a keyword search engine). These two | 596 // suggestion of a query on a keyword search engine). These two |
| 581 // functions are currently in sync, but there's no reason we | 597 // functions are currently in sync, but there's no reason we |
| 582 // couldn't decide in the future to score verbatim matches | 598 // couldn't decide in the future to score verbatim matches |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 868 (!done_ && | 884 (!done_ && |
| 869 input_.matches_requested() == AutocompleteInput::ALL_MATCHES))) | 885 input_.matches_requested() == AutocompleteInput::ALL_MATCHES))) |
| 870 return; | 886 return; |
| 871 | 887 |
| 872 // We can't keep running any previous query, so halt it. | 888 // We can't keep running any previous query, so halt it. |
| 873 StopSuggest(); | 889 StopSuggest(); |
| 874 | 890 |
| 875 // Remove existing results that cannot inline autocomplete the new input. | 891 // Remove existing results that cannot inline autocomplete the new input. |
| 876 RemoveAllStaleResults(); | 892 RemoveAllStaleResults(); |
| 877 | 893 |
| 894 // Revise the bolding of suggest results that remain so they look good against | |
|
msw
2014/01/06 21:09:00
nit: consider "Update the content and classificati
Mark P
2014/01/06 22:20:16
Done.
| |
| 895 // the current input. | |
| 896 RecalculateBolding(input_.text(), &default_results_.suggest_results); | |
| 897 if (!keyword_input_.text().empty()) { | |
| 898 RecalculateBolding(keyword_input_.text(), | |
| 899 &keyword_results_.suggest_results); | |
| 900 } | |
| 901 | |
| 878 // We can't start a new query if we're only allowed synchronous results. | 902 // We can't start a new query if we're only allowed synchronous results. |
| 879 if (input_.matches_requested() != AutocompleteInput::ALL_MATCHES) | 903 if (input_.matches_requested() != AutocompleteInput::ALL_MATCHES) |
| 880 return; | 904 return; |
| 881 | 905 |
| 882 // To avoid flooding the suggest server, don't send a query until at | 906 // To avoid flooding the suggest server, don't send a query until at |
| 883 // least 100 ms since the last query. | 907 // least 100 ms since the last query. |
| 884 base::TimeTicks next_suggest_time(time_suggest_request_sent_ + | 908 base::TimeTicks next_suggest_time(time_suggest_request_sent_ + |
| 885 base::TimeDelta::FromMilliseconds(kMinimumTimeBetweenSuggestQueriesMs)); | 909 base::TimeDelta::FromMilliseconds(kMinimumTimeBetweenSuggestQueriesMs)); |
| 886 base::TimeTicks now(base::TimeTicks::Now()); | 910 base::TimeTicks now(base::TimeTicks::Now()); |
| 887 if (now >= next_suggest_time) { | 911 if (now >= next_suggest_time) { |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1195 if (suggestion_detail) { | 1219 if (suggestion_detail) { |
| 1196 suggestion_detail->GetString("du", &deletion_url); | 1220 suggestion_detail->GetString("du", &deletion_url); |
| 1197 suggestion_detail->GetString("title", &match_contents) || | 1221 suggestion_detail->GetString("title", &match_contents) || |
| 1198 suggestion_detail->GetString("t", &match_contents); | 1222 suggestion_detail->GetString("t", &match_contents); |
| 1199 suggestion_detail->GetString("annotation", &annotation) || | 1223 suggestion_detail->GetString("annotation", &annotation) || |
| 1200 suggestion_detail->GetString("a", &annotation); | 1224 suggestion_detail->GetString("a", &annotation); |
| 1201 suggestion_detail->GetString("query_params", &suggest_query_params) || | 1225 suggestion_detail->GetString("query_params", &suggest_query_params) || |
| 1202 suggestion_detail->GetString("q", &suggest_query_params); | 1226 suggestion_detail->GetString("q", &suggest_query_params); |
| 1203 } | 1227 } |
| 1204 } | 1228 } |
| 1229 // Error correction for bad data from server. | |
|
msw
2014/01/06 21:09:00
|match_contents| was already initialized with |sug
Mark P
2014/01/06 22:20:16
I plan to talk to anuj about this because he's the
msw
2014/01/06 22:50:21
Keeping the workaround to fixup the broken |sugges
Mark P
2014/01/07 19:10:30
Moved the correcting assignment in the block, as y
| |
| 1230 if (match_contents.empty()) | |
| 1231 match_contents = suggestion; | |
| 1205 | 1232 |
| 1206 // TODO(kochi): Improve calculator suggestion presentation. | 1233 // TODO(kochi): Improve calculator suggestion presentation. |
| 1207 results->suggest_results.push_back(SuggestResult( | 1234 results->suggest_results.push_back(SuggestResult( |
| 1208 suggestion, match_type, match_contents, annotation, | 1235 suggestion, match_type, match_contents, annotation, |
| 1209 suggest_query_params, deletion_url, is_keyword, relevance, true, | 1236 suggest_query_params, deletion_url, is_keyword, relevance, true, |
| 1210 should_prefetch)); | 1237 should_prefetch, input_text)); |
| 1211 } | 1238 } |
| 1212 } | 1239 } |
| 1213 | 1240 |
| 1214 // Ignore suggested scores for non-keyword matches in keyword mode; if the | 1241 // Ignore suggested scores for non-keyword matches in keyword mode; if the |
| 1215 // server is allowed to score these, it could interfere with the user's | 1242 // server is allowed to score these, it could interfere with the user's |
| 1216 // ability to get good keyword results. | 1243 // ability to get good keyword results. |
| 1217 const bool abandon_suggested_scores = | 1244 const bool abandon_suggested_scores = |
| 1218 !is_keyword && !providers_.keyword_provider().empty(); | 1245 !is_keyword && !providers_.keyword_provider().empty(); |
| 1219 // Apply calculated relevance scores to suggestions if a valid list was | 1246 // Apply calculated relevance scores to suggestions if a valid list was |
| 1220 // not provided or we're abandoning suggested scores entirely. | 1247 // not provided or we're abandoning suggested scores entirely. |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 1250 | 1277 |
| 1251 bool relevance_from_server; | 1278 bool relevance_from_server; |
| 1252 int verbatim_relevance = GetVerbatimRelevance(&relevance_from_server); | 1279 int verbatim_relevance = GetVerbatimRelevance(&relevance_from_server); |
| 1253 int did_not_accept_default_suggestion = | 1280 int did_not_accept_default_suggestion = |
| 1254 default_results_.suggest_results.empty() ? | 1281 default_results_.suggest_results.empty() ? |
| 1255 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : | 1282 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : |
| 1256 TemplateURLRef::NO_SUGGESTION_CHOSEN; | 1283 TemplateURLRef::NO_SUGGESTION_CHOSEN; |
| 1257 if (verbatim_relevance > 0) { | 1284 if (verbatim_relevance > 0) { |
| 1258 SuggestResult verbatim( | 1285 SuggestResult verbatim( |
| 1259 input_.text(), AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 1286 input_.text(), AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, |
| 1260 input_.text(), base::string16(), std::string(), std::string(), | 1287 input_.text(), base::string16(), std::string(), std::string(), false, |
| 1261 false, verbatim_relevance, relevance_from_server, false); | 1288 verbatim_relevance, relevance_from_server, false, input_.text()); |
| 1262 AddMatchToMap(verbatim, input_.text(), std::string(), | 1289 AddMatchToMap(verbatim, input_.text(), std::string(), |
| 1263 did_not_accept_default_suggestion, &map); | 1290 did_not_accept_default_suggestion, &map); |
| 1264 } | 1291 } |
| 1265 if (!keyword_input_.text().empty()) { | 1292 if (!keyword_input_.text().empty()) { |
| 1266 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); | 1293 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); |
| 1267 // We only create the verbatim search query match for a keyword | 1294 // We only create the verbatim search query match for a keyword |
| 1268 // if it's not an extension keyword. Extension keywords are handled | 1295 // if it's not an extension keyword. Extension keywords are handled |
| 1269 // in KeywordProvider::Start(). (Extensions are complicated...) | 1296 // in KeywordProvider::Start(). (Extensions are complicated...) |
| 1270 // Note: in this provider, SEARCH_OTHER_ENGINE must correspond | 1297 // Note: in this provider, SEARCH_OTHER_ENGINE must correspond |
| 1271 // to the keyword verbatim search query. Do not create other matches | 1298 // to the keyword verbatim search query. Do not create other matches |
| 1272 // of type SEARCH_OTHER_ENGINE. | 1299 // of type SEARCH_OTHER_ENGINE. |
| 1273 if (keyword_url && | 1300 if (keyword_url && |
| 1274 (keyword_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION)) { | 1301 (keyword_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION)) { |
| 1275 bool keyword_relevance_from_server; | 1302 bool keyword_relevance_from_server; |
| 1276 const int keyword_verbatim_relevance = | 1303 const int keyword_verbatim_relevance = |
| 1277 GetKeywordVerbatimRelevance(&keyword_relevance_from_server); | 1304 GetKeywordVerbatimRelevance(&keyword_relevance_from_server); |
| 1278 if (keyword_verbatim_relevance > 0) { | 1305 if (keyword_verbatim_relevance > 0) { |
| 1279 SuggestResult verbatim( | 1306 SuggestResult verbatim( |
| 1280 keyword_input_.text(), AutocompleteMatchType::SEARCH_OTHER_ENGINE, | 1307 keyword_input_.text(), AutocompleteMatchType::SEARCH_OTHER_ENGINE, |
| 1281 keyword_input_.text(), base::string16(), std::string(), | 1308 keyword_input_.text(), base::string16(), std::string(), |
| 1282 std::string(), true, keyword_verbatim_relevance, | 1309 std::string(), true, keyword_verbatim_relevance, |
| 1283 keyword_relevance_from_server, false); | 1310 keyword_relevance_from_server, false, keyword_input_.text()); |
| 1284 AddMatchToMap(verbatim, keyword_input_.text(), std::string(), | 1311 AddMatchToMap(verbatim, keyword_input_.text(), std::string(), |
| 1285 did_not_accept_keyword_suggestion, &map); | 1312 did_not_accept_keyword_suggestion, &map); |
| 1286 } | 1313 } |
| 1287 } | 1314 } |
| 1288 } | 1315 } |
| 1289 AddHistoryResultsToMap(keyword_history_results_, true, | 1316 AddHistoryResultsToMap(keyword_history_results_, true, |
| 1290 did_not_accept_keyword_suggestion, &map); | 1317 did_not_accept_keyword_suggestion, &map); |
| 1291 AddHistoryResultsToMap(default_history_results_, false, | 1318 AddHistoryResultsToMap(default_history_results_, false, |
| 1292 did_not_accept_default_suggestion, &map); | 1319 did_not_accept_default_suggestion, &map); |
| 1293 | 1320 |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1623 prevent_inline_autocomplete = | 1650 prevent_inline_autocomplete = |
| 1624 !AutocompleteMatch::IsSearchType(match.type); | 1651 !AutocompleteMatch::IsSearchType(match.type); |
| 1625 } | 1652 } |
| 1626 | 1653 |
| 1627 int relevance = CalculateRelevanceForHistory( | 1654 int relevance = CalculateRelevanceForHistory( |
| 1628 i->time, is_keyword, !prevent_inline_autocomplete, | 1655 i->time, is_keyword, !prevent_inline_autocomplete, |
| 1629 prevent_search_history_inlining); | 1656 prevent_search_history_inlining); |
| 1630 scored_results.push_back(SuggestResult( | 1657 scored_results.push_back(SuggestResult( |
| 1631 i->term, AutocompleteMatchType::SEARCH_HISTORY, i->term, | 1658 i->term, AutocompleteMatchType::SEARCH_HISTORY, i->term, |
| 1632 base::string16(), std::string(), std::string(), is_keyword, relevance, | 1659 base::string16(), std::string(), std::string(), is_keyword, relevance, |
| 1633 false, false)); | 1660 false, false, input_text)); |
| 1634 } | 1661 } |
| 1635 | 1662 |
| 1636 // History returns results sorted for us. However, we may have docked some | 1663 // History returns results sorted for us. However, we may have docked some |
| 1637 // results' scores, so things are no longer in order. Do a stable sort to get | 1664 // results' scores, so things are no longer in order. Do a stable sort to get |
| 1638 // things back in order without otherwise disturbing results with equal | 1665 // things back in order without otherwise disturbing results with equal |
| 1639 // scores, then force the scores to be unique, so that the order in which | 1666 // scores, then force the scores to be unique, so that the order in which |
| 1640 // they're shown is deterministic. | 1667 // they're shown is deterministic. |
| 1641 std::stable_sort(scored_results.begin(), scored_results.end(), | 1668 std::stable_sort(scored_results.begin(), scored_results.end(), |
| 1642 CompareScoredResults()); | 1669 CompareScoredResults()); |
| 1643 int last_relevance = 0; | 1670 int last_relevance = 0; |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2035 if (!OmniboxFieldTrial::InZeroSuggestFieldTrial() || | 2062 if (!OmniboxFieldTrial::InZeroSuggestFieldTrial() || |
| 2036 service == NULL || | 2063 service == NULL || |
| 2037 !service->IsSyncEnabledAndLoggedIn() || | 2064 !service->IsSyncEnabledAndLoggedIn() || |
| 2038 !sync_prefs.GetPreferredDataTypes(syncer::UserTypes()).Has( | 2065 !sync_prefs.GetPreferredDataTypes(syncer::UserTypes()).Has( |
| 2039 syncer::PROXY_TABS) || | 2066 syncer::PROXY_TABS) || |
| 2040 service->GetEncryptedDataTypes().Has(syncer::SESSIONS)) | 2067 service->GetEncryptedDataTypes().Has(syncer::SESSIONS)) |
| 2041 return false; | 2068 return false; |
| 2042 | 2069 |
| 2043 return true; | 2070 return true; |
| 2044 } | 2071 } |
| OLD | NEW |