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

Unified Diff: chrome/browser/history/history_backend.cc

Issue 16776004: Replace FTS in the history_service with a brute force text search. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address scotts comments & fix unit tests. Created 7 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: chrome/browser/history/history_backend.cc
diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc
index 2817a98d0a7c23dcd9fd354ca4932055176d459c..4fc199f9f2a25c3c14c04821ff316d5d86ce9f21 100644
--- a/chrome/browser/history/history_backend.cc
+++ b/chrome/browser/history/history_backend.cc
@@ -1114,6 +1114,14 @@ bool HistoryBackend::GetVisitsForURL(URLID id, VisitVector* visits) {
return false;
}
+bool HistoryBackend::GetVisitsForURLWithOptions(URLID id,
brettw 2013/06/18 23:26:28 I don't get why this is a function since it looks
rmcilroy 2013/06/19 10:30:14 I was following the pattern of the functions above
+ const QueryOptions& options,
+ VisitVector* visits) {
+ if (db_)
+ return db_->GetVisitsForURLWithOptions(id, options, visits);
+ return false;
+}
+
bool HistoryBackend::GetMostRecentVisitsForURL(URLID id,
int max_visits,
VisitVector* visits) {
@@ -1402,8 +1410,14 @@ void HistoryBackend::QueryHistory(scoped_refptr<QueryHistoryRequest> request,
// if (archived_db_.get() &&
// expirer_.GetCurrentArchiveTime() - TimeDelta::FromDays(7)) {
} else {
- // Full text history query.
- QueryHistoryFTS(text_query, options, &request->value);
+ // Text history query.
+ QueryHistoryText(db_.get(), db_.get(), text_query, options,
+ &request->value);
+ if (archived_db_.get() &&
+ expirer_.GetCurrentArchiveTime() >= options.begin_time) {
+ QueryHistoryText(archived_db_.get(), archived_db_.get(), text_query,
+ options, &request->value);
+ }
}
}
@@ -1468,6 +1482,43 @@ void HistoryBackend::QueryHistoryBasic(URLDatabase* url_db,
result->set_reached_beginning(true);
}
+// Text-based querying of history.
+void HistoryBackend::QueryHistoryText(URLDatabase* url_db,
+ VisitDatabase* visit_db,
+ const string16& text_query,
+ const QueryOptions& options,
+ QueryResults* result) {
+ URLRows text_matches;
+ url_db->GetTextMatches(text_query, &text_matches);
+
+ std::vector<URLResult> matching_visits;
+ VisitVector visits; // Declare outside loop to prevent re-construction.
+ for (size_t i = 0; i < text_matches.size(); i++) {
+ // Get all visits for given URL match.
+ GetVisitsForURLWithOptions(text_matches[i].id(), options, &visits);
+
+ for (size_t j = 0; j < visits.size(); j++) {
+ URLResult url_result(text_matches[i]);
+ url_result.set_visit_time(visits[j].visit_time);
+ matching_visits.push_back(url_result);
+ }
+ }
+
+ std::sort(matching_visits.begin(), matching_visits.end(),
+ URLResult::CompareVisitTime);
+
+ size_t max_results = options.max_count == 0 ?
+ std::numeric_limits<size_t>::max() : static_cast<int>(options.max_count);
+ for (std::vector<URLResult>::iterator it = matching_visits.begin();
+ it != matching_visits.end() && result->size() < max_results; ++it) {
+ result->AppendURLBySwapping(&(*it));
+ }
+
+ if (matching_visits.size() == result->size() &&
+ options.begin_time <= first_recorded_time_)
+ result->set_reached_beginning(true);
+}
+
void HistoryBackend::QueryHistoryFTS(const string16& text_query,
const QueryOptions& options,
QueryResults* result) {

Powered by Google App Engine
This is Rietveld 408576698