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

Unified Diff: components/autofill/core/browser/autocomplete_history_manager.cc

Issue 962673004: [Autofill/Autocomplete Feature] Substring matching instead of prefix matching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Just code rebase. Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/browser/autocomplete_history_manager.cc
diff --git a/components/autofill/core/browser/autocomplete_history_manager.cc b/components/autofill/core/browser/autocomplete_history_manager.cc
index 44e766660ead2209857df440c279c8a45a6b0a3a..670b83b4c91c04c79dda2b22b0f3162b0b8ea7d6 100644
--- a/components/autofill/core/browser/autocomplete_history_manager.cc
+++ b/components/autofill/core/browser/autocomplete_history_manager.cc
@@ -9,6 +9,7 @@
#include "base/prefs/pref_service.h"
#include "base/profiler/scoped_tracker.h"
#include "base/strings/string16.h"
+#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/autofill_client.h"
#include "components/autofill/core/browser/autofill_driver.h"
@@ -16,6 +17,7 @@
#include "components/autofill/core/browser/autofill_external_delegate.h"
#include "components/autofill/core/browser/validation.h"
#include "components/autofill/core/common/autofill_pref_names.h"
+#include "components/autofill/core/common/autofill_util.h"
#include "components/autofill/core/common/form_data.h"
namespace autofill {
@@ -82,7 +84,30 @@ void AutocompleteHistoryManager::OnWebDataServiceRequestDone(
const WDResult<std::vector<base::string16> >* autofill_result =
static_cast<const WDResult<std::vector<base::string16> >*>(result);
std::vector<base::string16> suggestions = autofill_result->GetValue();
- SendSuggestions(&suggestions);
+
+ if (!IsFeatureSubstringMatchEnabled() || pending_query_prefix_.empty()) {
+ SendSuggestions(&suggestions);
+ } else {
+ std::vector<base::string16> preferred_suggestions;
please use gerrit instead 2015/06/28 01:20:07 Wouldn't it be better to perform this logic in SQL
Pritam Nikam 2015/06/29 15:38:21 We need to pass '%<delimiter> + prefix_lower + %'.
please use gerrit instead 2015/06/29 17:06:45 Use '\_' instead?
Pritam Nikam 2015/06/30 15:05:50 ESCAPE clause worked for (_) case. SELECT value
+ std::vector<base::string16> substring_matched_suggestions;
+ for (base::string16 suggestion : suggestions) {
+ if (StartsWith(suggestion, pending_query_prefix_, false)) {
+ preferred_suggestions.push_back(suggestion);
+ } else if (ContainsTokenThatStartsWith(suggestion, pending_query_prefix_,
+ false)) {
+ substring_matched_suggestions.push_back(suggestion);
+ }
+ }
+
+ // Prefix matches should precede other token matches.
+ if (IsFeatureSubstringMatchEnabled()) {
+ preferred_suggestions.insert(preferred_suggestions.end(),
+ substring_matched_suggestions.begin(),
+ substring_matched_suggestions.end());
+ }
+
+ SendSuggestions(&preferred_suggestions);
+ }
}
void AutocompleteHistoryManager::OnGetAutocompleteSuggestions(
@@ -103,8 +128,10 @@ void AutocompleteHistoryManager::OnGetAutocompleteSuggestions(
}
if (database_.get()) {
+ pending_query_prefix_ = prefix;
pending_query_handle_ = database_->GetFormValuesForElementName(
- name, prefix, kMaxAutocompleteMenuItems, this);
+ name, IsFeatureSubstringMatchEnabled() ? base::string16() : prefix,
+ kMaxAutocompleteMenuItems, this);
}
}

Powered by Google App Engine
This is Rietveld 408576698