OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/history_quick_provider.h" | 5 #include "chrome/browser/autocomplete/history_quick_provider.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/i18n/break_iterator.h" | 10 #include "base/i18n/break_iterator.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 // inline autocompletd. Each such result gets the next available | 105 // inline autocompletd. Each such result gets the next available |
106 // |max_match_score|. Upon use of |max_match_score| it is decremented. | 106 // |max_match_score|. Upon use of |max_match_score| it is decremented. |
107 // All subsequent matches must be clamped to retain match results ordering. | 107 // All subsequent matches must be clamped to retain match results ordering. |
108 int max_match_score = autocomplete_input_.prevent_inline_autocomplete() ? | 108 int max_match_score = autocomplete_input_.prevent_inline_autocomplete() ? |
109 kMaxNonInliningScore : -1; | 109 kMaxNonInliningScore : -1; |
110 for (ScoredHistoryMatches::const_iterator match_iter = matches.begin(); | 110 for (ScoredHistoryMatches::const_iterator match_iter = matches.begin(); |
111 match_iter != matches.end(); ++match_iter) { | 111 match_iter != matches.end(); ++match_iter) { |
112 const ScoredHistoryMatch& history_match(*match_iter); | 112 const ScoredHistoryMatch& history_match(*match_iter); |
113 if (history_match.raw_score > 0) { | 113 if (history_match.raw_score > 0) { |
114 AutocompleteMatch ac_match = QuickMatchToACMatch( | 114 AutocompleteMatch ac_match = QuickMatchToACMatch( |
115 history_match, | 115 history_match, matches, |
116 PreventInlineAutocomplete(autocomplete_input_), | 116 PreventInlineAutocomplete(autocomplete_input_), |
117 &max_match_score); | 117 &max_match_score); |
| 118 UMA_HISTOGRAM_COUNTS_100("Autocomplete.Confidence_HistoryQuick", |
| 119 ac_match.confidence * 100); |
118 matches_.push_back(ac_match); | 120 matches_.push_back(ac_match); |
119 } | 121 } |
120 } | 122 } |
121 } | 123 } |
122 | 124 |
123 // static | 125 // static |
124 const int HistoryQuickProvider::kMaxNonInliningScore = | 126 const int HistoryQuickProvider::kMaxNonInliningScore = |
125 AutocompleteResult::kLowestDefaultScore - 1; | 127 AutocompleteResult::kLowestDefaultScore - 1; |
126 | 128 |
127 AutocompleteMatch HistoryQuickProvider::QuickMatchToACMatch( | 129 AutocompleteMatch HistoryQuickProvider::QuickMatchToACMatch( |
128 const ScoredHistoryMatch& history_match, | 130 const ScoredHistoryMatch& history_match, |
| 131 const ScoredHistoryMatches& history_matches, |
129 bool prevent_inline_autocomplete, | 132 bool prevent_inline_autocomplete, |
130 int* max_match_score) { | 133 int* max_match_score) { |
131 DCHECK(max_match_score); | 134 DCHECK(max_match_score); |
132 const history::URLRow& info = history_match.url_info; | 135 const history::URLRow& info = history_match.url_info; |
133 int score = CalculateRelevance(history_match, max_match_score); | 136 int score = CalculateRelevance(history_match, max_match_score); |
134 AutocompleteMatch match(this, score, !!info.visit_count(), | 137 float confidence = CalculateConfidence(history_match, history_matches); |
| 138 AutocompleteMatch match(this, score, confidence, !!info.visit_count(), |
135 history_match.url_matches.empty() ? | 139 history_match.url_matches.empty() ? |
136 AutocompleteMatch::HISTORY_URL : | 140 AutocompleteMatch::HISTORY_URL : |
137 AutocompleteMatch::HISTORY_TITLE); | 141 AutocompleteMatch::HISTORY_TITLE); |
138 match.destination_url = info.url(); | 142 match.destination_url = info.url(); |
139 DCHECK(match.destination_url.is_valid()); | 143 DCHECK(match.destination_url.is_valid()); |
140 | 144 |
141 // Format the URL autocomplete presentation. | 145 // Format the URL autocomplete presentation. |
142 std::vector<size_t> offsets = | 146 std::vector<size_t> offsets = |
143 InMemoryURLIndex::OffsetsFromTermMatches(history_match.url_matches); | 147 InMemoryURLIndex::OffsetsFromTermMatches(history_match.url_matches); |
144 match.contents = | 148 match.contents = |
145 net::FormatUrlWithOffsets(info.url(), languages_, net::kFormatUrlOmitAll, | 149 net::FormatUrlWithOffsets(info.url(), languages_, net::kFormatUrlOmitAll, |
146 UnescapeRule::SPACES, NULL, NULL, &offsets); | 150 UnescapeRule::SPACES, NULL, NULL, &offsets); |
147 history::TermMatches new_matches = | 151 history::TermMatches new_matches = |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 // at the beginning of the result's URL and there is exactly one substring | 198 // at the beginning of the result's URL and there is exactly one substring |
195 // match in the URL. | 199 // match in the URL. |
196 int score = (history_match.can_inline) ? history_match.raw_score : | 200 int score = (history_match.can_inline) ? history_match.raw_score : |
197 std::min(kMaxNonInliningScore, history_match.raw_score); | 201 std::min(kMaxNonInliningScore, history_match.raw_score); |
198 *max_match_score = ((*max_match_score < 0) ? | 202 *max_match_score = ((*max_match_score < 0) ? |
199 score : std::min(score, *max_match_score)) - 1; | 203 score : std::min(score, *max_match_score)) - 1; |
200 return *max_match_score + 1; | 204 return *max_match_score + 1; |
201 } | 205 } |
202 | 206 |
203 // static | 207 // static |
| 208 float HistoryQuickProvider::CalculateConfidence( |
| 209 const ScoredHistoryMatch& match, |
| 210 const ScoredHistoryMatches& matches) { |
| 211 float denominator = 0.0f; |
| 212 for (ScoredHistoryMatches::const_iterator it = matches.begin(); |
| 213 it != matches.end(); ++it) { |
| 214 denominator += it->raw_score; |
| 215 } |
| 216 DCHECK(denominator > 0); |
| 217 |
| 218 return static_cast<float>(match.raw_score) / denominator; |
| 219 } |
| 220 |
| 221 // static |
204 ACMatchClassifications HistoryQuickProvider::SpansFromTermMatch( | 222 ACMatchClassifications HistoryQuickProvider::SpansFromTermMatch( |
205 const history::TermMatches& matches, | 223 const history::TermMatches& matches, |
206 size_t text_length, | 224 size_t text_length, |
207 bool is_url) { | 225 bool is_url) { |
208 ACMatchClassification::Style url_style = | 226 ACMatchClassification::Style url_style = |
209 is_url ? ACMatchClassification::URL : ACMatchClassification::NONE; | 227 is_url ? ACMatchClassification::URL : ACMatchClassification::NONE; |
210 ACMatchClassifications spans; | 228 ACMatchClassifications spans; |
211 if (matches.empty()) { | 229 if (matches.empty()) { |
212 if (text_length) | 230 if (text_length) |
213 spans.push_back(ACMatchClassification(0, url_style)); | 231 spans.push_back(ACMatchClassification(0, url_style)); |
(...skipping 10 matching lines...) Expand all Loading... |
224 do { | 242 do { |
225 offset += matches[i].length; | 243 offset += matches[i].length; |
226 ++i; | 244 ++i; |
227 } while ((i < match_count) && (offset == matches[i].offset)); | 245 } while ((i < match_count) && (offset == matches[i].offset)); |
228 if (offset < text_length) | 246 if (offset < text_length) |
229 spans.push_back(ACMatchClassification(offset, url_style)); | 247 spans.push_back(ACMatchClassification(offset, url_style)); |
230 } | 248 } |
231 | 249 |
232 return spans; | 250 return spans; |
233 } | 251 } |
OLD | NEW |