| Index: chrome/browser/bookmarks/bookmark_index.cc
|
| diff --git a/chrome/browser/bookmarks/bookmark_index.cc b/chrome/browser/bookmarks/bookmark_index.cc
|
| index b4640d91fdac5428158c4da91bc92f88f99c35bd..c5b3519dadb3d0a78a274d00d65ea23769570587 100644
|
| --- a/chrome/browser/bookmarks/bookmark_index.cc
|
| +++ b/chrome/browser/bookmarks/bookmark_index.cc
|
| @@ -10,8 +10,9 @@
|
|
|
| #include "base/i18n/case_conversion.h"
|
| #include "base/strings/string16.h"
|
| +#include "chrome/browser/bookmarks/bookmark_match.h"
|
| #include "chrome/browser/bookmarks/bookmark_model.h"
|
| -#include "chrome/browser/bookmarks/bookmark_title_match.h"
|
| +#include "chrome/browser/bookmarks/bookmark_utils.h"
|
| #include "chrome/browser/history/history_service.h"
|
| #include "chrome/browser/history/history_service_factory.h"
|
| #include "chrome/browser/history/query_parser.h"
|
| @@ -51,8 +52,10 @@ BookmarkIndex::NodeSet::const_iterator BookmarkIndex::Match::nodes_end() const {
|
| return nodes.empty() ? terms.front()->second.end() : nodes.end();
|
| }
|
|
|
| -BookmarkIndex::BookmarkIndex(content::BrowserContext* browser_context)
|
| - : browser_context_(browser_context) {
|
| +BookmarkIndex::BookmarkIndex(content::BrowserContext* browser_context,
|
| + const std::string& languages)
|
| + : browser_context_(browser_context),
|
| + languages_(languages) {
|
| }
|
|
|
| BookmarkIndex::~BookmarkIndex() {
|
| @@ -64,6 +67,10 @@ void BookmarkIndex::Add(const BookmarkNode* node) {
|
| std::vector<base::string16> terms = ExtractQueryWords(node->GetTitle());
|
| for (size_t i = 0; i < terms.size(); ++i)
|
| RegisterNode(terms[i], node);
|
| + terms = ExtractQueryWords(bookmark_utils::CleanUpUrlForMatching(node->url(),
|
| + languages_));
|
| + for (size_t i = 0; i < terms.size(); ++i)
|
| + RegisterNode(terms[i], node);
|
| }
|
|
|
| void BookmarkIndex::Remove(const BookmarkNode* node) {
|
| @@ -73,19 +80,22 @@ void BookmarkIndex::Remove(const BookmarkNode* node) {
|
| std::vector<base::string16> terms = ExtractQueryWords(node->GetTitle());
|
| for (size_t i = 0; i < terms.size(); ++i)
|
| UnregisterNode(terms[i], node);
|
| + terms = ExtractQueryWords(bookmark_utils::CleanUpUrlForMatching(node->url(),
|
| + languages_));
|
| + for (size_t i = 0; i < terms.size(); ++i)
|
| + UnregisterNode(terms[i], node);
|
| }
|
|
|
| -void BookmarkIndex::GetBookmarksWithTitlesMatching(
|
| - const base::string16& query,
|
| - size_t max_count,
|
| - std::vector<BookmarkTitleMatch>* results) {
|
| +void BookmarkIndex::GetBookmarksMatching(const base::string16& query,
|
| + size_t max_count,
|
| + std::vector<BookmarkMatch>* results) {
|
| std::vector<base::string16> terms = ExtractQueryWords(query);
|
| if (terms.empty())
|
| return;
|
|
|
| Matches matches;
|
| for (size_t i = 0; i < terms.size(); ++i) {
|
| - if (!GetBookmarksWithTitleMatchingTerm(terms[i], i == 0, &matches))
|
| + if (!GetBookmarksMatchingTerm(terms[i], i == 0, &matches))
|
| return;
|
| }
|
|
|
| @@ -149,21 +159,37 @@ void BookmarkIndex::AddMatchToResults(
|
| const BookmarkNode* node,
|
| QueryParser* parser,
|
| const std::vector<QueryNode*>& query_nodes,
|
| - std::vector<BookmarkTitleMatch>* results) {
|
| - BookmarkTitleMatch title_match;
|
| + std::vector<BookmarkMatch>* results) {
|
| + BookmarkMatch match;
|
| // Check that the result matches the query. The previous search
|
| // was a simple per-word search, while the more complex matching
|
| // of QueryParser may filter it out. For example, the query
|
| // ["thi"] will match the bookmark titled [Thinking], but since
|
| // ["thi"] is quoted we don't want to do a prefix match.
|
| - if (parser->DoesQueryMatch(node->GetTitle(), query_nodes,
|
| - &(title_match.match_positions))) {
|
| - title_match.node = node;
|
| - results->push_back(title_match);
|
| + std::vector<QueryWord> title_words, url_words;
|
| + parser->ExtractQueryWords(
|
| + base::i18n::ToLower(node->GetTitle()), &title_words);
|
| + parser->ExtractQueryWords(
|
| + bookmark_utils::CleanUpUrlForMatching(node->url(), languages_),
|
| + &url_words);
|
| + Snippet::MatchPositions title_matches, url_matches;
|
| + for (size_t i = 0; i < query_nodes.size(); ++i) {
|
| + const bool has_title_matches =
|
| + query_nodes[i]->HasMatchIn(title_words, &title_matches);
|
| + const bool has_url_matches =
|
| + query_nodes[i]->HasMatchIn(url_words, &url_matches);
|
| + if (!has_title_matches && !has_url_matches)
|
| + return;
|
| + QueryParser::CoalseAndSortMatchPositions(&title_matches);
|
| + QueryParser::CoalseAndSortMatchPositions(&url_matches);
|
| }
|
| + match.title_match_positions.swap(title_matches);
|
| + match.url_match_positions.swap(url_matches);
|
| + match.node = node;
|
| + results->push_back(match);
|
| }
|
|
|
| -bool BookmarkIndex::GetBookmarksWithTitleMatchingTerm(const base::string16& term,
|
| +bool BookmarkIndex::GetBookmarksMatchingTerm(const base::string16& term,
|
| bool first_term,
|
| Matches* matches) {
|
| Index::const_iterator i = index_.lower_bound(term);
|
|
|