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

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

Issue 1411543011: Omnibox: Make Keyword Provide More Generous with Matching (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: almost all of peter's comments Created 5 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 "components/omnibox/browser/search_provider.h" 5 #include "components/omnibox/browser/search_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 listener_->OnProviderUpdate(true); // always pretend something changed 181 listener_->OnProviderUpdate(true); // always pretend something changed
182 } 182 }
183 183
184 SearchProvider::~SearchProvider() { 184 SearchProvider::~SearchProvider() {
185 TemplateURLService* template_url_service = client()->GetTemplateURLService(); 185 TemplateURLService* template_url_service = client()->GetTemplateURLService();
186 if (template_url_service) 186 if (template_url_service)
187 template_url_service->RemoveObserver(this); 187 template_url_service->RemoveObserver(this);
188 } 188 }
189 189
190 // static 190 // static
191 int SearchProvider::CalculateRelevanceForKeywordVerbatim( 191 int SearchProvider::CalculateRelevanceForKeywordVerbatim(
Peter Kasting 2015/11/12 20:36:10 Nit: Move this function to correspond with your mo
Mark P 2015/11/12 21:42:48 Done. Also moved several other functions that I n
192 metrics::OmniboxInputType::Type type, 192 metrics::OmniboxInputType::Type type,
193 bool allow_exact_keyword_match,
193 bool prefer_keyword) { 194 bool prefer_keyword) {
194 // This function is responsible for scoring verbatim query matches 195 // This function is responsible for scoring verbatim query matches
195 // for non-extension keywords. KeywordProvider::CalculateRelevance() 196 // for non-extension substituting keywords.
196 // scores verbatim query matches for extension keywords, as well as 197 // KeywordProvider::CalculateRelevance() scores all other types of
197 // for keyword matches (i.e., suggestions of a keyword itself, not a 198 // keyword verbatim matches.
198 // suggestion of a query on a keyword search engine). These two 199 if (allow_exact_keyword_match && prefer_keyword)
199 // functions are currently in sync, but there's no reason we
200 // couldn't decide in the future to score verbatim matches
201 // differently for extension and non-extension keywords. If you
202 // make such a change, however, you should update this comment to
203 // describe it, so it's clear why the functions diverge.
204 if (prefer_keyword)
205 return 1500; 200 return 1500;
206 return (type == metrics::OmniboxInputType::QUERY) ? 1450 : 1100; 201 return (allow_exact_keyword_match &&
202 (type == metrics::OmniboxInputType::QUERY)) ?
203 1450 : 1100;
207 } 204 }
208 205
209 // static 206 // static
210 void SearchProvider::UpdateOldResults( 207 void SearchProvider::UpdateOldResults(
211 bool minimal_changes, 208 bool minimal_changes,
212 SearchSuggestionParser::Results* results) { 209 SearchSuggestionParser::Results* results) {
213 // When called without |minimal_changes|, it likely means the user has 210 // When called without |minimal_changes|, it likely means the user has
214 // pressed a key. Revise the cached results appropriately. 211 // pressed a key. Revise the cached results appropriately.
215 if (!minimal_changes) { 212 if (!minimal_changes) {
216 for (SearchSuggestionParser::SuggestResults::iterator sug_it = 213 for (SearchSuggestionParser::SuggestResults::iterator sug_it =
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 (keyword_results_.verbatim_relevance >= 0) && 1309 (keyword_results_.verbatim_relevance >= 0) &&
1313 !input_.prevent_inline_autocomplete() && 1310 !input_.prevent_inline_autocomplete() &&
1314 ((keyword_results_.verbatim_relevance > 0) || 1311 ((keyword_results_.verbatim_relevance > 0) ||
1315 !keyword_results_.suggest_results.empty() || 1312 !keyword_results_.suggest_results.empty() ||
1316 !keyword_results_.navigation_results.empty()); 1313 !keyword_results_.navigation_results.empty());
1317 if (relevance_from_server) 1314 if (relevance_from_server)
1318 *relevance_from_server = use_server_relevance; 1315 *relevance_from_server = use_server_relevance;
1319 return use_server_relevance ? 1316 return use_server_relevance ?
1320 keyword_results_.verbatim_relevance : 1317 keyword_results_.verbatim_relevance :
1321 CalculateRelevanceForKeywordVerbatim(keyword_input_.type(), 1318 CalculateRelevanceForKeywordVerbatim(keyword_input_.type(),
1319 true,
1322 keyword_input_.prefer_keyword()); 1320 keyword_input_.prefer_keyword());
1323 } 1321 }
1324 1322
1325 int SearchProvider::CalculateRelevanceForHistory( 1323 int SearchProvider::CalculateRelevanceForHistory(
1326 const base::Time& time, 1324 const base::Time& time,
1327 bool is_keyword, 1325 bool is_keyword,
1328 bool use_aggressive_method, 1326 bool use_aggressive_method,
1329 bool prevent_search_history_inlining) const { 1327 bool prevent_search_history_inlining) const {
1330 // The relevance of past searches falls off over time. There are two distinct 1328 // The relevance of past searches falls off over time. There are two distinct
1331 // equations used. If the first equation is used (searches to the primary 1329 // equations used. If the first equation is used (searches to the primary
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1500 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) 1498 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i)
1501 matches.push_back(i->second); 1499 matches.push_back(i->second);
1502 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); 1500 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant);
1503 1501
1504 // If there is a top scoring entry, find the corresponding answer. 1502 // If there is a top scoring entry, find the corresponding answer.
1505 if (!matches.empty()) 1503 if (!matches.empty())
1506 return answers_cache_.GetTopAnswerEntry(matches[0].contents); 1504 return answers_cache_.GetTopAnswerEntry(matches[0].contents);
1507 1505
1508 return AnswersQueryData(); 1506 return AnswersQueryData();
1509 } 1507 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698