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

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 Brett's comments. 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 614d93a3bf4747e41f1816dff5f47841464e6e3e..d2ca6872cce0228e76697898363edd3845d3545b 100644
--- a/chrome/browser/history/history_backend.cc
+++ b/chrome/browser/history/history_backend.cc
@@ -1358,8 +1358,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);
+ }
}
}
@@ -1424,6 +1430,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) {
Scott Hess - ex-Googler 2013/06/20 19:50:22 Do you think there would be any value to histogram
rmcilroy 2013/06/20 21:48:08 There is already a timing histogram for the caller
Scott Hess - ex-Googler 2013/06/20 22:18:31 Sounds good.
+ 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++) {
+ const URLRow& text_match = text_matches[i];
+ // Get all visits for given URL match.
+ visit_db->GetVisitsForURLWithOptions(text_match.id(), options, &visits);
+ for (size_t j = 0; j < visits.size(); j++) {
+ URLResult url_result(text_match);
+ 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