Repository navigation
fix(fts): count query terms, not dictionary terms, in conjunctive queries - #122
Merged
Merged
Conversation
…ries With conjunctive := true a document had to match as many dictionary terms as the query had terms. A wildcard expands to several dictionary terms, so 'foo* qux' accepted a document with foobar and foobaz but no qux, and rejected one with all three; 'foo fo*' rejected a document containing foo, which matches both query terms. Each matched dictionary term now records which query terms it satisfies, and a document passes when every query term is covered. Co-Authored-By: Claude Opus 5.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.
This work was produced with the help of language models.
Fixes #117.
With
conjunctive := true,QUERY_FTS_INDEXaccepted a document when it matched as many dictionary terms as the query had terms. A wildcard expands to several dictionary terms, sofoo* quxaccepted a document withfoobarandfoobazbut noquxand rejected one containing all three, andfoo fo*rejected a document containing onlyfoo.Fix. Query terms are deduplicated after stemming. Each matched dictionary term records which query terms it satisfies, and a document passes the conjunctive check when every query term is covered by one of its terms. Scores are unchanged: every matched dictionary term still contributes one edge per document. Single-threaded instruction counts on 1M documents are within noise of main for plain, wildcard, multi-term and conjunctive queries.
Tests.
wildcard.testgains a conjunctive case:foo* quxreturns only the documents withqux,foo fo*only the document withfoo, the same wildcard query withoutconjunctivereturns all four documents,foobar quxbehaves as before, a repeated term (qux qux) counts once, and a wildcard matching nothing (zzz* foo) returns no rows. It fails on main and passes here. FTS extension tests: no new failures.