| 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 "components/omnibox/browser/url_index_private_data.h" | 5 #include "components/omnibox/browser/url_index_private_data.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <functional> | 9 #include <functional> |
| 10 #include <iterator> | 10 #include <iterator> |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 return word_list_[word_id].find(term) == base::string16::npos; | 583 return word_list_[word_id].find(term) == base::string16::npos; |
| 584 }); | 584 }); |
| 585 } else { | 585 } else { |
| 586 word_id_set = WordIDSetForTermChars(Char16SetFromString16(term)); | 586 word_id_set = WordIDSetForTermChars(Char16SetFromString16(term)); |
| 587 } | 587 } |
| 588 | 588 |
| 589 // If any words resulted then we can compose a set of history IDs by unioning | 589 // If any words resulted then we can compose a set of history IDs by unioning |
| 590 // the sets from each word. | 590 // the sets from each word. |
| 591 // We use |buffer| because it's more efficient to collect everything and then | 591 // We use |buffer| because it's more efficient to collect everything and then |
| 592 // construct a flat_set than to insert elements one by one. | 592 // construct a flat_set than to insert elements one by one. |
| 593 |
| 594 #define BUFFER 1 |
| 595 #define BY_ONE 2 |
| 596 #define MERGE 3 |
| 597 |
| 598 #define METHOD MERGE |
| 599 |
| 600 #if METHOD == BUFFER |
| 601 |
| 593 HistoryIDVector buffer; | 602 HistoryIDVector buffer; |
| 594 for (WordID word_id : word_id_set) { | 603 for (WordID word_id : word_id_set) { |
| 595 WordIDHistoryMap::iterator word_iter = word_id_history_map_.find(word_id); | 604 WordIDHistoryMap::iterator word_iter = word_id_history_map_.find(word_id); |
| 596 if (word_iter != word_id_history_map_.end()) { | 605 if (word_iter != word_id_history_map_.end()) { |
| 597 HistoryIDSet& word_history_id_set(word_iter->second); | 606 HistoryIDSet& word_history_id_set(word_iter->second); |
| 598 buffer.insert(buffer.end(), word_history_id_set.begin(), | 607 buffer.insert(buffer.end(), word_history_id_set.begin(), |
| 599 word_history_id_set.end()); | 608 word_history_id_set.end()); |
| 600 } | 609 } |
| 601 } | 610 } |
| 602 HistoryIDSet history_id_set(buffer.begin(), buffer.end(), | 611 HistoryIDSet history_id_set(buffer.begin(), buffer.end(), |
| 603 base::KEEP_FIRST_OF_DUPES); | 612 base::KEEP_FIRST_OF_DUPES); |
| 604 | 613 |
| 614 #elif METHOD == BY_ONE |
| 615 |
| 616 HistoryIDSet history_id_set; |
| 617 |
| 618 for (WordID word_id : word_id_set) { |
| 619 WordIDHistoryMap::iterator word_iter = word_id_history_map_.find(word_id); |
| 620 if (word_iter != word_id_history_map_.end()) { |
| 621 HistoryIDSet& word_history_id_set(word_iter->second); |
| 622 history_id_set.insert_by_one(word_history_id_set.begin(), |
| 623 word_history_id_set.end()); |
| 624 } |
| 625 } |
| 626 |
| 627 #else // MERGE |
| 628 |
| 629 HistoryIDSet history_id_set; |
| 630 |
| 631 for (WordID word_id : word_id_set) { |
| 632 WordIDHistoryMap::iterator word_iter = word_id_history_map_.find(word_id); |
| 633 if (word_iter != word_id_history_map_.end()) { |
| 634 HistoryIDSet& word_history_id_set(word_iter->second); |
| 635 history_id_set.insert_merge(word_history_id_set.begin(), |
| 636 word_history_id_set.end()); |
| 637 } |
| 638 } |
| 639 |
| 640 #endif |
| 641 |
| 605 // Record a new cache entry for this word if the term is longer than | 642 // Record a new cache entry for this word if the term is longer than |
| 606 // a single character. | 643 // a single character. |
| 607 if (term_length > 1) | 644 if (term_length > 1) |
| 608 search_term_cache_[term] = SearchTermCacheItem(word_id_set, history_id_set); | 645 search_term_cache_[term] = SearchTermCacheItem(word_id_set, history_id_set); |
| 609 | 646 |
| 610 return history_id_set; | 647 return history_id_set; |
| 611 } | 648 } |
| 612 | 649 |
| 613 WordIDSet URLIndexPrivateData::WordIDSetForTermChars( | 650 WordIDSet URLIndexPrivateData::WordIDSetForTermChars( |
| 614 const Char16Set& term_chars) { | 651 const Char16Set& term_chars) { |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1266 // First cut: typed count, visit count, recency. | 1303 // First cut: typed count, visit count, recency. |
| 1267 // TODO(mrossetti): This is too simplistic. Consider an approach which ranks | 1304 // TODO(mrossetti): This is too simplistic. Consider an approach which ranks |
| 1268 // recently visited (within the last 12/24 hours) as highly important. Get | 1305 // recently visited (within the last 12/24 hours) as highly important. Get |
| 1269 // input from mpearson. | 1306 // input from mpearson. |
| 1270 if (r1.typed_count() != r2.typed_count()) | 1307 if (r1.typed_count() != r2.typed_count()) |
| 1271 return (r1.typed_count() > r2.typed_count()); | 1308 return (r1.typed_count() > r2.typed_count()); |
| 1272 if (r1.visit_count() != r2.visit_count()) | 1309 if (r1.visit_count() != r2.visit_count()) |
| 1273 return (r1.visit_count() > r2.visit_count()); | 1310 return (r1.visit_count() > r2.visit_count()); |
| 1274 return (r1.last_visit() > r2.last_visit()); | 1311 return (r1.last_visit() > r2.last_visit()); |
| 1275 } | 1312 } |
| OLD | NEW |