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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(bool is_voice_query, 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 (const SearchProvider* provider : providers_) { | 63 for (const SearchProvider* provider : providers_) { |
64 for (SearchResult* result : provider->results()) { | 64 for (SearchResult* result : provider->results()) { |
65 DCHECK_GE(result->relevance(), 0.0); | |
66 DCHECK_LE(result->relevance(), 1.0); | |
67 DCHECK(!result->id().empty()); | 65 DCHECK(!result->id().empty()); |
68 | 66 |
| 67 // We cannot rely on providers to give relevance scores in the range |
| 68 // [0.0, 1.0] (e.g., PeopleProvider directly gives values from the |
| 69 // Google+ API). Clamp to that range. |
| 70 double relevance = std::min(std::max(result->relevance(), 0.0), 1.0); |
| 71 |
69 double boost = boost_; | 72 double boost = boost_; |
70 KnownResults::const_iterator known_it = | 73 KnownResults::const_iterator known_it = |
71 known_results.find(result->id()); | 74 known_results.find(result->id()); |
72 if (known_it != known_results.end()) { | 75 if (known_it != known_results.end()) { |
73 switch (known_it->second) { | 76 switch (known_it->second) { |
74 case PERFECT_PRIMARY: | 77 case PERFECT_PRIMARY: |
75 boost = 4.0; | 78 boost = 4.0; |
76 break; | 79 break; |
77 case PREFIX_PRIMARY: | 80 case PREFIX_PRIMARY: |
78 boost = 3.75; | 81 boost = 3.75; |
79 break; | 82 break; |
80 case PERFECT_SECONDARY: | 83 case PERFECT_SECONDARY: |
81 boost = 3.25; | 84 boost = 3.25; |
82 break; | 85 break; |
83 case PREFIX_SECONDARY: | 86 case PREFIX_SECONDARY: |
84 boost = 3.0; | 87 boost = 3.0; |
85 break; | 88 break; |
86 case UNKNOWN_RESULT: | 89 case UNKNOWN_RESULT: |
87 NOTREACHED() << "Unknown result in KnownResults?"; | 90 NOTREACHED() << "Unknown result in KnownResults?"; |
88 break; | 91 break; |
89 } | 92 } |
90 } | 93 } |
91 | 94 |
92 // If this is a voice query, voice results receive a massive boost. | 95 // If this is a voice query, voice results receive a massive boost. |
93 if (is_voice_query && result->voice_result()) | 96 if (is_voice_query && result->voice_result()) |
94 boost += 4.0; | 97 boost += 4.0; |
95 | 98 |
96 results_.push_back(SortData(result, result->relevance() + boost)); | 99 results_.push_back(SortData(result, relevance + boost)); |
97 } | 100 } |
98 } | 101 } |
99 | 102 |
100 std::sort(results_.begin(), results_.end()); | 103 std::sort(results_.begin(), results_.end()); |
101 if (max_results_ != kNoMaxResultsLimit && results_.size() > max_results_) | 104 if (max_results_ != kNoMaxResultsLimit && results_.size() > max_results_) |
102 results_.resize(max_results_); | 105 results_.resize(max_results_); |
103 } | 106 } |
104 | 107 |
105 const SortedResults& results() const { return results_; } | 108 const SortedResults& results() const { return results_; } |
106 | 109 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 results->swap(final); | 246 results->swap(final); |
244 } | 247 } |
245 | 248 |
246 void Mixer::FetchResults(bool is_voice_query, | 249 void Mixer::FetchResults(bool is_voice_query, |
247 const KnownResults& known_results) { | 250 const KnownResults& known_results) { |
248 for (const auto& item : groups_) | 251 for (const auto& item : groups_) |
249 item.second->FetchResults(is_voice_query, known_results); | 252 item.second->FetchResults(is_voice_query, known_results); |
250 } | 253 } |
251 | 254 |
252 } // namespace app_list | 255 } // namespace app_list |
OLD | NEW |