Repository navigation
Score term queries with term frequencies - #12
Merged
Merged
Conversation
The structured `term` node built its TermQuery with IndexRecordOption::Basic, which skips term frequencies: BM25 counted every match once, so `.term` ranked a document holding the token three times level with one holding it once, and scored unlike `.parsed` for the same token. Build it WithFreqs, as tantivy's QueryParser does. Fields indexed without freqs (raw strings, numerics) downgrade to Basic, so their scores are unchanged. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
.termbuilt its tantivyTermQuerywithIndexRecordOption::Basic. That option skips term frequencies, so BM25 counted every match once..termnow usesWithFreqs, the same option tantivy'sQueryParseruses for its term leaves (rust/src/lib.rs).Why
On a text field, a document containing the token three times ranked the same as one containing it once.
.termalso scored differently from.parsedand from a one-token.phrasefor the same token. That mismatch forced an app-side workaround of building a one-token phrase instead of a term.Checked against tantivy 0.26.1 with two equal-length docs ("apple" ×3 vs ×1):
TermQuery+Basic(old.term)TermQuery+WithFreqs(new.term)QueryParser"apple"Reviewer notes
.termscores on text fields change, so relevance ordering can shift. Worth a line in the release notes.Basic.termScoresUseTermFrequencyinStructuredQueryTestschecks that the ×3 doc outscores the ×1 doc. It also checks that.termscores match.parsedand a one-token.phrase.swift testpassed (393 tests) against a locally builtlibtantivy_ffi.a, andcargo testpassed (15 tests). I didn't rebuild the old code to watch the new test fail; the table above shows old.termscores both docs the same, which would fail its ×3 > ×1 check.🤖 Generated with Claude Code