chromium/components/omnibox/browser/scored_history_match.cc

// Copyright 2012 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/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 {

// The number of days of recency scores to precompute.
const int kDaysToPrecomputeRecencyScoresFor =;

// The number of raw term score buckets use; raw term scores greater this are
// capped at the score of the largest bucket.
const int kMaxRawTermScore =;

// Pre-computed information to speed up calculating recency scores.
// |days_ago_to_recency_score| is a simple array mapping how long ago a page was
// visited (in days) to the recency score we should assign it.  This allows easy
// lookups of scores without requiring math. This is initialized by
// InitDaysAgoToRecencyScoreArray called by
// ScoredHistoryMatch::Init().
std::array<float, kDaysToPrecomputeRecencyScoresFor> days_ago_to_recency_score;

// Pre-computed information to speed up calculating topicality scores.
// |raw_term_score_to_topicality_score| is a simple array mapping how raw terms
// scores (a weighted sum of the number of hits for the term, weighted by how
// important the hit is: hostname, path, etc.) to the topicality score we should
// assign it.  This allows easy lookups of scores without requiring math. This
// is initialized by InitRawTermScoreToTopicalityScoreArray() called from
// ScoredHistoryMatch::Init().
std::array<float, kMaxRawTermScore> raw_term_score_to_topicality_score;

// Precalculates raw_term_score_to_topicality_score, used in
// GetTopicalityScore().
void InitRawTermScoreToTopicalityScoreArray() {}

// Pre-calculates days_ago_to_recency_score, used in GetRecencyScore().
void InitDaysAgoToRecencyScoreArray() {}

}  // namespace

// static
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;

// Comparison function for sorting ScoredMatches by their scores with
// intelligent tie-breaking.
bool ScoredHistoryMatch::MatchScoreGreater(const ScoredHistoryMatch& m1,
                                           const ScoredHistoryMatch& m2) {}

// static
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) {}

// static
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) {}

// static
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) {}

// static
size_t ScoredHistoryMatch::ComputeTotalMatchLength(
    const WordStarts& terms_to_word_starts_offsets,
    const TermMatches& matches,
    const WordStarts& word_starts,
    size_t num_words_to_allow) {}

// static
size_t ScoredHistoryMatch::CountUniqueMatchTerms(
    const TermMatches& term_matches) {}

// static
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 {}

// static
float ScoredHistoryMatch::GetFinalRelevancyScore(float topicality_score,
                                                 float frequency_score,
                                                 float specificity_score,
                                                 float domain_score) {}

// static
std::vector<ScoredHistoryMatch::ScoreMaxRelevance>
ScoredHistoryMatch::GetHQPBuckets() {}

// static
ScoredHistoryMatch::ScoreMaxRelevances
ScoredHistoryMatch::GetHQPBucketsFromString(const std::string& buckets_str) {}

int ScoredHistoryMatch::GetDomainRelevancyScore(base::Time now) const {}