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

Side by Side Diff: chrome/browser/autocomplete/search_provider.cc

Issue 58003005: Modify Entity Suggestion support and Add Profile Suggest support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 1 month 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 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 94 }
95 } 95 }
96 } 96 }
97 return false; 97 return false;
98 } 98 }
99 99
100 // Builds the match contents and classification for the contents, and updates 100 // Builds the match contents and classification for the contents, and updates
101 // the given |AutocompleteMatch|. 101 // the given |AutocompleteMatch|.
102 void SetAndClassifyMatchContents(const string16& query_string, 102 void SetAndClassifyMatchContents(const string16& query_string,
103 const string16& input_text, 103 const string16& input_text,
104 const string16& match_contents, 104 const string16& title,
105 const string16& annotation, 105 const ACMatchClassifications& title_class,
106 AutocompleteMatch* match) { 106 AutocompleteMatch* match) {
107 size_t match_contents_start = 0; 107 if (title.empty()) {
108 size_t annotation_start = match_contents.size(); 108 match->contents = query_string;
109 // Append annotation if present.
110 if (annotation.empty()) {
111 match->contents = match_contents;
112 } else { 109 } else {
113 std::vector<size_t> positions; 110 match->contents = title;
114 match->contents = l10n_util::GetStringFUTF16( 111 if (!title_class.empty()) {
115 IDS_ANNOTATED_SUGGESTION, match_contents, annotation, &positions); 112 match->contents_class = title_class;
116 match_contents_start = positions[0]; 113 return;
117 annotation_start = positions[1]; 114 }
118 } 115 }
119 size_t match_contents_end = match_contents_start + match_contents.size();
120
121 if (!annotation.empty() && (annotation_start < match_contents_start))
122 match->contents_class.push_back(ACMatchClassification(
123 annotation_start, ACMatchClassification::DIM));
124
125 // We do intra-string highlighting for suggestions - the suggested segment 116 // We do intra-string highlighting for suggestions - the suggested segment
126 // will be highlighted, e.g. for input_text = "you" the suggestion may be 117 // will be highlighted, e.g. for input_text = "you" the suggestion may be
127 // "youtube", so we'll bold the "tube" section: you*tube*. 118 // "youtube", so we'll bold the "tube" section: you*tube*.
128 if (input_text != match_contents) { 119 if (input_text != title) {
129 size_t input_position = match->contents.substr( 120 size_t input_position = match->contents.find(input_text);
130 match_contents_start, match_contents.length()).find(input_text);
131 if (input_position == string16::npos) { 121 if (input_position == string16::npos) {
132 // The input text is not a substring of the query string, e.g. input 122 // The input text is not a substring of the query string, e.g. input
133 // text is "slasdot" and the query string is "slashdot", so we bold the 123 // text is "slasdot" and the query string is "slashdot", so we bold the
134 // whole thing. 124 // whole thing.
135 match->contents_class.push_back(ACMatchClassification( 125 match->contents_class.push_back(ACMatchClassification(
136 match_contents_start, ACMatchClassification::MATCH)); 126 0, ACMatchClassification::MATCH));
137 } else { 127 } else {
138 input_position += match_contents_start;
139
140 // TODO(beng): ACMatchClassification::MATCH now seems to just mean 128 // TODO(beng): ACMatchClassification::MATCH now seems to just mean
141 // "bold" this. Consider modifying the terminology. 129 // "bold" this. Consider modifying the terminology.
142 // We don't iterate over the string here annotating all matches because 130 // We don't iterate over the string here annotating all matches because
143 // it looks odd to have every occurrence of a substring that may be as 131 // it looks odd to have every occurrence of a substring that may be as
144 // short as a single character highlighted in a query suggestion result, 132 // short as a single character highlighted in a query suggestion result,
145 // e.g. for input text "s" and query string "southwest airlines", it 133 // e.g. for input text "s" and query string "southwest airlines", it
146 // looks odd if both the first and last s are highlighted. 134 // looks odd if both the first and last s are highlighted.
147 if (input_position != match_contents_start) { 135 if (input_position != 0) {
148 match->contents_class.push_back(ACMatchClassification( 136 match->contents_class.push_back(ACMatchClassification(
149 match_contents_start, ACMatchClassification::MATCH)); 137 0, ACMatchClassification::MATCH));
150 } 138 }
151 match->contents_class.push_back( 139 match->contents_class.push_back(
152 ACMatchClassification(input_position, ACMatchClassification::NONE)); 140 ACMatchClassification(input_position, ACMatchClassification::NONE));
153 size_t next_fragment_position = input_position + input_text.length(); 141 size_t next_fragment_position = input_position + input_text.length();
154 if (next_fragment_position < query_string.length()) { 142 if (next_fragment_position < query_string.length()) {
155 match->contents_class.push_back(ACMatchClassification( 143 match->contents_class.push_back(ACMatchClassification(
156 next_fragment_position, ACMatchClassification::MATCH)); 144 next_fragment_position, ACMatchClassification::MATCH));
157 } 145 }
158 } 146 }
159 } else { 147 } else {
160 // Otherwise, |match| is a verbatim (what-you-typed) match, either for the 148 // Otherwise, |match| is a verbatim (what-you-typed) match, either for the
161 // default provider or a keyword search provider. 149 // default provider or a keyword search provider.
162 match->contents_class.push_back(ACMatchClassification( 150 match->contents_class.push_back(ACMatchClassification(
163 match_contents_start, ACMatchClassification::NONE)); 151 0, ACMatchClassification::NONE));
164 } 152 }
153 }
165 154
166 if (!annotation.empty() && (annotation_start >= match_contents_start)) 155 AutocompleteMatchType::Type GetAutocompleteMatchType(const std::string& type) {
167 match->contents_class.push_back(ACMatchClassification( 156 if (type == "ENTITY")
168 match_contents_end, ACMatchClassification::DIM)); 157 return AutocompleteMatchType::SEARCH_SUGGEST_ENTITY;
158 if (type == "INFINITE")
159 return AutocompleteMatchType::SEARCH_SUGGEST_INFINITE;
160 return AutocompleteMatchType::SEARCH_SUGGEST;
161 }
162
163 // Whether the given suggestion types supports suggestion detail.
Peter Kasting 2013/11/05 23:36:58 Nit: types -> type
Anuj 2013/12/09 08:24:56 Method removed.
164 bool TypeSupportsSuggestionDetail(const std::string& type) {
165 return (type == "ENTITY") || (type == "INFINITE") || (type == "PROFILE") ||
166 (type == "PERSONALIZED_QUERY");
169 } 167 }
170 168
171 } // namespace 169 } // namespace
172 170
173 171
174 // SearchProvider::Providers -------------------------------------------------- 172 // SearchProvider::Providers --------------------------------------------------
175 173
176 SearchProvider::Providers::Providers(TemplateURLService* template_url_service) 174 SearchProvider::Providers::Providers(TemplateURLService* template_url_service)
177 : template_url_service_(template_url_service) { 175 : template_url_service_(template_url_service) {
178 } 176 }
(...skipping 20 matching lines...) Expand all
199 } 197 }
200 198
201 SearchProvider::Result::~Result() { 199 SearchProvider::Result::~Result() {
202 } 200 }
203 201
204 202
205 // SearchProvider::SuggestResult ---------------------------------------------- 203 // SearchProvider::SuggestResult ----------------------------------------------
206 204
207 SearchProvider::SuggestResult::SuggestResult( 205 SearchProvider::SuggestResult::SuggestResult(
208 const string16& suggestion, 206 const string16& suggestion,
209 const string16& match_contents, 207 AutocompleteMatchType::Type type,
208 const string16& title,
209 ACMatchClassifications title_class,
210 const string16& annotation, 210 const string16& annotation,
211 ACMatchClassifications annotation_class,
211 const std::string& suggest_query_params, 212 const std::string& suggest_query_params,
212 bool from_keyword_provider, 213 bool from_keyword_provider,
213 int relevance, 214 int relevance,
214 bool relevance_from_server, 215 bool relevance_from_server,
215 bool should_prefetch) 216 bool should_prefetch)
216 : Result(from_keyword_provider, relevance, relevance_from_server), 217 : Result(from_keyword_provider, relevance, relevance_from_server),
217 suggestion_(suggestion), 218 suggestion_(suggestion),
218 match_contents_(match_contents), 219 type_(type),
220 title_(title),
221 title_class_(title_class),
219 annotation_(annotation), 222 annotation_(annotation),
223 annotation_class_(annotation_class),
220 suggest_query_params_(suggest_query_params), 224 suggest_query_params_(suggest_query_params),
221 should_prefetch_(should_prefetch) { 225 should_prefetch_(should_prefetch) {
222 } 226 }
223 227
224 SearchProvider::SuggestResult::~SuggestResult() { 228 SearchProvider::SuggestResult::~SuggestResult() {
225 } 229 }
226 230
227 bool SearchProvider::SuggestResult::IsInlineable(const string16& input) const { 231 bool SearchProvider::SuggestResult::IsInlineable(const string16& input) const {
228 return StartsWith(suggestion_, input, false); 232 return StartsWith(suggestion_, input, false);
229 } 233 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 } 344 }
341 345
342 // static 346 // static
343 AutocompleteMatch SearchProvider::CreateSearchSuggestion( 347 AutocompleteMatch SearchProvider::CreateSearchSuggestion(
344 AutocompleteProvider* autocomplete_provider, 348 AutocompleteProvider* autocomplete_provider,
345 const AutocompleteInput& input, 349 const AutocompleteInput& input,
346 const string16& input_text, 350 const string16& input_text,
347 int relevance, 351 int relevance,
348 AutocompleteMatch::Type type, 352 AutocompleteMatch::Type type,
349 bool is_keyword, 353 bool is_keyword,
350 const string16& match_contents, 354 const string16& title,
355 const ACMatchClassifications& title_class,
Peter Kasting 2013/11/05 23:36:58 I'm not terribly keen on changing the param names
Anuj 2013/11/06 00:18:28 This change was in accordance with our in person d
351 const string16& annotation, 356 const string16& annotation,
357 const ACMatchClassifications& annotation_class,
Peter Kasting 2013/11/05 23:36:58 Do we have to pass |annotation| and |annotation_cl
Anuj 2013/11/06 00:18:28 Please elaborate. What do you mean by "one caller"
Peter Kasting 2013/11/06 00:34:26 Only AddMatchToMap() needs to do anything with thi
Anuj 2013/12/09 08:24:56 Classification parameters removed
352 const TemplateURL* template_url, 358 const TemplateURL* template_url,
353 const string16& query_string, 359 const string16& query_string,
354 const std::string& suggest_query_params, 360 const std::string& suggest_query_params,
355 int accepted_suggestion, 361 int accepted_suggestion,
356 int omnibox_start_margin, 362 int omnibox_start_margin,
357 bool append_extra_query_params) { 363 bool append_extra_query_params) {
358 AutocompleteMatch match(autocomplete_provider, relevance, false, type); 364 AutocompleteMatch match(autocomplete_provider, relevance, false, type);
359 365
360 if (!template_url) 366 if (!template_url)
361 return match; 367 return match;
362 match.keyword = template_url->keyword(); 368 match.keyword = template_url->keyword();
363 369
364 SetAndClassifyMatchContents( 370 SetAndClassifyMatchContents(
365 query_string, input_text, match_contents, annotation, &match); 371 query_string, input_text, title, title_class, &match);
366 372
367 match.allowed_to_be_default_match = (input_text == match_contents); 373 if (!annotation.empty()) {
374 match.description = annotation;
375 if (!annotation_class.empty())
376 match.description_class = annotation_class;
377 }
378
379 match.allowed_to_be_default_match = (input_text == title);
368 380
369 // When the user forced a query, we need to make sure all the fill_into_edit 381 // When the user forced a query, we need to make sure all the fill_into_edit
370 // values preserve that property. Otherwise, if the user starts editing a 382 // values preserve that property. Otherwise, if the user starts editing a
371 // suggestion, non-Search results will suddenly appear. 383 // suggestion, non-Search results will suddenly appear.
372 if (input.type() == AutocompleteInput::FORCED_QUERY) 384 if (input.type() == AutocompleteInput::FORCED_QUERY)
373 match.fill_into_edit.assign(ASCIIToUTF16("?")); 385 match.fill_into_edit.assign(ASCIIToUTF16("?"));
374 if (is_keyword) 386 if (is_keyword)
375 match.fill_into_edit.append(match.keyword + char16(' ')); 387 match.fill_into_edit.append(match.keyword + char16(' '));
376 if (!input.prevent_inline_autocomplete() && 388 if (!input.prevent_inline_autocomplete() &&
377 StartsWith(query_string, input_text, false)) { 389 StartsWith(query_string, input_text, false)) {
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 // Do not blindly trust the URL coming from the server to be valid. 1041 // Do not blindly trust the URL coming from the server to be valid.
1030 GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(suggestion), std::string())); 1042 GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(suggestion), std::string()));
1031 if (url.is_valid()) { 1043 if (url.is_valid()) {
1032 string16 title; 1044 string16 title;
1033 if (descriptions != NULL) 1045 if (descriptions != NULL)
1034 descriptions->GetString(index, &title); 1046 descriptions->GetString(index, &title);
1035 results->navigation_results.push_back(NavigationResult( 1047 results->navigation_results.push_back(NavigationResult(
1036 *this, url, title, is_keyword, relevance, true)); 1048 *this, url, title, is_keyword, relevance, true));
1037 } 1049 }
1038 } else { 1050 } else {
1051 AutocompleteMatchType::Type match_type = GetAutocompleteMatchType(type);
1039 bool should_prefetch = static_cast<int>(index) == prefetch_index; 1052 bool should_prefetch = static_cast<int>(index) == prefetch_index;
1040 DictionaryValue* suggestion_detail = NULL; 1053 DictionaryValue* suggestion_detail = NULL;
1041 string16 match_contents = suggestion; 1054 string16 title;
1042 string16 disambiguating_query; 1055 ACMatchClassifications title_class;
1043 string16 annotation; 1056 string16 annotation;
1057 ACMatchClassifications annotation_class;
1058 std::string classifications;
1044 std::string suggest_query_params; 1059 std::string suggest_query_params;
1045 if (suggestion_details && (type == "ENTITY") && 1060 if (suggestion_details && TypeSupportsSuggestionDetail(type) &&
1046 suggestion_details->GetDictionary(index, &suggestion_detail) && 1061 suggestion_details->GetDictionary(index, &suggestion_detail) &&
1047 suggestion_detail) { 1062 suggestion_detail) {
1048 suggestion_detail->GetString("a", &annotation); 1063 suggestion_detail->GetString("title", &title) ||
1049 if (suggestion_detail->GetString("dq", &disambiguating_query) && 1064 suggestion_detail->GetString("t", &title);
1050 !disambiguating_query.empty()) 1065 suggestion_detail->GetString("title_class", &classifications) ||
1051 suggestion = disambiguating_query; 1066 suggestion_detail->GetString("tc", &classifications);
1052 suggestion_detail->GetString("q", &suggest_query_params); 1067 title_class =
1068 AutocompleteMatch::ClassificationsFromString(classifications);
Peter Kasting 2013/11/05 23:36:58 The more I think about this the less OK I am with
Anuj 2013/11/06 00:18:28 I failed to identify "several reasons" in your com
Peter Kasting 2013/11/06 00:34:26 That's because I didn't give them. I'd really rat
Anuj 2013/12/09 08:24:56 Classifications removed.
1069 classifications.clear();
1070
1071 suggestion_detail->GetString("annotation", &annotation) ||
1072 suggestion_detail->GetString("a", &annotation);
1073 suggestion_detail->GetString("annotation_class", &classifications) ||
1074 suggestion_detail->GetString("ac", &classifications);
1075 annotation_class =
1076 AutocompleteMatch::ClassificationsFromString(classifications);
1077 classifications.clear();
1078
1079 suggestion_detail->GetString("query_params", &suggest_query_params) ||
1080 suggestion_detail->GetString("q", &suggest_query_params);
1053 } 1081 }
1054 // TODO(kochi): Improve calculator suggestion presentation. 1082 // TODO(kochi): Improve calculator suggestion presentation.
1055 results->suggest_results.push_back(SuggestResult( 1083 results->suggest_results.push_back(SuggestResult(
1056 suggestion, match_contents, annotation, suggest_query_params, 1084 suggestion, match_type, title, title_class, annotation,
Peter Kasting 2013/11/05 23:36:58 Nit: Two spaces
Anuj 2013/12/09 08:24:56 Done.
1057 is_keyword, relevance, true, should_prefetch)); 1085 annotation_class, suggest_query_params, is_keyword, relevance, true,
1086 should_prefetch));
1058 } 1087 }
1059 } 1088 }
1060 1089
1061 // Apply calculated relevance scores if a valid list was not provided. 1090 // Apply calculated relevance scores if a valid list was not provided.
1062 if (relevances == NULL) { 1091 if (relevances == NULL) {
1063 ApplyCalculatedSuggestRelevance(&results->suggest_results); 1092 ApplyCalculatedSuggestRelevance(&results->suggest_results);
1064 ApplyCalculatedNavigationRelevance(&results->navigation_results); 1093 ApplyCalculatedNavigationRelevance(&results->navigation_results);
1065 } 1094 }
1066 // Keep the result lists sorted. 1095 // Keep the result lists sorted.
1067 const CompareScoredResults comparator = CompareScoredResults(); 1096 const CompareScoredResults comparator = CompareScoredResults();
(...skipping 25 matching lines...) Expand all
1093 TemplateURLRef::NO_SUGGESTION_CHOSEN; 1122 TemplateURLRef::NO_SUGGESTION_CHOSEN;
1094 if (verbatim_relevance > 0) { 1123 if (verbatim_relevance > 0) {
1095 AddMatchToMap(input_.text(), 1124 AddMatchToMap(input_.text(),
1096 verbatim_relevance, 1125 verbatim_relevance,
1097 relevance_from_server, 1126 relevance_from_server,
1098 false, 1127 false,
1099 std::string(), 1128 std::string(),
1100 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 1129 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
1101 false, 1130 false,
1102 input_.text(), 1131 input_.text(),
1132 ACMatchClassifications(),
1103 string16(), 1133 string16(),
1134 ACMatchClassifications(),
1104 input_.text(), 1135 input_.text(),
1105 did_not_accept_default_suggestion, 1136 did_not_accept_default_suggestion,
1106 std::string(), 1137 std::string(),
1107 &map); 1138 &map);
1108 } 1139 }
1109 if (!keyword_input_.text().empty()) { 1140 if (!keyword_input_.text().empty()) {
1110 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); 1141 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL();
1111 // We only create the verbatim search query match for a keyword 1142 // We only create the verbatim search query match for a keyword
1112 // if it's not an extension keyword. Extension keywords are handled 1143 // if it's not an extension keyword. Extension keywords are handled
1113 // in KeywordProvider::Start(). (Extensions are complicated...) 1144 // in KeywordProvider::Start(). (Extensions are complicated...)
1114 // Note: in this provider, SEARCH_OTHER_ENGINE must correspond 1145 // Note: in this provider, SEARCH_OTHER_ENGINE must correspond
1115 // to the keyword verbatim search query. Do not create other matches 1146 // to the keyword verbatim search query. Do not create other matches
1116 // of type SEARCH_OTHER_ENGINE. 1147 // of type SEARCH_OTHER_ENGINE.
1117 if (keyword_url && 1148 if (keyword_url &&
1118 (keyword_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION)) { 1149 (keyword_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION)) {
1119 bool keyword_relevance_from_server; 1150 bool keyword_relevance_from_server;
1120 const int keyword_verbatim_relevance = 1151 const int keyword_verbatim_relevance =
1121 GetKeywordVerbatimRelevance(&keyword_relevance_from_server); 1152 GetKeywordVerbatimRelevance(&keyword_relevance_from_server);
1122 if (keyword_verbatim_relevance > 0) { 1153 if (keyword_verbatim_relevance > 0) {
1123 AddMatchToMap(keyword_input_.text(), 1154 AddMatchToMap(keyword_input_.text(),
1124 keyword_verbatim_relevance, 1155 keyword_verbatim_relevance,
1125 keyword_relevance_from_server, 1156 keyword_relevance_from_server,
1126 false, 1157 false,
1127 std::string(), 1158 std::string(),
1128 AutocompleteMatchType::SEARCH_OTHER_ENGINE, 1159 AutocompleteMatchType::SEARCH_OTHER_ENGINE,
1129 true, 1160 true,
1130 keyword_input_.text(), 1161 keyword_input_.text(),
1162 ACMatchClassifications(),
1131 string16(), 1163 string16(),
1164 ACMatchClassifications(),
1132 keyword_input_.text(), 1165 keyword_input_.text(),
1133 did_not_accept_keyword_suggestion, 1166 did_not_accept_keyword_suggestion,
1134 std::string(), 1167 std::string(),
1135 &map); 1168 &map);
1136 } 1169 }
1137 } 1170 }
1138 } 1171 }
1139 AddHistoryResultsToMap(keyword_history_results_, true, 1172 AddHistoryResultsToMap(keyword_history_results_, true,
1140 did_not_accept_keyword_suggestion, &map); 1173 did_not_accept_keyword_suggestion, &map);
1141 AddHistoryResultsToMap(default_history_results_, false, 1174 AddHistoryResultsToMap(default_history_results_, false,
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 for (SuggestResults::const_iterator i(scored_results.begin()); 1402 for (SuggestResults::const_iterator i(scored_results.begin());
1370 i != scored_results.end(); ++i) { 1403 i != scored_results.end(); ++i) {
1371 AddMatchToMap(input_text, 1404 AddMatchToMap(input_text,
1372 i->relevance(), 1405 i->relevance(),
1373 false, 1406 false,
1374 false, 1407 false,
1375 std::string(), 1408 std::string(),
1376 AutocompleteMatchType::SEARCH_HISTORY, 1409 AutocompleteMatchType::SEARCH_HISTORY,
1377 is_keyword, 1410 is_keyword,
1378 i->suggestion(), 1411 i->suggestion(),
1412 ACMatchClassifications(),
1379 string16(), 1413 string16(),
1414 ACMatchClassifications(),
1380 i->suggestion(), 1415 i->suggestion(),
1381 did_not_accept_suggestion, 1416 did_not_accept_suggestion,
1382 std::string(), 1417 std::string(),
1383 map); 1418 map);
1384 } 1419 }
1385 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.AddHistoryResultsTime", 1420 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.AddHistoryResultsTime",
1386 base::TimeTicks::Now() - start_time); 1421 base::TimeTicks::Now() - start_time);
1387 } 1422 }
1388 1423
1389 SearchProvider::SuggestResults SearchProvider::ScoreHistoryResults( 1424 SearchProvider::SuggestResults SearchProvider::ScoreHistoryResults(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 if (!prevent_inline_autocomplete && classifier && (i->term != input_text)) { 1456 if (!prevent_inline_autocomplete && classifier && (i->term != input_text)) {
1422 AutocompleteMatch match; 1457 AutocompleteMatch match;
1423 classifier->Classify(i->term, false, false, &match, NULL); 1458 classifier->Classify(i->term, false, false, &match, NULL);
1424 prevent_inline_autocomplete = 1459 prevent_inline_autocomplete =
1425 !AutocompleteMatch::IsSearchType(match.type); 1460 !AutocompleteMatch::IsSearchType(match.type);
1426 } 1461 }
1427 1462
1428 int relevance = CalculateRelevanceForHistory( 1463 int relevance = CalculateRelevanceForHistory(
1429 i->time, is_keyword, !prevent_inline_autocomplete, 1464 i->time, is_keyword, !prevent_inline_autocomplete,
1430 prevent_search_history_inlining); 1465 prevent_search_history_inlining);
1431 scored_results.push_back( 1466 scored_results.push_back(SuggestResult(
1432 SuggestResult(i->term, string16(), string16(), std::string(), 1467 i->term, AutocompleteMatchType::SEARCH_HISTORY, string16(),
1433 is_keyword, relevance, false, false)); 1468 ACMatchClassifications(), string16(), ACMatchClassifications(),
1469 std::string(), is_keyword, relevance, false, false));
1434 } 1470 }
1435 1471
1436 // History returns results sorted for us. However, we may have docked some 1472 // History returns results sorted for us. However, we may have docked some
1437 // results' scores, so things are no longer in order. Do a stable sort to get 1473 // results' scores, so things are no longer in order. Do a stable sort to get
1438 // things back in order without otherwise disturbing results with equal 1474 // things back in order without otherwise disturbing results with equal
1439 // scores, then force the scores to be unique, so that the order in which 1475 // scores, then force the scores to be unique, so that the order in which
1440 // they're shown is deterministic. 1476 // they're shown is deterministic.
1441 std::stable_sort(scored_results.begin(), scored_results.end(), 1477 std::stable_sort(scored_results.begin(), scored_results.end(),
1442 CompareScoredResults()); 1478 CompareScoredResults());
1443 int last_relevance = 0; 1479 int last_relevance = 0;
(...skipping 11 matching lines...) Expand all
1455 const std::string& metadata, 1491 const std::string& metadata,
1456 MatchMap* map) { 1492 MatchMap* map) {
1457 for (size_t i = 0; i < results.size(); ++i) { 1493 for (size_t i = 0; i < results.size(); ++i) {
1458 const bool is_keyword = results[i].from_keyword_provider(); 1494 const bool is_keyword = results[i].from_keyword_provider();
1459 const string16& input = is_keyword ? keyword_input_.text() : input_.text(); 1495 const string16& input = is_keyword ? keyword_input_.text() : input_.text();
1460 AddMatchToMap(input, 1496 AddMatchToMap(input,
1461 results[i].relevance(), 1497 results[i].relevance(),
1462 results[i].relevance_from_server(), 1498 results[i].relevance_from_server(),
1463 results[i].should_prefetch(), 1499 results[i].should_prefetch(),
1464 metadata, 1500 metadata,
1465 AutocompleteMatchType::SEARCH_SUGGEST, 1501 results[i].type(),
1466 is_keyword, 1502 is_keyword,
1467 results[i].match_contents(), 1503 results[i].title(),
1504 results[i].title_class(),
1468 results[i].annotation(), 1505 results[i].annotation(),
1506 results[i].annotation_class(),
1469 results[i].suggestion(), 1507 results[i].suggestion(),
1470 i, 1508 i,
1471 results[i].suggest_query_params(), 1509 results[i].suggest_query_params(),
1472 map); 1510 map);
1473 } 1511 }
1474 } 1512 }
1475 1513
1476 int SearchProvider::GetVerbatimRelevance(bool* relevance_from_server) const { 1514 int SearchProvider::GetVerbatimRelevance(bool* relevance_from_server) const {
1477 // Use the suggested verbatim relevance score if it is non-negative (valid), 1515 // Use the suggested verbatim relevance score if it is non-negative (valid),
1478 // if inline autocomplete isn't prevented (always show verbatim on backspace), 1516 // if inline autocomplete isn't prevented (always show verbatim on backspace),
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1574 // Don't let scores go below 0. Negative relevance scores are meaningful in 1612 // Don't let scores go below 0. Negative relevance scores are meaningful in
1575 // a different way. 1613 // a different way.
1576 int base_score; 1614 int base_score;
1577 if (is_primary_provider) 1615 if (is_primary_provider)
1578 base_score = (input_.type() == AutocompleteInput::URL) ? 750 : 1050; 1616 base_score = (input_.type() == AutocompleteInput::URL) ? 750 : 1050;
1579 else 1617 else
1580 base_score = 200; 1618 base_score = 200;
1581 return std::max(0, base_score - score_discount); 1619 return std::max(0, base_score - score_discount);
1582 } 1620 }
1583 1621
1584 void SearchProvider::AddMatchToMap(const string16& input_text, 1622 void SearchProvider::AddMatchToMap(
1585 int relevance, 1623 const string16& input_text,
1586 bool relevance_from_server, 1624 int relevance,
1587 bool should_prefetch, 1625 bool relevance_from_server,
1588 const std::string& metadata, 1626 bool should_prefetch,
1589 AutocompleteMatch::Type type, 1627 const std::string& metadata,
1590 bool is_keyword, 1628 AutocompleteMatch::Type type,
1591 const string16& match_contents, 1629 bool is_keyword,
1592 const string16& annotation, 1630 const string16& title,
1593 const string16& query_string, 1631 const ACMatchClassifications& title_class,
1594 int accepted_suggestion, 1632 const string16& annotation,
1595 const std::string& suggest_query_params, 1633 const ACMatchClassifications& annotation_class,
1596 MatchMap* map) { 1634 const string16& query_string,
1635 int accepted_suggestion,
1636 const std::string& suggest_query_params,
1637 MatchMap* map) {
1597 // On non-mobile, ask the instant controller for the appropriate start margin. 1638 // On non-mobile, ask the instant controller for the appropriate start margin.
1598 // On mobile the start margin is unused, so leave the value as default there. 1639 // On mobile the start margin is unused, so leave the value as default there.
1599 int omnibox_start_margin = chrome::kDisableStartMargin; 1640 int omnibox_start_margin = chrome::kDisableStartMargin;
1600 #if !defined(OS_ANDROID) && !defined(IOS) 1641 #if !defined(OS_ANDROID) && !defined(IOS)
1601 if (chrome::IsInstantExtendedAPIEnabled()) { 1642 if (chrome::IsInstantExtendedAPIEnabled()) {
1602 Browser* browser = 1643 Browser* browser =
1603 chrome::FindBrowserWithProfile(profile_, chrome::GetActiveDesktop()); 1644 chrome::FindBrowserWithProfile(profile_, chrome::GetActiveDesktop());
1604 if (browser && browser->instant_controller() && 1645 if (browser && browser->instant_controller() &&
1605 browser->instant_controller()->instant()) { 1646 browser->instant_controller()->instant()) {
1606 omnibox_start_margin = 1647 omnibox_start_margin =
1607 browser->instant_controller()->instant()->omnibox_bounds().x(); 1648 browser->instant_controller()->instant()->omnibox_bounds().x();
1608 } 1649 }
1609 } 1650 }
1610 #endif // !defined(OS_ANDROID) && !defined(IOS) 1651 #endif // !defined(OS_ANDROID) && !defined(IOS)
1611 1652
1612 const TemplateURL* template_url = is_keyword ? 1653 const TemplateURL* template_url = is_keyword ?
1613 providers_.GetKeywordProviderURL() : providers_.GetDefaultProviderURL(); 1654 providers_.GetKeywordProviderURL() : providers_.GetDefaultProviderURL();
1614 AutocompleteMatch match = CreateSearchSuggestion( 1655 AutocompleteMatch match = CreateSearchSuggestion(
1615 this, input_, input_text, relevance, type, is_keyword, match_contents, 1656 this, input_, input_text, relevance, type, is_keyword, title, title_class,
1616 annotation, template_url, query_string, suggest_query_params, 1657 annotation, annotation_class, template_url, query_string,
1617 accepted_suggestion, omnibox_start_margin, 1658 suggest_query_params, accepted_suggestion, omnibox_start_margin,
1618 !is_keyword || providers_.default_provider().empty()); 1659 !is_keyword || providers_.default_provider().empty());
1619 if (!match.destination_url.is_valid()) 1660 if (!match.destination_url.is_valid())
1620 return; 1661 return;
1621 match.search_terms_args->bookmark_bar_pinned = 1662 match.search_terms_args->bookmark_bar_pinned =
1622 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); 1663 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar);
1623 match.RecordAdditionalInfo(kRelevanceFromServerKey, 1664 match.RecordAdditionalInfo(kRelevanceFromServerKey,
1624 relevance_from_server ? kTrue : kFalse); 1665 relevance_from_server ? kTrue : kFalse);
1625 match.RecordAdditionalInfo(kShouldPrefetchKey, 1666 match.RecordAdditionalInfo(kShouldPrefetchKey,
1626 should_prefetch ? kTrue : kFalse); 1667 should_prefetch ? kTrue : kFalse);
1627 1668
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1780 it->set_relevance(max_query_relevance); 1821 it->set_relevance(max_query_relevance);
1781 it->set_relevance_from_server(relevance_from_server); 1822 it->set_relevance_from_server(relevance_from_server);
1782 } 1823 }
1783 } 1824 }
1784 1825
1785 void SearchProvider::UpdateDone() { 1826 void SearchProvider::UpdateDone() {
1786 // We're done when the timer isn't running, there are no suggest queries 1827 // We're done when the timer isn't running, there are no suggest queries
1787 // pending, and we're not waiting on Instant. 1828 // pending, and we're not waiting on Instant.
1788 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); 1829 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0);
1789 } 1830 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698