Chromium Code Reviews| Index: chrome/browser/bookmarks/bookmark_index.cc |
| diff --git a/chrome/browser/bookmarks/bookmark_index.cc b/chrome/browser/bookmarks/bookmark_index.cc |
| index 77c22d985990464467233e624eb214675a3a667b..5bd48122ed1d4fee89b029cff4009fca0a10b963 100644 |
| --- a/chrome/browser/bookmarks/bookmark_index.cc |
| +++ b/chrome/browser/bookmarks/bookmark_index.cc |
| @@ -10,6 +10,7 @@ |
| #include "base/i18n/case_conversion.h" |
| #include "base/strings/string16.h" |
| +#include "base/strings/utf_offset_string_conversions.h" |
| #include "chrome/browser/bookmarks/bookmark_model.h" |
| #include "chrome/browser/bookmarks/bookmark_utils.h" |
| #include "chrome/browser/history/history_service.h" |
| @@ -92,8 +93,9 @@ void BookmarkIndex::Add(const BookmarkNode* node) { |
| for (size_t i = 0; i < terms.size(); ++i) |
| RegisterNode(terms[i], node); |
| if (index_urls_) { |
| - terms = ExtractQueryWords( |
| - bookmark_utils::CleanUpUrlForMatching(node->url(), languages_)); |
| + base::OffsetAdjuster::Adjustments adjustments; |
| + terms = ExtractQueryWords(bookmark_utils::CleanUpUrlForMatching( |
| + node->url(), languages_, &adjustments)); |
|
Peter Kasting
2014/04/23 23:18:01
Maybe we should be able to pass NULL for the last
Mark P
2014/04/24 14:05:02
Done.
|
| for (size_t i = 0; i < terms.size(); ++i) |
| RegisterNode(terms[i], node); |
| } |
| @@ -108,8 +110,9 @@ void BookmarkIndex::Remove(const BookmarkNode* node) { |
| for (size_t i = 0; i < terms.size(); ++i) |
| UnregisterNode(terms[i], node); |
| if (index_urls_) { |
| - terms = ExtractQueryWords( |
| - bookmark_utils::CleanUpUrlForMatching(node->url(), languages_)); |
| + base::OffsetAdjuster::Adjustments adjustments; |
| + terms = ExtractQueryWords(bookmark_utils::CleanUpUrlForMatching( |
| + node->url(), languages_, &adjustments)); |
| for (size_t i = 0; i < terms.size(); ++i) |
| UnregisterNode(terms[i], node); |
| } |
| @@ -205,10 +208,10 @@ void BookmarkIndex::AddMatchToResults( |
| const base::string16 lower_title = |
| base::i18n::ToLower(Normalize(node->GetTitle())); |
| parser->ExtractQueryWords(lower_title, &title_words); |
| + base::OffsetAdjuster::Adjustments adjustments; |
| if (index_urls_) { |
| - parser->ExtractQueryWords( |
| - bookmark_utils::CleanUpUrlForMatching(node->url(), languages_), |
| - &url_words); |
| + parser->ExtractQueryWords(bookmark_utils::CleanUpUrlForMatching( |
| + node->url(), languages_, &adjustments), &url_words); |
| } |
| query_parser::Snippet::MatchPositions title_matches, url_matches; |
| for (size_t i = 0; i < query_nodes.size(); ++i) { |
| @@ -229,8 +232,17 @@ void BookmarkIndex::AddMatchToResults( |
| // TODO(mpearson): revise match positions appropriately. |
| match.title_match_positions.swap(title_matches); |
| } |
| - if (index_urls_) |
| + if (index_urls_) { |
| + // Now that we're done processing this entry, correct the offsets of the |
| + // matches in |url_matches| so they point to offsets in the original URL |
| + // spec, not the cleaned-up URL string that we used for matching. |
| + std::vector<size_t> offsets = |
| + BookmarkMatch::OffsetsFromMatchPositions(url_matches); |
| + base::OffsetAdjuster::UnadjustOffsets(adjustments, &offsets); |
| + url_matches = |
| + BookmarkMatch::ReplaceOffsetsInMatchPositions(url_matches, offsets); |
| match.url_match_positions.swap(url_matches); |
| + } |
| match.node = node; |
| results->push_back(match); |
| } |