#include "components/omnibox/browser/scored_history_match.h"
#include <math.h>
#include <array>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/check_op.h"
#include "base/no_destructor.h"
#include "base/numerics/safe_conversions.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_offset_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "components/bookmarks/browser/bookmark_utils.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/history_url_provider.h"
#include "components/omnibox/browser/in_memory_url_index_types.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/omnibox/browser/url_prefix.h"
#include "url/gurl.h"
#include "url/third_party/mozilla/url_parse.h"
namespace {
const int kDaysToPrecomputeRecencyScoresFor = …;
const int kMaxRawTermScore = …;
std::array<float, kDaysToPrecomputeRecencyScoresFor> days_ago_to_recency_score;
std::array<float, kMaxRawTermScore> raw_term_score_to_topicality_score;
void InitRawTermScoreToTopicalityScoreArray() { … }
void InitDaysAgoToRecencyScoreArray() { … }
}
bool ScoredHistoryMatch::also_do_hup_like_scoring_;
float ScoredHistoryMatch::bookmark_value_;
float ScoredHistoryMatch::typed_value_;
size_t ScoredHistoryMatch::max_visits_to_score_;
bool ScoredHistoryMatch::allow_tld_matches_;
bool ScoredHistoryMatch::allow_scheme_matches_;
size_t ScoredHistoryMatch::num_title_words_to_allow_;
float ScoredHistoryMatch::topicality_threshold_;
ScoredHistoryMatch::ScoreMaxRelevances*
ScoredHistoryMatch::relevance_buckets_override_ = …;
OmniboxFieldTrial::NumMatchesScores*
ScoredHistoryMatch::matches_to_specificity_override_ = …;
ScoredHistoryMatch::ScoredHistoryMatch()
: … { … }
ScoredHistoryMatch::ScoredHistoryMatch(
const history::URLRow& row,
const VisitInfoVector& visits,
const std::u16string& lower_string,
const String16Vector& terms_vector,
const WordStarts& terms_to_word_starts_offsets,
const RowWordStarts& word_starts,
bool is_url_bookmarked,
size_t num_matching_pages,
bool is_highly_visited_host,
base::Time now) { … }
ScoredHistoryMatch::ScoredHistoryMatch(const ScoredHistoryMatch& other) =
default;
ScoredHistoryMatch::ScoredHistoryMatch(ScoredHistoryMatch&& other) = default;
ScoredHistoryMatch& ScoredHistoryMatch::operator=(
const ScoredHistoryMatch& other) = default;
ScoredHistoryMatch& ScoredHistoryMatch::operator=(ScoredHistoryMatch&& other) =
default;
ScoredHistoryMatch::~ScoredHistoryMatch() = default;
bool ScoredHistoryMatch::MatchScoreGreater(const ScoredHistoryMatch& m1,
const ScoredHistoryMatch& m2) { … }
TermMatches ScoredHistoryMatch::FilterUrlTermMatches(
const WordStarts& terms_to_word_starts_offsets,
const GURL& url,
const WordStarts& url_word_starts,
const base::OffsetAdjuster::Adjustments& adjustments,
const TermMatches& url_matches) { … }
ScoredHistoryMatch::UrlMatchingSignals
ScoredHistoryMatch::ComputeUrlMatchingSignals(
const WordStarts& terms_to_word_starts_offsets,
const GURL& url,
const WordStarts& url_word_starts,
const base::OffsetAdjuster::Adjustments& adjustments,
const TermMatches& url_matches) { … }
TermMatches ScoredHistoryMatch::FilterTermMatchesByWordStarts(
const TermMatches& term_matches,
const WordStarts& terms_to_word_starts_offsets,
const WordStarts& word_starts,
size_t start_pos,
size_t end_pos,
bool allow_midword_continuations) { … }
size_t ScoredHistoryMatch::ComputeTotalMatchLength(
const WordStarts& terms_to_word_starts_offsets,
const TermMatches& matches,
const WordStarts& word_starts,
size_t num_words_to_allow) { … }
size_t ScoredHistoryMatch::CountUniqueMatchTerms(
const TermMatches& term_matches) { … }
void ScoredHistoryMatch::Init() { … }
float ScoredHistoryMatch::GetTopicalityScore(
const int num_terms,
const GURL& url,
const base::OffsetAdjuster::Adjustments& adjustments,
const WordStarts& terms_to_word_starts_offsets,
const RowWordStarts& word_starts) { … }
void ScoredHistoryMatch::IncrementUrlMatchTermScores(
const WordStarts& terms_to_word_starts_offsets,
const GURL& url,
const WordStarts& url_word_starts,
const base::OffsetAdjuster::Adjustments& adjustments,
std::vector<int>* term_scores) { … }
void ScoredHistoryMatch::IncrementTitleMatchTermScores(
const WordStarts& terms_to_word_starts_offsets,
const WordStarts& title_word_starts,
std::vector<int>* term_scores) { … }
float ScoredHistoryMatch::GetRecencyScore(int last_visit_days_ago) const { … }
float ScoredHistoryMatch::GetFrequency(const base::Time& now,
const bool bookmarked,
const VisitInfoVector& visits) const { … }
float ScoredHistoryMatch::GetDocumentSpecificityScore(
size_t num_matching_pages) const { … }
float ScoredHistoryMatch::GetFinalRelevancyScore(float topicality_score,
float frequency_score,
float specificity_score,
float domain_score) { … }
std::vector<ScoredHistoryMatch::ScoreMaxRelevance>
ScoredHistoryMatch::GetHQPBuckets() { … }
ScoredHistoryMatch::ScoreMaxRelevances
ScoredHistoryMatch::GetHQPBucketsFromString(const std::string& buckets_str) { … }
int ScoredHistoryMatch::GetDomainRelevancyScore(base::Time now) const { … }