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 "components/omnibox/browser/search_provider.h" | 5 #include "components/omnibox/browser/search_provider.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <cmath> | 9 #include <cmath> |
10 #include <utility> | 10 #include <utility> |
(...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 matches.push_back(i->second); | 1038 matches.push_back(i->second); |
1039 | 1039 |
1040 AddNavigationResultsToMatches(keyword_results_.navigation_results, &matches); | 1040 AddNavigationResultsToMatches(keyword_results_.navigation_results, &matches); |
1041 AddNavigationResultsToMatches(default_results_.navigation_results, &matches); | 1041 AddNavigationResultsToMatches(default_results_.navigation_results, &matches); |
1042 | 1042 |
1043 // Now add the most relevant matches to |matches_|. We take up to kMaxMatches | 1043 // Now add the most relevant matches to |matches_|. We take up to kMaxMatches |
1044 // suggest/navsuggest matches, regardless of origin. We always include in | 1044 // suggest/navsuggest matches, regardless of origin. We always include in |
1045 // that set a legal default match if possible. If Instant Extended is enabled | 1045 // that set a legal default match if possible. If Instant Extended is enabled |
1046 // and we have server-provided (and thus hopefully more accurate) scores for | 1046 // and we have server-provided (and thus hopefully more accurate) scores for |
1047 // some suggestions, we allow more of those, until we reach | 1047 // some suggestions, we allow more of those, until we reach |
1048 // AutocompleteResult::kMaxMatches total matches (that is, enough to fill the | 1048 // AutocompleteResult::GetMaxMatches() total matches (that is, enough to fill |
1049 // whole popup). | 1049 // the whole popup). |
1050 // | 1050 // |
1051 // We will always return any verbatim matches, no matter how we obtained their | 1051 // We will always return any verbatim matches, no matter how we obtained their |
1052 // scores, unless we have already accepted AutocompleteResult::kMaxMatches | 1052 // scores, unless we have already accepted AutocompleteResult::GetMaxMatches() |
1053 // higher-scoring matches under the conditions above. | 1053 // higher-scoring matches under the conditions above. |
1054 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); | 1054 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); |
1055 | 1055 |
1056 // Guarantee that if there's a legal default match anywhere in the result | 1056 // Guarantee that if there's a legal default match anywhere in the result |
1057 // set that it'll get returned. The rotate() call does this by moving the | 1057 // set that it'll get returned. The rotate() call does this by moving the |
1058 // default match to the front of the list. | 1058 // default match to the front of the list. |
1059 ACMatches::iterator default_match = | 1059 ACMatches::iterator default_match = |
1060 AutocompleteResult::FindTopMatch(&matches); | 1060 AutocompleteResult::FindTopMatch(&matches); |
1061 if (default_match != matches.end()) | 1061 if (default_match != matches.end()) |
1062 std::rotate(matches.begin(), default_match, default_match + 1); | 1062 std::rotate(matches.begin(), default_match, default_match + 1); |
1063 | 1063 |
1064 // It's possible to get a copy of an answer from previous matches and get the | 1064 // It's possible to get a copy of an answer from previous matches and get the |
1065 // same or a different answer to another server-provided suggestion. In the | 1065 // same or a different answer to another server-provided suggestion. In the |
1066 // future we may decide that we want to have answers attached to multiple | 1066 // future we may decide that we want to have answers attached to multiple |
1067 // suggestions, but the current assumption is that there should only ever be | 1067 // suggestions, but the current assumption is that there should only ever be |
1068 // one suggestion with an answer. To maintain this assumption, remove any | 1068 // one suggestion with an answer. To maintain this assumption, remove any |
1069 // answers after the first. | 1069 // answers after the first. |
1070 RemoveExtraAnswers(&matches); | 1070 RemoveExtraAnswers(&matches); |
1071 | 1071 |
1072 matches_.clear(); | 1072 matches_.clear(); |
1073 size_t num_suggestions = 0; | 1073 size_t num_suggestions = 0; |
1074 for (ACMatches::const_iterator i(matches.begin()); | 1074 for (ACMatches::const_iterator i(matches.begin()); |
1075 (i != matches.end()) && | 1075 (i != matches.end()) && |
1076 (matches_.size() < AutocompleteResult::kMaxMatches); | 1076 (matches_.size() < AutocompleteResult::GetMaxMatches()); |
1077 ++i) { | 1077 ++i) { |
1078 // SEARCH_OTHER_ENGINE is only used in the SearchProvider for the keyword | 1078 // SEARCH_OTHER_ENGINE is only used in the SearchProvider for the keyword |
1079 // verbatim result, so this condition basically means "if this match is a | 1079 // verbatim result, so this condition basically means "if this match is a |
1080 // suggestion of some sort". | 1080 // suggestion of some sort". |
1081 if ((i->type != AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED) && | 1081 if ((i->type != AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED) && |
1082 (i->type != AutocompleteMatchType::SEARCH_OTHER_ENGINE)) { | 1082 (i->type != AutocompleteMatchType::SEARCH_OTHER_ENGINE)) { |
1083 // If we've already hit the limit on non-server-scored suggestions, and | 1083 // If we've already hit the limit on non-server-scored suggestions, and |
1084 // this isn't a server-scored suggestion we can add, skip it. | 1084 // this isn't a server-scored suggestion we can add, skip it. |
1085 if ((num_suggestions >= kMaxMatches) && | 1085 if ((num_suggestions >= kMaxMatches) && |
1086 (!search::IsInstantExtendedAPIEnabled() || | 1086 (!search::IsInstantExtendedAPIEnabled() || |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1545 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) | 1545 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) |
1546 matches.push_back(i->second); | 1546 matches.push_back(i->second); |
1547 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); | 1547 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); |
1548 | 1548 |
1549 // If there is a top scoring entry, find the corresponding answer. | 1549 // If there is a top scoring entry, find the corresponding answer. |
1550 if (!matches.empty()) | 1550 if (!matches.empty()) |
1551 return answers_cache_.GetTopAnswerEntry(matches[0].contents); | 1551 return answers_cache_.GetTopAnswerEntry(matches[0].contents); |
1552 | 1552 |
1553 return AnswersQueryData(); | 1553 return AnswersQueryData(); |
1554 } | 1554 } |
OLD | NEW |