| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ui/app_list/search/mixer.h" | 5 #include "ui/app_list/search/mixer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 // Used to group relevant providers together fox mixing their results. | 51 // Used to group relevant providers together fox mixing their results. |
| 52 class Mixer::Group { | 52 class Mixer::Group { |
| 53 public: | 53 public: |
| 54 Group(size_t max_results, double boost) | 54 Group(size_t max_results, double boost) |
| 55 : max_results_(max_results), boost_(boost) {} | 55 : max_results_(max_results), boost_(boost) {} |
| 56 ~Group() {} | 56 ~Group() {} |
| 57 | 57 |
| 58 void AddProvider(SearchProvider* provider) { providers_.push_back(provider); } | 58 void AddProvider(SearchProvider* provider) { providers_.push_back(provider); } |
| 59 | 59 |
| 60 void FetchResults(const KnownResults& known_results) { | 60 void FetchResults(bool is_voice_query, const KnownResults& known_results) { |
| 61 results_.clear(); | 61 results_.clear(); |
| 62 | 62 |
| 63 for (Providers::const_iterator provider_it = providers_.begin(); | 63 for (Providers::const_iterator provider_it = providers_.begin(); |
| 64 provider_it != providers_.end(); | 64 provider_it != providers_.end(); |
| 65 ++provider_it) { | 65 ++provider_it) { |
| 66 for (SearchProvider::Results::const_iterator result_it = | 66 for (SearchProvider::Results::const_iterator result_it = |
| 67 (*provider_it)->results().begin(); | 67 (*provider_it)->results().begin(); |
| 68 result_it != (*provider_it)->results().end(); | 68 result_it != (*provider_it)->results().end(); |
| 69 ++result_it) { | 69 ++result_it) { |
| 70 DCHECK_GE((*result_it)->relevance(), 0.0); | 70 DCHECK_GE((*result_it)->relevance(), 0.0); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 87 break; | 87 break; |
| 88 case PREFIX_SECONDARY: | 88 case PREFIX_SECONDARY: |
| 89 boost = 3.0; | 89 boost = 3.0; |
| 90 break; | 90 break; |
| 91 case UNKNOWN_RESULT: | 91 case UNKNOWN_RESULT: |
| 92 NOTREACHED() << "Unknown result in KnownResults?"; | 92 NOTREACHED() << "Unknown result in KnownResults?"; |
| 93 break; | 93 break; |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 // If this is a voice query, voice results receive a massive boost. |
| 98 if (is_voice_query && (*result_it)->voice_result()) |
| 99 boost += 4.0; |
| 100 |
| 97 results_.push_back( | 101 results_.push_back( |
| 98 SortData(*result_it, (*result_it)->relevance() + boost)); | 102 SortData(*result_it, (*result_it)->relevance() + boost)); |
| 99 } | 103 } |
| 100 } | 104 } |
| 101 | 105 |
| 102 std::sort(results_.begin(), results_.end()); | 106 std::sort(results_.begin(), results_.end()); |
| 103 if (max_results_ != kNoMaxResultsLimit && results_.size() > max_results_) | 107 if (max_results_ != kNoMaxResultsLimit && results_.size() > max_results_) |
| 104 results_.resize(max_results_); | 108 results_.resize(max_results_); |
| 105 } | 109 } |
| 106 | 110 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 128 groups_[OMNIBOX_GROUP].reset(new Group(kNoMaxResultsLimit, 2.0)); | 132 groups_[OMNIBOX_GROUP].reset(new Group(kNoMaxResultsLimit, 2.0)); |
| 129 groups_[WEBSTORE_GROUP].reset(new Group(kMaxWebstoreResults, 1.0)); | 133 groups_[WEBSTORE_GROUP].reset(new Group(kMaxWebstoreResults, 1.0)); |
| 130 groups_[PEOPLE_GROUP].reset(new Group(kMaxPeopleResults, 0.0)); | 134 groups_[PEOPLE_GROUP].reset(new Group(kMaxPeopleResults, 0.0)); |
| 131 groups_[SUGGESTIONS_GROUP].reset(new Group(kMaxSuggestionsResults, 3.0)); | 135 groups_[SUGGESTIONS_GROUP].reset(new Group(kMaxSuggestionsResults, 3.0)); |
| 132 } | 136 } |
| 133 | 137 |
| 134 void Mixer::AddProviderToGroup(GroupId group, SearchProvider* provider) { | 138 void Mixer::AddProviderToGroup(GroupId group, SearchProvider* provider) { |
| 135 groups_[group]->AddProvider(provider); | 139 groups_[group]->AddProvider(provider); |
| 136 } | 140 } |
| 137 | 141 |
| 138 void Mixer::MixAndPublish(const KnownResults& known_results) { | 142 void Mixer::MixAndPublish(bool is_voice_query, |
| 139 FetchResults(known_results); | 143 const KnownResults& known_results) { |
| 144 FetchResults(is_voice_query, known_results); |
| 140 | 145 |
| 141 SortedResults results; | 146 SortedResults results; |
| 142 results.reserve(kMaxResults); | 147 results.reserve(kMaxResults); |
| 143 | 148 |
| 144 const Group& main_group = *groups_[MAIN_GROUP]; | 149 const Group& main_group = *groups_[MAIN_GROUP]; |
| 145 const Group& omnibox_group = *groups_[OMNIBOX_GROUP]; | 150 const Group& omnibox_group = *groups_[OMNIBOX_GROUP]; |
| 146 const Group& webstore_group = *groups_[WEBSTORE_GROUP]; | 151 const Group& webstore_group = *groups_[WEBSTORE_GROUP]; |
| 147 const Group& people_group = *groups_[PEOPLE_GROUP]; | 152 const Group& people_group = *groups_[PEOPLE_GROUP]; |
| 148 const Group& suggestions_group = *groups_[SUGGESTIONS_GROUP]; | 153 const Group& suggestions_group = *groups_[SUGGESTIONS_GROUP]; |
| 149 | 154 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 if (id_set.find(id) != id_set.end()) | 245 if (id_set.find(id) != id_set.end()) |
| 241 continue; | 246 continue; |
| 242 | 247 |
| 243 id_set.insert(id); | 248 id_set.insert(id); |
| 244 final.push_back(*it); | 249 final.push_back(*it); |
| 245 } | 250 } |
| 246 | 251 |
| 247 results->swap(final); | 252 results->swap(final); |
| 248 } | 253 } |
| 249 | 254 |
| 250 void Mixer::FetchResults(const KnownResults& known_results) { | 255 void Mixer::FetchResults(bool is_voice_query, |
| 256 const KnownResults& known_results) { |
| 251 for (const auto& item : groups_) | 257 for (const auto& item : groups_) |
| 252 item.second->FetchResults(known_results); | 258 item.second->FetchResults(is_voice_query, known_results); |
| 253 } | 259 } |
| 254 | 260 |
| 255 } // namespace app_list | 261 } // namespace app_list |
| OLD | NEW |