Index: components/omnibox/browser/url_index_private_data.cc |
diff --git a/components/omnibox/browser/url_index_private_data.cc b/components/omnibox/browser/url_index_private_data.cc |
index b9f2a93ea945bc2e73e33afdb396d0bd0ef8a975..663ee8a7dc6c3fbacccb78130779cc6e3832749e 100644 |
--- a/components/omnibox/browser/url_index_private_data.cc |
+++ b/components/omnibox/browser/url_index_private_data.cc |
@@ -10,6 +10,7 @@ |
#include <iterator> |
#include <limits> |
#include <numeric> |
+#include <set> |
#include <string> |
#include <vector> |
@@ -155,7 +156,10 @@ ScoredHistoryMatches URLIndexPrivateData::HistoryItemsForTerms( |
(cursor_position < original_search_string.length()) && |
(cursor_position > 0)) { |
// The original search_string broken at cursor position. This is one type of |
- // transformation. |
+ // transformation. It's possible this transformation doesn't actually |
+ // break any words. There's no harm in adding the transformation in this |
+ // case because the searching code below prevents running duplicate |
+ // searches. |
base::string16 transformed_search_string(original_search_string); |
transformed_search_string.insert(cursor_position, base::ASCIIToUTF16(" ")); |
search_strings.push_back(transformed_search_string); |
@@ -173,6 +177,9 @@ ScoredHistoryMatches URLIndexPrivateData::HistoryItemsForTerms( |
ResetSearchTermCache(); |
bool history_ids_were_trimmed = false; |
+ // A set containing the list of words extracted from each search string, |
+ // used to prevent running duplicate searches. |
+ std::set<String16Vector> search_string_words; |
for (const base::string16& search_string : search_strings) { |
// The search string we receive may contain escaped characters. For reducing |
// the index we need individual, lower-cased words, ignoring escapings. For |
@@ -192,6 +199,10 @@ ScoredHistoryMatches URLIndexPrivateData::HistoryItemsForTerms( |
String16VectorFromString16(lower_unescaped_string, false, nullptr)); |
if (lower_words.empty()) |
continue; |
+ // If we've already searched for this list of words, don't do it again. |
+ if (search_string_words.find(lower_words) != search_string_words.end()) |
+ continue; |
+ search_string_words.insert(lower_words); |
HistoryIDVector history_ids = HistoryIDsFromWords(lower_words); |
history_ids_were_trimmed |= TrimHistoryIdsPool(&history_ids); |