// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "components/history/core/browser/keyword_search_term_util.h" #include <algorithm> #include "base/time/time.h" #include "components/history/core/browser/features.h" #include "components/history/core/browser/keyword_search_term.h" namespace history { namespace { // Calculates the score for the given number of visits in a given day. // Recent visits count more than historical ones, so multiply in a boost // depending on how long ago this day was. This boost is a curve that // smoothly goes through these values: Today gets 3x, a week ago 2x, three // weeks ago 1.5x, gradually falling off to 1x at the very end. double GetMostVisitedFrecencyScore(int visit_count, base::Time day, base::Time now) { … } // Returns whether two search terms are identical - i.e., they have the same // normalized search terms. bool IsSameSearchTerm(const KeywordSearchTermVisit& lhs, const KeywordSearchTermVisit& rhs) { … } // Return whether a visit to a search term constitutes a duplicative visit - // i.e., a visit to the same search term in an interval smaller than // kAutocompleteDuplicateVisitIntervalThreshold. // Called with identical search terms only. i.e., IsSameSearchTerm() is true. bool IsDuplicativeVisitToSearchTerm(const KeywordSearchTermVisit& lhs, const KeywordSearchTermVisit& rhs) { … } // Transforms a visit time to its timeslot, i.e., day of the viist. base::Time VisitTimeToTimeslot(base::Time visit_time) { … } // Returns whether two search term visits are in the same timeslot. // Called with identical search terms only. i.e., IsSameSearchTerm() is true. bool IsInSameTimeslot(const KeywordSearchTermVisit& lhs, const KeywordSearchTermVisit& rhs) { … } } // namespace const base::TimeDelta kAutocompleteDuplicateVisitIntervalThreshold = …; // Returns the frecency score of the visit based on the following formula: // (frequency ^ kFrequencyExponent) * kRecencyDecayUnitSec // frecency = ———————————————————————————————————————————————————————————————— // recency_in_seconds + kRecencyDecayUnitSec double GetFrecencyScore(int visit_count, base::Time visit_time, base::Time now) { … } // AutocompleteSearchTermHelper ------------------------------------------------ // A helper class to aggregate keyword search term visits returned by the // `KeywordSearchTermVisitEnumerator` into unique search terms with // `visit_count` aggregated across the visits for use as prefix or zero-prefix // suggestions in the omnibox. class AutocompleteSearchTermHelper { … }; void GetAutocompleteSearchTermsFromEnumerator( KeywordSearchTermVisitEnumerator& enumerator, const size_t count, SearchTermRankingPolicy ranking_policy, KeywordSearchTermVisitList* search_terms) { … } // MostRepeatedSearchTermHelper ------------------------------------------------ // A helper class to aggregate keyword search term visits returned by the // `KeywordSearchTermVisitEnumerator` into unique search terms with // `visit_count` and `score` aggregated across the days of visit for use in the // Most Visited tiles. class MostRepeatedSearchTermHelper { … }; void GetMostRepeatedSearchTermsFromEnumerator( KeywordSearchTermVisitEnumerator& enumerator, const size_t count, KeywordSearchTermVisitList* search_terms) { … } } // namespace history