Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(575)

Side by Side Diff: components/omnibox/search_suggestion_parser.cc

Issue 1134123004: Omnibox - Use Case Insensitive Matching when Bolding Query Suggestions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove extra include Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/autocomplete/search_provider_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/search_suggestion_parser.h" 5 #include "components/omnibox/search_suggestion_parser.h"
6 6
7 #include <algorithm>
8
7 #include "base/i18n/icu_string_conversions.h" 9 #include "base/i18n/icu_string_conversions.h"
8 #include "base/json/json_string_value_serializer.h" 10 #include "base/json/json_string_value_serializer.h"
9 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
10 #include "base/logging.h" 12 #include "base/logging.h"
11 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
12 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 17 #include "base/values.h"
16 #include "components/omnibox/autocomplete_input.h" 18 #include "components/omnibox/autocomplete_input.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 const size_t contents_index = 147 const size_t contents_index =
146 suggestion_.length() - match_contents_.length(); 148 suggestion_.length() - match_contents_.length();
147 // Ensure the query starts with the input text, and ends with the match 149 // Ensure the query starts with the input text, and ends with the match
148 // contents, and the input text has an overlap with contents. 150 // contents, and the input text has an overlap with contents.
149 if (StartsWith(suggestion_, input_text, true) && 151 if (StartsWith(suggestion_, input_text, true) &&
150 EndsWith(suggestion_, match_contents_, true) && 152 EndsWith(suggestion_, match_contents_, true) &&
151 (input_text.length() > contents_index)) { 153 (input_text.length() > contents_index)) {
152 lookup_text = input_text.substr(contents_index); 154 lookup_text = input_text.substr(contents_index);
153 } 155 }
154 } 156 }
155 size_t lookup_position = match_contents_.find(lookup_text); 157 // Do a case-insensitive search for |lookup_text|.
156 if (!allow_bolding_all && (lookup_position == base::string16::npos)) { 158 base::string16::const_iterator lookup_position = std::search(
159 match_contents_.begin(), match_contents_.end(), lookup_text.begin(),
160 lookup_text.end(), base::CaseInsensitiveCompare<wchar_t>());
Peter Kasting 2015/05/11 23:40:37 wchar_t seems wrong, shouldn't it be char16?
Mark P 2015/05/11 23:45:56 Already fixed; the new patchset was being uploaded
161 if (!allow_bolding_all && (lookup_position == match_contents_.end())) {
157 // Bail if the code below to update the bolding would bold the whole 162 // Bail if the code below to update the bolding would bold the whole
158 // string. Note that the string may already be entirely bolded; if 163 // string. Note that the string may already be entirely bolded; if
159 // so, leave it as is. 164 // so, leave it as is.
160 return; 165 return;
161 } 166 }
162 match_contents_class_.clear(); 167 match_contents_class_.clear();
163 // We do intra-string highlighting for suggestions - the suggested segment 168 // We do intra-string highlighting for suggestions - the suggested segment
164 // will be highlighted, e.g. for input_text = "you" the suggestion may be 169 // will be highlighted, e.g. for input_text = "you" the suggestion may be
165 // "youtube", so we'll bold the "tube" section: you*tube*. 170 // "youtube", so we'll bold the "tube" section: you*tube*.
166 if (input_text != match_contents_) { 171 if (input_text != match_contents_) {
167 if (lookup_position == base::string16::npos) { 172 if (lookup_position == match_contents_.end()) {
168 // The input text is not a substring of the query string, e.g. input 173 // The input text is not a substring of the query string, e.g. input
169 // text is "slasdot" and the query string is "slashdot", so we bold the 174 // text is "slasdot" and the query string is "slashdot", so we bold the
170 // whole thing. 175 // whole thing.
171 match_contents_class_.push_back( 176 match_contents_class_.push_back(
172 ACMatchClassification(0, ACMatchClassification::MATCH)); 177 ACMatchClassification(0, ACMatchClassification::MATCH));
173 } else { 178 } else {
174 // We don't iterate over the string here annotating all matches because 179 // We don't iterate over the string here annotating all matches because
175 // it looks odd to have every occurrence of a substring that may be as 180 // it looks odd to have every occurrence of a substring that may be as
176 // short as a single character highlighted in a query suggestion result, 181 // short as a single character highlighted in a query suggestion result,
177 // e.g. for input text "s" and query string "southwest airlines", it 182 // e.g. for input text "s" and query string "southwest airlines", it
178 // looks odd if both the first and last s are highlighted. 183 // looks odd if both the first and last s are highlighted.
179 if (lookup_position != 0) { 184 const size_t lookup_index = lookup_position - match_contents_.begin();
185 if (lookup_index != 0) {
180 match_contents_class_.push_back( 186 match_contents_class_.push_back(
181 ACMatchClassification(0, ACMatchClassification::MATCH)); 187 ACMatchClassification(0, ACMatchClassification::MATCH));
182 } 188 }
183 match_contents_class_.push_back( 189 match_contents_class_.push_back(
184 ACMatchClassification(lookup_position, ACMatchClassification::NONE)); 190 ACMatchClassification(lookup_index, ACMatchClassification::NONE));
185 size_t next_fragment_position = lookup_position + lookup_text.length(); 191 size_t next_fragment_position = lookup_index + lookup_text.length();
186 if (next_fragment_position < match_contents_.length()) { 192 if (next_fragment_position < match_contents_.length()) {
187 match_contents_class_.push_back(ACMatchClassification( 193 match_contents_class_.push_back(ACMatchClassification(
188 next_fragment_position, ACMatchClassification::MATCH)); 194 next_fragment_position, ACMatchClassification::MATCH));
189 } 195 }
190 } 196 }
191 } else { 197 } else {
192 // Otherwise, match_contents_ is a verbatim (what-you-typed) match, either 198 // Otherwise, match_contents_ is a verbatim (what-you-typed) match, either
193 // for the default provider or a keyword search provider. 199 // for the default provider or a keyword search provider.
194 match_contents_class_.push_back( 200 match_contents_class_.push_back(
195 ACMatchClassification(0, ACMatchClassification::NONE)); 201 ACMatchClassification(0, ACMatchClassification::NONE));
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 base::CollapseWhitespace(suggestion, false), match_type, 534 base::CollapseWhitespace(suggestion, false), match_type,
529 base::CollapseWhitespace(match_contents, false), 535 base::CollapseWhitespace(match_contents, false),
530 match_contents_prefix, annotation, answer_contents, answer_type_str, 536 match_contents_prefix, annotation, answer_contents, answer_type_str,
531 answer.Pass(), suggest_query_params, deletion_url, is_keyword_result, 537 answer.Pass(), suggest_query_params, deletion_url, is_keyword_result,
532 relevance, relevances != NULL, should_prefetch, trimmed_input)); 538 relevance, relevances != NULL, should_prefetch, trimmed_input));
533 } 539 }
534 } 540 }
535 results->relevances_from_server = relevances != NULL; 541 results->relevances_from_server = relevances != NULL;
536 return true; 542 return true;
537 } 543 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/search_provider_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698