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

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: Fix kSafeRegexWordBoundary for Korean. 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..d7d4fc492a2b4347367e66356d8a9342487aa3f1 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,
+ 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,9 @@ 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);
}
}
@@ -1468,6 +1477,45 @@ 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);
+
+ bool too_many = false;
+ std::vector<URLResult> matching_visits;
+ VisitVector visits; // Declare outside loop to prevent re-construction.
+ for (size_t i = 0; (i < text_matches.size()) && !too_many; i++) {
+ // Get all visits for given URL match.
+ GetVisitsForURLWithOptions(text_matches[i].id(), options, &visits);
+
+ for (size_t j = 0; j < visits.size(); j++) {
+ if (options.max_count != 0 &&
+ static_cast<int>(result->size()) >= options.max_count) {
+ too_many = true; // Got too many items.
+ break;
+ }
+ 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);
+ for (std::vector<URLResult>::iterator it = matching_visits.begin();
+ it != matching_visits.end(); ++it) {
+ result->AppendURLBySwapping(&(*it));
+ }
+
+ if (!too_many && 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