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 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
839 AutocompleteMatch match = HistoryURLProvider::SuggestExactInput( | 839 AutocompleteMatch match = HistoryURLProvider::SuggestExactInput( |
840 this, input_, !HasHTTPScheme(input_.text())); | 840 this, input_, !HasHTTPScheme(input_.text())); |
841 match.relevance = matches_.front().relevance + 1; | 841 match.relevance = matches_.front().relevance + 1; |
842 matches_.insert(matches_.begin(), match); | 842 matches_.insert(matches_.begin(), match); |
843 } | 843 } |
844 | 844 |
845 if (matches_.size() > max_total_matches) | 845 if (matches_.size() > max_total_matches) |
846 matches_.resize(max_total_matches); | 846 matches_.resize(max_total_matches); |
847 } | 847 } |
848 | 848 |
849 bool SearchProvider::IsTopMatchScoreTooLow() const { | 849 bool SearchProvider::IsTopMatchScoreTooLow( |
850 return matches_.front().relevance < CalculateRelevanceForVerbatim(); | 850 int keyword_search_what_you_typed_relevance) const { |
851 return std::max(matches_.front().relevance, | |
852 keyword_search_what_you_typed_relevance) < | |
853 CalculateRelevanceForVerbatim(); | |
Peter Kasting
2013/01/21 20:22:57
Nit: Indent 4
Mark P
2013/01/21 20:57:45
Done.
| |
851 } | 854 } |
852 | 855 |
853 bool SearchProvider::IsTopMatchHighRankSearchForURL() const { | 856 bool SearchProvider::IsTopMatchHighRankSearchForURL( |
857 int keyword_search_what_you_typed_relevance) const { | |
854 return input_.type() == AutocompleteInput::URL && | 858 return input_.type() == AutocompleteInput::URL && |
855 matches_.front().relevance > CalculateRelevanceForVerbatim() && | 859 ((keyword_search_what_you_typed_relevance > |
856 (matches_.front().type == AutocompleteMatch::SEARCH_SUGGEST || | 860 matches_.front().relevance) || |
857 matches_.front().type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED); | 861 (matches_.front().relevance > CalculateRelevanceForVerbatim() && |
862 (matches_.front().type == AutocompleteMatch::SEARCH_SUGGEST || | |
863 matches_.front().type == | |
864 AutocompleteMatch::SEARCH_WHAT_YOU_TYPED))); | |
858 } | 865 } |
859 | 866 |
860 bool SearchProvider::IsTopMatchNotInlinable() const { | 867 bool SearchProvider::IsTopMatchNotInlinable( |
861 return matches_.front().type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED && | 868 int keyword_search_what_you_typed_relevance) const { |
869 return (keyword_search_what_you_typed_relevance < | |
870 matches_.front().relevance) && | |
871 matches_.front().type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED && | |
862 matches_.front().type != AutocompleteMatch::URL_WHAT_YOU_TYPED && | 872 matches_.front().type != AutocompleteMatch::URL_WHAT_YOU_TYPED && |
863 matches_.front().inline_autocomplete_offset == string16::npos && | 873 matches_.front().inline_autocomplete_offset == string16::npos && |
864 matches_.front().fill_into_edit != input_.text(); | 874 matches_.front().fill_into_edit != input_.text(); |
865 } | 875 } |
866 | 876 |
867 void SearchProvider::UpdateMatches() { | 877 void SearchProvider::UpdateMatches() { |
868 ConvertResultsToAutocompleteMatches(); | 878 ConvertResultsToAutocompleteMatches(); |
869 | 879 |
880 const int keyword_search_what_you_typed_relevance = | |
881 providers_.keyword_provider().empty() ? 0 : | |
882 KeywordProvider::CalculateRelevance(input_.type(), true, true, | |
883 input_.prefer_keyword(), input_.allow_exact_keyword_match()); | |
884 | |
870 // Check constraints that may be violated by suggested relevances. | 885 // Check constraints that may be violated by suggested relevances. |
871 if (!matches_.empty() && | 886 if (!matches_.empty() && |
872 (has_suggested_relevance_ || verbatim_relevance_ >= 0)) { | 887 (has_suggested_relevance_ || verbatim_relevance_ >= 0)) { |
873 // These two blocks attempt to repair undesriable behavior by suggested | 888 // These two blocks attempt to repair undesriable behavior by suggested |
874 // relevances with minimal impact, preserving other suggested relevances. | 889 // relevances with minimal impact, preserving other suggested relevances. |
875 if (IsTopMatchScoreTooLow()) { | 890 if (IsTopMatchScoreTooLow(keyword_search_what_you_typed_relevance)) { |
876 // Disregard the suggested verbatim relevance if the top score is below | 891 // Disregard the suggested verbatim relevance if the top score is below |
877 // the usual verbatim value. For example, a BarProvider may rely on | 892 // the usual verbatim value. For example, a BarProvider may rely on |
878 // SearchProvider's verbatim or inlineable matches for input "foo" to | 893 // SearchProvider's verbatim or inlineable matches for input "foo" to |
879 // always outrank its own lowly-ranked non-inlineable "bar" match. | 894 // always outrank its own lowly-ranked non-inlineable "bar" match. |
880 verbatim_relevance_ = -1; | 895 verbatim_relevance_ = -1; |
881 ConvertResultsToAutocompleteMatches(); | 896 ConvertResultsToAutocompleteMatches(); |
882 } | 897 } |
883 if (IsTopMatchHighRankSearchForURL()) { | 898 if (IsTopMatchHighRankSearchForURL( |
899 keyword_search_what_you_typed_relevance)) { | |
884 // Disregard the suggested search and verbatim relevances if the input | 900 // Disregard the suggested search and verbatim relevances if the input |
885 // type is URL and the top match is a highly-ranked search suggestion. | 901 // type is URL and the top match is a highly-ranked search suggestion. |
886 // For example, prevent a search for "foo.com" from outranking another | 902 // For example, prevent a search for "foo.com" from outranking another |
887 // provider's navigation for "foo.com" or "foo.com/url_from_history". | 903 // provider's navigation for "foo.com" or "foo.com/url_from_history". |
888 ApplyCalculatedSuggestRelevance(&keyword_suggest_results_, true); | 904 ApplyCalculatedSuggestRelevance(&keyword_suggest_results_, true); |
889 ApplyCalculatedSuggestRelevance(&default_suggest_results_, false); | 905 ApplyCalculatedSuggestRelevance(&default_suggest_results_, false); |
890 verbatim_relevance_ = -1; | 906 verbatim_relevance_ = -1; |
891 ConvertResultsToAutocompleteMatches(); | 907 ConvertResultsToAutocompleteMatches(); |
892 } | 908 } |
893 if (IsTopMatchNotInlinable()) { | 909 if (IsTopMatchNotInlinable(keyword_search_what_you_typed_relevance)) { |
894 // Disregard suggested relevances if the top match is not SWYT, inlinable, | 910 // Disregard suggested relevances if the top match is not SWYT, inlinable, |
895 // or URL_WHAT_YOU_TYPED (which may be top match regardless of inlining). | 911 // or URL_WHAT_YOU_TYPED (which may be top match regardless of inlining). |
896 // For example, input "foo" should not invoke a search for "bar", which | 912 // For example, input "foo" should not invoke a search for "bar", which |
897 // would happen if the "bar" search match outranked all other matches. | 913 // would happen if the "bar" search match outranked all other matches. |
898 ApplyCalculatedRelevance(); | 914 ApplyCalculatedRelevance(); |
899 ConvertResultsToAutocompleteMatches(); | 915 ConvertResultsToAutocompleteMatches(); |
900 } | 916 } |
901 DCHECK(!IsTopMatchScoreTooLow()); | 917 DCHECK(!IsTopMatchScoreTooLow(keyword_search_what_you_typed_relevance)); |
902 DCHECK(!IsTopMatchHighRankSearchForURL()); | 918 DCHECK(!IsTopMatchHighRankSearchForURL( |
903 DCHECK(!IsTopMatchNotInlinable()); | 919 keyword_search_what_you_typed_relevance)); |
920 DCHECK(!IsTopMatchNotInlinable(keyword_search_what_you_typed_relevance)); | |
904 } | 921 } |
905 | 922 |
906 UpdateStarredStateOfMatches(); | 923 UpdateStarredStateOfMatches(); |
907 UpdateDone(); | 924 UpdateDone(); |
908 } | 925 } |
909 | 926 |
910 void SearchProvider::AddNavigationResultsToMatches( | 927 void SearchProvider::AddNavigationResultsToMatches( |
911 const NavigationResults& navigation_results, | 928 const NavigationResults& navigation_results, |
912 bool is_keyword) { | 929 bool is_keyword) { |
913 if (navigation_results.empty()) | 930 if (navigation_results.empty()) |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1290 } | 1307 } |
1291 | 1308 |
1292 void SearchProvider::UpdateDone() { | 1309 void SearchProvider::UpdateDone() { |
1293 // We're done when the timer isn't running, there are no suggest queries | 1310 // We're done when the timer isn't running, there are no suggest queries |
1294 // pending, and we're not waiting on instant. | 1311 // pending, and we're not waiting on instant. |
1295 done_ = (!timer_.IsRunning() && (suggest_results_pending_ == 0) && | 1312 done_ = (!timer_.IsRunning() && (suggest_results_pending_ == 0) && |
1296 (instant_finalized_ || | 1313 (instant_finalized_ || |
1297 (!chrome::BrowserInstantController::IsInstantEnabled(profile_) && | 1314 (!chrome::BrowserInstantController::IsInstantEnabled(profile_) && |
1298 !chrome::search::IsInstantExtendedAPIEnabled(profile_)))); | 1315 !chrome::search::IsInstantExtendedAPIEnabled(profile_)))); |
1299 } | 1316 } |
OLD | NEW |