Skip to main content

score

Function score 

Source
pub fn score(
    query_terms: &[String],
    term_freq: &HashMap<String, u32>,
    doc_len: u32,
    avg_doc_len: f64,
    n_docs_with: &HashMap<String, u32>,
    total_docs: u32,
    params: &Bm25Params,
) -> f64
Expand description

Compute the BM25 score for a single (document, query) pair.

  • query_terms is the pre-tokenized query. Duplicate tokens are summed naturally — if the user typed "rust rust db", the rust contribution gets counted twice, matching the standard formulation.
  • term_freq maps each unique term in the document to its frequency within that document. The caller can build this from super::tokenizer::tokenize output.
  • n_docs_with is the corpus statistic — for each term, how many distinct documents contain it. Only entries for query terms are read; extra entries are ignored.
  • Returns 0.0 for the empty query, the empty corpus (total_docs == 0), or a document whose terms don’t intersect the query.