Index: chrome/browser/history/scored_history_match.cc |
diff --git a/chrome/browser/history/scored_history_match.cc b/chrome/browser/history/scored_history_match.cc |
index 98e772763a90d0497a7cf5ea1026c07dfecb3977..42b853134677a9445fba98689e46cba715752142 100644 |
--- a/chrome/browser/history/scored_history_match.cc |
+++ b/chrome/browser/history/scored_history_match.cc |
@@ -56,6 +56,7 @@ const int kBaseScoreForUntypedResultsInHUPLikeScoring = 900; |
bool ScoredHistoryMatch::initialized_ = false; |
bool ScoredHistoryMatch::use_new_scoring = false; |
+bool ScoredHistoryMatch::only_count_matches_at_word_boundaries = false; |
bool ScoredHistoryMatch::also_do_hup_like_scoring = false; |
ScoredHistoryMatch::ScoredHistoryMatch() |
@@ -63,6 +64,7 @@ ScoredHistoryMatch::ScoredHistoryMatch() |
can_inline(false) { |
if (!initialized_) { |
InitializeNewScoringField(); |
+ InitializeOnlyCountMatchesAtWordBoundariesField(); |
InitializeAlsoDoHUPLikeScoringField(); |
initialized_ = true; |
} |
@@ -79,6 +81,7 @@ ScoredHistoryMatch::ScoredHistoryMatch(const URLRow& row, |
can_inline(false) { |
if (!initialized_) { |
InitializeNewScoringField(); |
+ InitializeOnlyCountMatchesAtWordBoundariesField(); |
InitializeAlsoDoHUPLikeScoringField(); |
initialized_ = true; |
} |
@@ -161,10 +164,13 @@ ScoredHistoryMatch::ScoredHistoryMatch(const URLRow& row, |
// Get partial scores based on term matching. Note that the score for |
// each of the URL and title are adjusted by the fraction of the |
// terms appearing in each. |
- int url_score = ScoreComponentForMatches(url_matches, url.length()) * |
+ int url_score = |
+ ScoreComponentForMatches(url_matches, word_starts.url_word_starts_, |
+ url.length()) * |
std::min(url_matches.size(), terms.size()) / terms.size(); |
int title_score = |
- ScoreComponentForMatches(title_matches, title.length()) * |
+ ScoreComponentForMatches(title_matches, word_starts.title_word_starts_, |
+ title.length()) * |
std::min(title_matches.size(), terms.size()) / terms.size(); |
// Arbitrarily pick the best. |
// TODO(mrossetti): It might make sense that a term which appears in both |
@@ -287,8 +293,23 @@ int AccumulateMatchLength(int total, const TermMatch& match) { |
} |
// static |
-int ScoredHistoryMatch::ScoreComponentForMatches(const TermMatches& matches, |
- size_t max_length) { |
+int ScoredHistoryMatch::ScoreComponentForMatches( |
+ const TermMatches& provided_matches, |
+ const WordStarts& word_starts, |
+ size_t max_length) { |
+ if (provided_matches.empty()) |
+ return 0; |
+ |
+ TermMatches matches_at_word_boundaries; |
+ if (only_count_matches_at_word_boundaries) { |
+ MakeTermMatchesOnlyAtWordBoundaries( |
+ provided_matches, word_starts, &matches_at_word_boundaries); |
Peter Kasting
2012/12/01 01:21:44
Nit: I'd slightly prefer to wrap after arg 2 and i
Mark P
2012/12/01 01:55:32
Done.
|
+ } |
+ // The actual matches we'll use for matching. This is |provided_matches| |
+ // with all the matches not at a word boundary removed (if told to do so). |
+ const TermMatches& matches = only_count_matches_at_word_boundaries ? |
+ matches_at_word_boundaries : provided_matches; |
+ |
if (matches.empty()) |
return 0; |
@@ -346,6 +367,31 @@ int ScoredHistoryMatch::ScoreComponentForMatches(const TermMatches& matches, |
} |
// static |
+void ScoredHistoryMatch::MakeTermMatchesOnlyAtWordBoundaries( |
+ const TermMatches& matches, |
+ const WordStarts& word_starts, |
+ TermMatches* matches_at_word_boundaries) { |
+ matches_at_word_boundaries->clear(); |
+ // Resize it to an upper-bound estimate of the correct size. |
+ matches_at_word_boundaries->reserve(matches.size()); |
+ std::vector<size_t>::const_iterator next_word_starts = word_starts.begin(); |
Peter Kasting
2012/12/01 01:21:44
Nit: Is there a typedef we should be using here?
Mark P
2012/12/01 01:55:32
Done.
|
+ for (TermMatches::const_iterator iter = matches.begin(); |
+ iter != matches.end(); ++iter) { |
+ // Advance next_word_starts until it's >= the position of the term |
+ // we're considering. |
+ while ((next_word_starts != word_starts.end()) && |
+ (*next_word_starts < iter->offset)) { |
+ ++next_word_starts; |
+ } |
+ if ((next_word_starts != word_starts.end()) && |
+ (*next_word_starts == iter->offset)) { |
+ // At word boundary: copy this element into |matches|. |
+ matches_at_word_boundaries->push_back(*iter); |
+ } |
+ } |
+} |
+ |
+// static |
int ScoredHistoryMatch::ScoreForValue(int value, const int* value_ranks) { |
int i = 0; |
int rank_count = arraysize(kScoreRank); |
@@ -657,6 +703,14 @@ void ScoredHistoryMatch::InitializeNewScoringField() { |
new_scoring_option, NUM_OPTIONS); |
} |
+void ScoredHistoryMatch::InitializeOnlyCountMatchesAtWordBoundariesField() { |
+ only_count_matches_at_word_boundaries = |
+ AutocompleteFieldTrial:: |
+ InHQPOnlyCountMatchesAtWordBoundariesFieldTrial() && |
+ AutocompleteFieldTrial:: |
+ InHQPOnlyCountMatchesAtWordBoundariesFieldTrialExperimentGroup(); |
+} |
+ |
void ScoredHistoryMatch::InitializeAlsoDoHUPLikeScoringField() { |
also_do_hup_like_scoring = |
AutocompleteFieldTrial::InHQPReplaceHUPScoringFieldTrial() && |