Skip to content

fix(fts): count query terms, not dictionary terms, in conjunctive queries - #122

Merged
adsharma merged 1 commit into
LadybugDB:mainfrom
zahariash:fix/fts-conjunctive-wildcard
Oct 14, 2026
Merged

adsharma merged 1 commit into
LadybugDB:mainfrom
zahariash:fix/fts-conjunctive-wildcard

Conversation

@zahariash

Copy link
Copy Markdown

This work was produced with the help of language models.

Fixes #117.

With conjunctive := true, QUERY_FTS_INDEX accepted a document when it matched 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 containing all three, and foo fo* rejected a document containing only foo.

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.test gains a conjunctive case: foo* qux returns only the documents with qux, foo fo* only the document with foo, the same wildcard query without conjunctive returns all four documents, foobar qux behaves 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.

…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>
@adsharma
adsharma merged commit 5065115 into LadybugDB:main Oct 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Conjunctive FTS queries with a wildcard return the wrong documents

2 participants