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

Unified Diff: components/bookmarks/browser/bookmark_index.cc

Issue 2537223008: Add TitledUrlIndex for indexing arbitrary title/URL pairs (Closed)
Patch Set: refactor in-place to preserve history Created 4 years 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/bookmarks/browser/bookmark_index.cc
diff --git a/components/bookmarks/browser/bookmark_index.cc b/components/bookmarks/browser/bookmark_index.cc
index 9c34e5a2ca5f821b76f0c2724f7ffb542b4d247d..88e0fe17ab3e6f067f2a2bf21bb530944af55762 100644
--- a/components/bookmarks/browser/bookmark_index.cc
+++ b/components/bookmarks/browser/bookmark_index.cc
@@ -6,11 +6,6 @@
#include <stdint.h>
-#include <algorithm>
-#include <functional>
-#include <iterator>
-#include <list>
-
#include "base/i18n/case_conversion.h"
#include "base/logging.h"
#include "base/stl_util.h"
@@ -18,8 +13,8 @@
#include "build/build_config.h"
#include "components/bookmarks/browser/bookmark_client.h"
#include "components/bookmarks/browser/bookmark_match.h"
-#include "components/bookmarks/browser/bookmark_node.h"
#include "components/bookmarks/browser/bookmark_utils.h"
+#include "components/bookmarks/browser/titled_url_node.h"
#include "components/query_parser/snippet.h"
#include "third_party/icu/source/common/unicode/normalizer2.h"
#include "third_party/icu/source/common/unicode/utypes.h"
@@ -63,9 +58,9 @@ struct NodeTypedCountPairSortFunctor {
}
};
-// Extract the const Node* stored in a BookmarkClient::NodeTypedCountPair.
+// Extract the const TitledUrlNode* stored in a NodeTypedCountPair.
struct NodeTypedCountPairExtractNodeFunctor {
- const BookmarkNode* operator()(const NodeTypedCountPair& pair) const {
+ const TitledUrlNode* operator()(const NodeTypedCountPair& pair) const {
return pair.first;
}
};
@@ -80,34 +75,34 @@ BookmarkIndex::BookmarkIndex(BookmarkClient* client)
BookmarkIndex::~BookmarkIndex() {
}
-void BookmarkIndex::Add(const BookmarkNode* node) {
- if (!node->is_url())
+void BookmarkIndex::Add(const TitledUrlNode* node) {
+ if (!node->GetTitledUrlNodeUrl().is_valid())
return;
std::vector<base::string16> terms =
- ExtractQueryWords(Normalize(node->GetTitle()));
+ ExtractQueryWords(Normalize(node->GetTitledUrlNodeTitle()));
for (size_t i = 0; i < terms.size(); ++i)
RegisterNode(terms[i], node);
- terms =
- ExtractQueryWords(CleanUpUrlForMatching(node->url(), nullptr));
+ terms = ExtractQueryWords(
+ CleanUpUrlForMatching(node->GetTitledUrlNodeUrl(), nullptr));
for (size_t i = 0; i < terms.size(); ++i)
RegisterNode(terms[i], node);
}
-void BookmarkIndex::Remove(const BookmarkNode* node) {
- if (!node->is_url())
+void BookmarkIndex::Remove(const TitledUrlNode* node) {
+ if (!node->GetTitledUrlNodeUrl().is_valid())
return;
std::vector<base::string16> terms =
- ExtractQueryWords(Normalize(node->GetTitle()));
+ ExtractQueryWords(Normalize(node->GetTitledUrlNodeTitle()));
for (size_t i = 0; i < terms.size(); ++i)
UnregisterNode(terms[i], node);
- terms =
- ExtractQueryWords(CleanUpUrlForMatching(node->url(), nullptr));
+ terms = ExtractQueryWords(
+ CleanUpUrlForMatching(node->GetTitledUrlNodeUrl(), nullptr));
for (size_t i = 0; i < terms.size(); ++i)
UnregisterNode(terms[i], node);
}
-void BookmarkIndex::GetBookmarksMatching(
+void BookmarkIndex::GetResultsMatching(
const base::string16& input_query,
size_t max_count,
query_parser::MatchingAlgorithm matching_algorithm,
@@ -119,8 +114,8 @@ void BookmarkIndex::GetBookmarksMatching(
NodeSet matches;
for (size_t i = 0; i < terms.size(); ++i) {
- if (!GetBookmarksMatchingTerm(
- terms[i], i == 0, matching_algorithm, &matches)) {
+ if (!GetResultsMatchingTerm(terms[i], i == 0, matching_algorithm,
+ &matches)) {
return;
}
}
@@ -165,22 +160,22 @@ void BookmarkIndex::SortMatches(const NodeSet& matches,
}
void BookmarkIndex::AddMatchToResults(
- const BookmarkNode* node,
+ const TitledUrlNode* node,
query_parser::QueryParser* parser,
const query_parser::QueryNodeVector& query_nodes,
std::vector<BookmarkMatch>* results) {
// 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"] will match the title [Thinking], but since
// ["thi"] is quoted we don't want to do a prefix match.
query_parser::QueryWordVector title_words, url_words;
const base::string16 lower_title =
- base::i18n::ToLower(Normalize(node->GetTitle()));
+ base::i18n::ToLower(Normalize(node->GetTitledUrlNodeTitle()));
parser->ExtractQueryWords(lower_title, &title_words);
base::OffsetAdjuster::Adjustments adjustments;
parser->ExtractQueryWords(
- CleanUpUrlForMatching(node->url(), &adjustments),
+ CleanUpUrlForMatching(node->GetTitledUrlNodeUrl(), &adjustments),
&url_words);
query_parser::Snippet::MatchPositions title_matches, url_matches;
for (const auto& node : query_nodes) {
@@ -193,7 +188,7 @@ void BookmarkIndex::AddMatchToResults(
query_parser::QueryParser::SortAndCoalesceMatchPositions(&url_matches);
}
BookmarkMatch match;
- if (lower_title.length() == node->GetTitle().length()) {
+ if (lower_title.length() == node->GetTitledUrlNodeTitle().length()) {
// Only use title matches if the lowercase string is the same length
// as the original string, otherwise the matches are meaningless.
// TODO(mpearson): revise match positions appropriately.
@@ -212,7 +207,7 @@ void BookmarkIndex::AddMatchToResults(
results->push_back(match);
}
-bool BookmarkIndex::GetBookmarksMatchingTerm(
+bool BookmarkIndex::GetResultsMatchingTerm(
const base::string16& term,
bool first_term,
query_parser::MatchingAlgorithm matching_algorithm,
@@ -225,7 +220,7 @@ bool BookmarkIndex::GetBookmarksMatchingTerm(
term, matching_algorithm)) {
// Term is too short for prefix match, compare using exact match.
if (i->first != term)
- return false; // No bookmarks with this term.
+ return false; // No title/URL pairs with this term.
if (first_term) {
(*matches) = i->second;
@@ -272,16 +267,16 @@ std::vector<base::string16> BookmarkIndex::ExtractQueryWords(
}
void BookmarkIndex::RegisterNode(const base::string16& term,
- const BookmarkNode* node) {
+ const TitledUrlNode* node) {
index_[term].insert(node);
}
void BookmarkIndex::UnregisterNode(const base::string16& term,
- const BookmarkNode* node) {
+ const TitledUrlNode* node) {
Index::iterator i = index_.find(term);
if (i == index_.end()) {
// We can get here if the node has the same term more than once. For
- // example, a bookmark with the title 'foo foo' would end up here.
+ // example, a node with the title 'foo foo' would end up here.
return;
}
i->second.erase(node);

Powered by Google App Engine
This is Rietveld 408576698