OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ |
6 #define CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ | 6 #define CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 private: | 43 private: |
44 friend class HistoryQuickProviderTest; | 44 friend class HistoryQuickProviderTest; |
45 FRIEND_TEST_ALL_PREFIXES(HistoryQuickProviderTest, Spans); | 45 FRIEND_TEST_ALL_PREFIXES(HistoryQuickProviderTest, Spans); |
46 FRIEND_TEST_ALL_PREFIXES(HistoryQuickProviderTest, Relevance); | 46 FRIEND_TEST_ALL_PREFIXES(HistoryQuickProviderTest, Relevance); |
47 | 47 |
48 // The initial maximum allowable score for a match which cannot be inlined. | 48 // The initial maximum allowable score for a match which cannot be inlined. |
49 static const int kMaxNonInliningScore; | 49 static const int kMaxNonInliningScore; |
50 | 50 |
51 // Creates an AutocompleteMatch from |history_match|. |max_match_score| gives | 51 // Creates an AutocompleteMatch from |history_match|. |max_match_score| gives |
52 // the maximum possible score for the match. | 52 // the maximum possible score for the match. |history_matches| is the full set |
| 53 // of matches to compare each match to when calculating confidence. |
53 AutocompleteMatch QuickMatchToACMatch( | 54 AutocompleteMatch QuickMatchToACMatch( |
54 const history::ScoredHistoryMatch& history_match, | 55 const history::ScoredHistoryMatch& history_match, |
| 56 const history::ScoredHistoryMatches& history_matches, |
55 bool prevent_inline_autocomplete, | 57 bool prevent_inline_autocomplete, |
56 int* max_match_score); | 58 int* max_match_score); |
57 | 59 |
58 // Determines the relevance score of |history_match|. The maximum allowed | 60 // Determines the relevance score of |history_match|. The maximum allowed |
59 // score for the match is passed in |max_match_score|. The |max_match_score| | 61 // score for the match is passed in |max_match_score|. The |max_match_score| |
60 // is always set to the resulting score minus 1 whenever the match's score | 62 // is always set to the resulting score minus 1 whenever the match's score |
61 // has to be limited or is <= to |max_match_score|. This function should be | 63 // has to be limited or is <= to |max_match_score|. This function should be |
62 // called in a loop with each match in decreasing order of raw score. | 64 // called in a loop with each match in decreasing order of raw score. |
63 static int CalculateRelevance( | 65 static int CalculateRelevance( |
64 const history::ScoredHistoryMatch& history_match, | 66 const history::ScoredHistoryMatch& history_match, |
65 int* max_match_score); | 67 int* max_match_score); |
66 | 68 |
| 69 // Determines the confidence of |match| by comparing the |raw_score| to the |
| 70 // sum of the scores of |matches|. Returns a float in the range [0, 1]. |
| 71 static float CalculateConfidence( |
| 72 const history::ScoredHistoryMatch& match, |
| 73 const history::ScoredHistoryMatches& matches); |
| 74 |
67 // Returns the index that should be used for history lookups. | 75 // Returns the index that should be used for history lookups. |
68 history::InMemoryURLIndex* GetIndex(); | 76 history::InMemoryURLIndex* GetIndex(); |
69 | 77 |
70 // Fill and return an ACMatchClassifications structure given the term | 78 // Fill and return an ACMatchClassifications structure given the term |
71 // matches (|matches|) to highlight where terms were found. | 79 // matches (|matches|) to highlight where terms were found. |
72 static ACMatchClassifications SpansFromTermMatch( | 80 static ACMatchClassifications SpansFromTermMatch( |
73 const history::TermMatches& matches, | 81 const history::TermMatches& matches, |
74 size_t text_length, | 82 size_t text_length, |
75 bool is_url); | 83 bool is_url); |
76 | 84 |
77 // Only for use in unittests. Takes ownership of |index|. | 85 // Only for use in unittests. Takes ownership of |index|. |
78 void SetIndexForTesting(history::InMemoryURLIndex* index); | 86 void SetIndexForTesting(history::InMemoryURLIndex* index); |
79 AutocompleteInput autocomplete_input_; | 87 AutocompleteInput autocomplete_input_; |
80 std::string languages_; | 88 std::string languages_; |
81 | 89 |
82 // Only used for testing. | 90 // Only used for testing. |
83 scoped_ptr<history::InMemoryURLIndex> index_for_testing_; | 91 scoped_ptr<history::InMemoryURLIndex> index_for_testing_; |
84 }; | 92 }; |
85 | 93 |
86 #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ | 94 #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ |
OLD | NEW |