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 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 772 } | 772 } |
| 773 | 773 |
| 774 void SearchProvider::ConvertResultsToAutocompleteMatches() { | 774 void SearchProvider::ConvertResultsToAutocompleteMatches() { |
| 775 // Convert all the results to matches and add them to a map, so we can keep | 775 // Convert all the results to matches and add them to a map, so we can keep |
| 776 // the most relevant match for each result. | 776 // the most relevant match for each result. |
| 777 MatchMap map; | 777 MatchMap map; |
| 778 const Time no_time; | 778 const Time no_time; |
| 779 int did_not_accept_keyword_suggestion = keyword_suggest_results_.empty() ? | 779 int did_not_accept_keyword_suggestion = keyword_suggest_results_.empty() ? |
| 780 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : | 780 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : |
| 781 TemplateURLRef::NO_SUGGESTION_CHOSEN; | 781 TemplateURLRef::NO_SUGGESTION_CHOSEN; |
| 782 // Keyword what you typed results are handled by the KeywordProvider. | |
| 783 | 782 |
| 784 int verbatim_relevance = GetVerbatimRelevance(); | 783 int verbatim_relevance = GetVerbatimRelevance(); |
| 785 int did_not_accept_default_suggestion = default_suggest_results_.empty() ? | 784 int did_not_accept_default_suggestion = default_suggest_results_.empty() ? |
| 786 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : | 785 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : |
| 787 TemplateURLRef::NO_SUGGESTION_CHOSEN; | 786 TemplateURLRef::NO_SUGGESTION_CHOSEN; |
| 788 if (verbatim_relevance > 0) { | 787 if (verbatim_relevance > 0) { |
| 789 AddMatchToMap(input_.text(), input_.text(), verbatim_relevance, | 788 AddMatchToMap(input_.text(), input_.text(), verbatim_relevance, |
| 790 AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, | 789 AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, |
| 791 did_not_accept_default_suggestion, false, &map); | 790 did_not_accept_default_suggestion, false, &map); |
| 792 } | 791 } |
| 792 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); | |
| 793 if (!keyword_input_text_.empty() && keyword_url && | |
|
Bart N.
2013/01/29 18:50:42
Most of the time keyword_input_text_ is empty, so
Mark P
2013/01/30 19:46:21
Done. (Perhaps I have too much respect for optimi
| |
| 794 !keyword_url->IsExtensionKeyword()) { | |
|
Bart N.
2013/01/29 18:50:42
It's not clear to me why we ignore extension keywo
Mark P
2013/01/30 19:46:21
Done.
| |
| 795 AddMatchToMap(keyword_input_text_, keyword_input_text_, | |
| 796 CalculateRelevanceForKeywordVerbatim( | |
| 797 input_.type(), input_.prefer_keyword()), | |
| 798 AutocompleteMatch::SEARCH_OTHER_ENGINE, | |
| 799 did_not_accept_keyword_suggestion, true, &map); | |
| 800 } | |
| 793 const size_t what_you_typed_size = map.size(); | 801 const size_t what_you_typed_size = map.size(); |
| 794 if (!default_provider_suggestion_.text.empty() && | 802 if (!default_provider_suggestion_.text.empty() && |
| 795 default_provider_suggestion_.type == INSTANT_SUGGESTION_SEARCH && | 803 default_provider_suggestion_.type == INSTANT_SUGGESTION_SEARCH && |
| 796 !input_.prevent_inline_autocomplete()) | 804 !input_.prevent_inline_autocomplete()) |
| 797 AddMatchToMap(input_.text() + default_provider_suggestion_.text, | 805 AddMatchToMap(input_.text() + default_provider_suggestion_.text, |
| 798 input_.text(), verbatim_relevance + 1, | 806 input_.text(), verbatim_relevance + 1, |
| 799 AutocompleteMatch::SEARCH_SUGGEST, | 807 AutocompleteMatch::SEARCH_SUGGEST, |
| 800 did_not_accept_default_suggestion, false, &map); | 808 did_not_accept_default_suggestion, false, &map); |
| 801 | 809 |
| 802 AddHistoryResultsToMap(keyword_history_results_, true, | 810 AddHistoryResultsToMap(keyword_history_results_, true, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 819 // |verbatim_relevance| here. | 827 // |verbatim_relevance| here. |
| 820 matches_.push_back(NavigationToMatch( | 828 matches_.push_back(NavigationToMatch( |
| 821 NavigationResult(GURL(UTF16ToUTF8(default_provider_suggestion_.text)), | 829 NavigationResult(GURL(UTF16ToUTF8(default_provider_suggestion_.text)), |
| 822 string16(), | 830 string16(), |
| 823 kNonURLVerbatimRelevance + 1), | 831 kNonURLVerbatimRelevance + 1), |
| 824 false)); | 832 false)); |
| 825 } | 833 } |
| 826 AddNavigationResultsToMatches(keyword_navigation_results_, true); | 834 AddNavigationResultsToMatches(keyword_navigation_results_, true); |
| 827 AddNavigationResultsToMatches(default_navigation_results_, false); | 835 AddNavigationResultsToMatches(default_navigation_results_, false); |
| 828 | 836 |
| 829 // Allow an additional match for "what you typed" if it's present. | 837 // Allow additional match(es) for "what you typed" results if present. |
|
Bart N.
2013/01/29 18:50:42
If I read the code correctly, we may end up with 5
Mark P
2013/01/30 19:46:21
Yes.
| |
| 830 const size_t max_total_matches = kMaxMatches + what_you_typed_size; | 838 const size_t max_total_matches = kMaxMatches + what_you_typed_size; |
|
Bart N.
2013/01/29 18:50:42
Technically, this is not "what you typed" matches,
Mark P
2013/01/30 19:46:21
Done.
| |
| 831 std::partial_sort(matches_.begin(), | 839 std::partial_sort(matches_.begin(), |
| 832 matches_.begin() + std::min(max_total_matches, matches_.size()), | 840 matches_.begin() + std::min(max_total_matches, matches_.size()), |
| 833 matches_.end(), &AutocompleteMatch::MoreRelevant); | 841 matches_.end(), &AutocompleteMatch::MoreRelevant); |
| 834 | 842 |
| 835 // If the top match is effectively 'verbatim' but exceeds the calculated | 843 // If the top match is effectively 'verbatim' but exceeds the calculated |
| 836 // verbatim relevance, and REQUESTED_URL |input_| has a |desired_tld| | 844 // verbatim relevance, and REQUESTED_URL |input_| has a |desired_tld| |
| 837 // (for example ".com" when the CTRL key is pressed for REQUESTED_URL input), | 845 // (for example ".com" when the CTRL key is pressed for REQUESTED_URL input), |
| 838 // promote a URL_WHAT_YOU_TYPED match to the top. Otherwise, these matches can | 846 // promote a URL_WHAT_YOU_TYPED match to the top. Otherwise, these matches can |
| 839 // stomp the HistoryURLProvider's similar transient URL_WHAT_YOU_TYPED match, | 847 // stomp the HistoryURLProvider's similar transient URL_WHAT_YOU_TYPED match, |
| 840 // and CTRL+ENTER will invoke the search instead of the expected navigation. | 848 // and CTRL+ENTER will invoke the search instead of the expected navigation. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 857 return matches_.front().relevance < CalculateRelevanceForVerbatim(); | 865 return matches_.front().relevance < CalculateRelevanceForVerbatim(); |
| 858 } | 866 } |
| 859 | 867 |
| 860 bool SearchProvider::IsTopMatchHighRankSearchForURL() const { | 868 bool SearchProvider::IsTopMatchHighRankSearchForURL() const { |
| 861 return input_.type() == AutocompleteInput::URL && | 869 return input_.type() == AutocompleteInput::URL && |
| 862 matches_.front().relevance > CalculateRelevanceForVerbatim() && | 870 matches_.front().relevance > CalculateRelevanceForVerbatim() && |
| 863 (matches_.front().type == AutocompleteMatch::SEARCH_SUGGEST || | 871 (matches_.front().type == AutocompleteMatch::SEARCH_SUGGEST || |
| 864 matches_.front().type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED); | 872 matches_.front().type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED); |
| 865 } | 873 } |
| 866 | 874 |
| 867 bool SearchProvider::IsTopMatchNotInlinable() const { | 875 bool SearchProvider::IsTopMatchNotInlinable() const { |
|
Bart N.
2013/01/29 18:50:42
Don't you want to modify this condition now to inc
Mark P
2013/01/30 19:46:21
I was thinking about doing that in another changel
| |
| 868 return matches_.front().type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED && | 876 return matches_.front().type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED && |
| 869 matches_.front().type != AutocompleteMatch::URL_WHAT_YOU_TYPED && | 877 matches_.front().type != AutocompleteMatch::URL_WHAT_YOU_TYPED && |
| 870 matches_.front().inline_autocomplete_offset == string16::npos && | 878 matches_.front().inline_autocomplete_offset == string16::npos && |
| 871 matches_.front().fill_into_edit != input_.text(); | 879 matches_.front().fill_into_edit != input_.text(); |
| 872 } | 880 } |
| 873 | 881 |
| 874 void SearchProvider::UpdateMatches() { | 882 void SearchProvider::UpdateMatches() { |
| 875 ConvertResultsToAutocompleteMatches(); | 883 ConvertResultsToAutocompleteMatches(); |
| 876 | 884 |
| 877 // Check constraints that may be violated by suggested relevances. | 885 // Check constraints that may be violated by suggested relevances. |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1079 | 1087 |
| 1080 case AutocompleteInput::URL: | 1088 case AutocompleteInput::URL: |
| 1081 return 850; | 1089 return 850; |
| 1082 | 1090 |
| 1083 default: | 1091 default: |
| 1084 NOTREACHED(); | 1092 NOTREACHED(); |
| 1085 return 0; | 1093 return 0; |
| 1086 } | 1094 } |
| 1087 } | 1095 } |
| 1088 | 1096 |
| 1097 // static | |
| 1098 int SearchProvider::CalculateRelevanceForKeywordVerbatim( | |
| 1099 AutocompleteInput::Type type, | |
| 1100 bool prefer_keyword) { | |
| 1101 if (prefer_keyword) | |
| 1102 return 1500; | |
| 1103 return (type == AutocompleteInput::QUERY) ? 1450 : 1100; | |
|
Bart N.
2013/01/29 18:50:42
Nit: We don't need () around the first expression.
Mark P
2013/01/30 19:46:21
Done.
| |
| 1104 } | |
| 1105 | |
| 1089 int SearchProvider::CalculateRelevanceForHistory( | 1106 int SearchProvider::CalculateRelevanceForHistory( |
| 1090 const Time& time, | 1107 const Time& time, |
| 1091 bool is_keyword, | 1108 bool is_keyword, |
| 1092 bool prevent_inline_autocomplete) const { | 1109 bool prevent_inline_autocomplete) const { |
| 1093 // The relevance of past searches falls off over time. There are two distinct | 1110 // The relevance of past searches falls off over time. There are two distinct |
| 1094 // equations used. If the first equation is used (searches to the primary | 1111 // equations used. If the first equation is used (searches to the primary |
| 1095 // provider that we want to inline autocomplete), the score starts at 1399 and | 1112 // provider that we want to inline autocomplete), the score starts at 1399 and |
| 1096 // falls to 1300. If the second equation is used the relevance of a search 15 | 1113 // falls to 1300. If the second equation is used the relevance of a search 15 |
| 1097 // minutes ago is discounted 50 points, while the relevance of a search two | 1114 // minutes ago is discounted 50 points, while the relevance of a search two |
| 1098 // weeks ago is discounted 450 points. | 1115 // weeks ago is discounted 450 points. |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1297 } | 1314 } |
| 1298 | 1315 |
| 1299 void SearchProvider::UpdateDone() { | 1316 void SearchProvider::UpdateDone() { |
| 1300 // We're done when the timer isn't running, there are no suggest queries | 1317 // We're done when the timer isn't running, there are no suggest queries |
| 1301 // pending, and we're not waiting on instant. | 1318 // pending, and we're not waiting on instant. |
| 1302 done_ = (!timer_.IsRunning() && (suggest_results_pending_ == 0) && | 1319 done_ = (!timer_.IsRunning() && (suggest_results_pending_ == 0) && |
| 1303 (instant_finalized_ || | 1320 (instant_finalized_ || |
| 1304 (!chrome::BrowserInstantController::IsInstantEnabled(profile_) && | 1321 (!chrome::BrowserInstantController::IsInstantEnabled(profile_) && |
| 1305 !chrome::search::IsInstantExtendedAPIEnabled(profile_)))); | 1322 !chrome::search::IsInstantExtendedAPIEnabled(profile_)))); |
| 1306 } | 1323 } |
| OLD | NEW |