OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This file contains the Search autocomplete provider. This provider is | 5 // This file contains the Search autocomplete provider. This provider is |
6 // responsible for all non-keyword autocomplete entries that start with | 6 // responsible for all non-keyword autocomplete entries that start with |
7 // "Search <engine> for ...", including searching for the current input string, | 7 // "Search <engine> for ...", including searching for the current input string, |
8 // search history, and search suggestions. An instance of it gets created and | 8 // search history, and search suggestions. An instance of it gets created and |
9 // managed by the autocomplete controller. | 9 // managed by the autocomplete controller. |
10 // | 10 // |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 GURL url; | 164 GURL url; |
165 | 165 |
166 // Name for the site. | 166 // Name for the site. |
167 string16 site_name; | 167 string16 site_name; |
168 }; | 168 }; |
169 | 169 |
170 typedef std::vector<string16> SuggestResults; | 170 typedef std::vector<string16> SuggestResults; |
171 typedef std::vector<NavigationResult> NavigationResults; | 171 typedef std::vector<NavigationResult> NavigationResults; |
172 typedef std::vector<history::KeywordSearchTermVisit> HistoryResults; | 172 typedef std::vector<history::KeywordSearchTermVisit> HistoryResults; |
173 typedef std::map<string16, AutocompleteMatch> MatchMap; | 173 typedef std::map<string16, AutocompleteMatch> MatchMap; |
| 174 typedef std::pair<string16, int> ScoredTerm; |
| 175 typedef std::vector<ScoredTerm> ScoredTerms; |
| 176 |
| 177 class CompareScoredTerms; |
174 | 178 |
175 // Called when timer_ expires. | 179 // Called when timer_ expires. |
176 void Run(); | 180 void Run(); |
177 | 181 |
178 // Runs the history query, if necessary. The history query is synchronous. | 182 // Runs the history query, if necessary. The history query is synchronous. |
179 // This does not update |done_|. | 183 // This does not update |done_|. |
180 void DoHistoryQuery(bool minimal_changes); | 184 void DoHistoryQuery(bool minimal_changes); |
181 | 185 |
182 // Determines whether an asynchronous subcomponent query should run for the | 186 // Determines whether an asynchronous subcomponent query should run for the |
183 // current input. If so, starts it if necessary; otherwise stops it. | 187 // current input. If so, starts it if necessary; otherwise stops it. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 const NavigationResults& navigation_results, | 221 const NavigationResults& navigation_results, |
218 bool is_keyword); | 222 bool is_keyword); |
219 | 223 |
220 // Adds a match for each result in |results| to |map|. |is_keyword| indicates | 224 // Adds a match for each result in |results| to |map|. |is_keyword| indicates |
221 // whether the results correspond to the keyword provider or default provider. | 225 // whether the results correspond to the keyword provider or default provider. |
222 void AddHistoryResultsToMap(const HistoryResults& results, | 226 void AddHistoryResultsToMap(const HistoryResults& results, |
223 bool is_keyword, | 227 bool is_keyword, |
224 int did_not_accept_suggestion, | 228 int did_not_accept_suggestion, |
225 MatchMap* map); | 229 MatchMap* map); |
226 | 230 |
| 231 // Calculates relevance scores for all |results|. |
| 232 ScoredTerms ScoreHistoryTerms(const HistoryResults& results, |
| 233 bool base_prevent_inline_autocomplete, |
| 234 bool input_multiple_words, |
| 235 const string16& input_text, |
| 236 bool is_keyword); |
| 237 |
227 // Adds a match for each result in |suggest_results| to |map|. |is_keyword| | 238 // Adds a match for each result in |suggest_results| to |map|. |is_keyword| |
228 // indicates whether the results correspond to the keyword provider or default | 239 // indicates whether the results correspond to the keyword provider or default |
229 // provider. | 240 // provider. |
230 void AddSuggestResultsToMap(const SuggestResults& suggest_results, | 241 void AddSuggestResultsToMap(const SuggestResults& suggest_results, |
231 bool is_keyword, | 242 bool is_keyword, |
232 int did_not_accept_suggestion, | 243 int did_not_accept_suggestion, |
233 MatchMap* map); | 244 MatchMap* map); |
234 | 245 |
235 // Determines the relevance for a particular match. We use different scoring | 246 // Determines the relevance for a particular match. We use different scoring |
236 // algorithms for the different types of matches. | 247 // algorithms for the different types of matches. |
237 int CalculateRelevanceForWhatYouTyped() const; | 248 int CalculateRelevanceForWhatYouTyped() const; |
238 // |time| is the time at which this query was last seen. |is_keyword| is true | 249 // |time| is the time at which this query was last seen. |is_keyword| |
239 // if the search is from the keyword provider. |looks_like_url| is true if the | 250 // indicates whether the results correspond to the keyword provider or default |
240 // search term would be treated as a URL if typed into the omnibox. | 251 // provider. |prevent_inline_autocomplete| is true if we should not inline |
| 252 // autocomplete this query. |
241 int CalculateRelevanceForHistory(const base::Time& time, | 253 int CalculateRelevanceForHistory(const base::Time& time, |
242 bool looks_like_url, | 254 bool is_keyword, |
243 bool is_keyword) const; | 255 bool prevent_inline_autocomplete) const; |
244 // |result_number| is the index of the suggestion in the result set from the | 256 // |result_number| is the index of the suggestion in the result set from the |
245 // server; the best suggestion is suggestion number 0. |is_keyword| is true | 257 // server; the best suggestion is suggestion number 0. |is_keyword| is true |
246 // if the search is from the keyword provider. | 258 // if the search is from the keyword provider. |
247 int CalculateRelevanceForSuggestion(size_t num_results, | 259 int CalculateRelevanceForSuggestion(size_t num_results, |
248 size_t result_number, | 260 size_t result_number, |
249 bool is_keyword) const; | 261 bool is_keyword) const; |
250 // |result_number| is same as above. |is_keyword| is true if the navigation | 262 // |result_number| is same as above. |is_keyword| is true if the navigation |
251 // result was suggested by the keyword provider. | 263 // result was suggested by the keyword provider. |
252 int CalculateRelevanceForNavigation(size_t num_results, | 264 int CalculateRelevanceForNavigation(size_t num_results, |
253 size_t result_number, | 265 size_t result_number, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 // Has FinalizeInstantQuery been invoked since the last |Start|? | 331 // Has FinalizeInstantQuery been invoked since the last |Start|? |
320 bool instant_finalized_; | 332 bool instant_finalized_; |
321 | 333 |
322 // The |suggest_text| parameter passed to FinalizeInstantQuery. | 334 // The |suggest_text| parameter passed to FinalizeInstantQuery. |
323 string16 default_provider_suggest_text_; | 335 string16 default_provider_suggest_text_; |
324 | 336 |
325 DISALLOW_COPY_AND_ASSIGN(SearchProvider); | 337 DISALLOW_COPY_AND_ASSIGN(SearchProvider); |
326 }; | 338 }; |
327 | 339 |
328 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ | 340 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ |
OLD | NEW |