Term frequency (source code)

= Term frequency
{title2=$\mathrm{tf}_{t,d}$}

The raw <term frequency> $\mathrm{tf}_{t,d}$ counts occurrences of term $t$ in one document $d$, after the chosen indexing preprocessing. It records how often the term appears there. <Document frequency> instead counts how many documents contain the term.<Introduction to Information Retrieval by Christopher D. Manning and others>[§6.2, Term frequency and weighting, occurrence-count definition and term/document subscripts]{ref}

For indexed terms $w_1,\ldots,w_L$, the <indicator function> gives
$$
\mathrm{tf}_{t,d}=\sum_{i=1}^{L}\mathbf1_{\{w_i=t\}}.
$$
In `red red boat`, the raw <term frequency> of red is two and that of boat is one. The proportions $2/3$ and $1/3$ are normalized counts; they are not the raw counts in this convention.

Reordering the document to `boat red red` preserves both <term frequencies> but changes which <phrase queries> match. Counts therefore compress away ordering information. A <positional index> can retain the occurrence positions as well as the counts.<Introduction to Information Retrieval by Christopher D. Manning and others>[§6.2, order is discarded by the count representation; §2.4.2, term counts alongside positional postings]{ref}

A retrieval score can use <term frequency> as evidence that a document discusses a query term, but repetition alone does not establish relevance. Nor must doubling a raw count double a score: a scoring rule can deliberately reduce the effect of repeated occurrences. Whenever a transformed or normalized quantity is called <term frequency>, its formula should be specified.