OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/history/url_database.h" | 5 #include "chrome/browser/history/url_database.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 statement.BindInt(3, min_typed); | 351 statement.BindInt(3, min_typed); |
352 | 352 |
353 if (!statement.Step()) | 353 if (!statement.Step()) |
354 return false; | 354 return false; |
355 | 355 |
356 DCHECK(info); | 356 DCHECK(info); |
357 FillURLRow(statement, info); | 357 FillURLRow(statement, info); |
358 return true; | 358 return true; |
359 } | 359 } |
360 | 360 |
| 361 bool URLDatabase::GetTextMatches(const string16& query, |
| 362 URLRows* results) { |
| 363 ScopedVector<QueryNode> query_nodes; |
| 364 query_parser_.ParseQueryNodes(query, &query_nodes.get()); |
| 365 |
| 366 results->clear(); |
| 367 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, |
| 368 "SELECT" HISTORY_URL_ROW_FIELDS "FROM urls WHERE hidden = 0")); |
| 369 |
| 370 while (statement.Step()) { |
| 371 std::vector<QueryWord> query_words; |
| 372 string16 url = base::i18n::ToLower(statement.ColumnString16(1)); |
| 373 query_parser_.ExtractQueryWords(url, &query_words); |
| 374 string16 title = base::i18n::ToLower(statement.ColumnString16(2)); |
| 375 query_parser_.ExtractQueryWords(title, &query_words); |
| 376 |
| 377 if (query_parser_.DoesQueryMatch(query_words, query_nodes.get())) { |
| 378 history::URLResult info; |
| 379 FillURLRow(statement, &info); |
| 380 if (info.url().is_valid()) |
| 381 results->push_back(info); |
| 382 } |
| 383 } |
| 384 return !results->empty(); |
| 385 } |
| 386 |
361 bool URLDatabase::InitKeywordSearchTermsTable() { | 387 bool URLDatabase::InitKeywordSearchTermsTable() { |
362 has_keyword_search_terms_ = true; | 388 has_keyword_search_terms_ = true; |
363 if (!GetDB().DoesTableExist("keyword_search_terms")) { | 389 if (!GetDB().DoesTableExist("keyword_search_terms")) { |
364 if (!GetDB().Execute("CREATE TABLE keyword_search_terms (" | 390 if (!GetDB().Execute("CREATE TABLE keyword_search_terms (" |
365 "keyword_id INTEGER NOT NULL," // ID of the TemplateURL. | 391 "keyword_id INTEGER NOT NULL," // ID of the TemplateURL. |
366 "url_id INTEGER NOT NULL," // ID of the url. | 392 "url_id INTEGER NOT NULL," // ID of the url. |
367 "lower_term LONGVARCHAR NOT NULL," // The search term, in lower case. | 393 "lower_term LONGVARCHAR NOT NULL," // The search term, in lower case. |
368 "term LONGVARCHAR NOT NULL)")) // The actual search term. | 394 "term LONGVARCHAR NOT NULL)")) // The actual search term. |
369 return false; | 395 return false; |
370 } | 396 } |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 return GetDB().Execute(sql.c_str()); | 595 return GetDB().Execute(sql.c_str()); |
570 } | 596 } |
571 | 597 |
572 bool URLDatabase::CreateMainURLIndex() { | 598 bool URLDatabase::CreateMainURLIndex() { |
573 // Index over URLs so we can quickly look up based on URL. | 599 // Index over URLs so we can quickly look up based on URL. |
574 return GetDB().Execute( | 600 return GetDB().Execute( |
575 "CREATE INDEX IF NOT EXISTS urls_url_index ON urls (url)"); | 601 "CREATE INDEX IF NOT EXISTS urls_url_index ON urls (url)"); |
576 } | 602 } |
577 | 603 |
578 } // namespace history | 604 } // namespace history |
OLD | NEW |