You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Exclusion pattern not working in extended search #712
This is a known limitation of how extended search interacts with multiple keys. The ! operator works correctly per-field, but the cross-key aggregation uses "include if ANY key matches" — which is wrong for inverse patterns since almost every item has at least one field that doesn't contain the excluded term.
The workaround is to use logical queries, which give you explicit control over which keys are searched:
Fixing this in the general case (especially mixed queries like ^hello !syrup) requires architectural changes to how the searcher communicates match types back to the aggregation layer. Leaving this open as a known issue.
The core issue is that _searchObjectList searches each key independently via searcher.searchIn(text) and includes the item if ANY key returns isMatch: true. This is correct for positive patterns but wrong for inverse ones:
→ include (wrong: should exclude because title contains Syrup)
The fix requires "ANY key" aggregation for positive patterns but "ALL keys" for inverse. However, searchIn() returns a single { isMatch, score } with no information about whether the result came from a positive or inverse match.
For mixed patterns like ^hello !Syrup, it gets worse — a key could fail because of the positive term OR the inverse term, and we can't tell which. We'd need ExtendedSearch.searchIn to return per-term results, which means redesigning the Searcher interface.
This is documented in the source at _searchObjectList in src/core/index.ts.
Fixed in 9351882. ExtendedSearch.searchIn now sets hasInverse on the result when inverse matchers are involved, and _searchObjectList uses this to switch from "ANY key matches" to "ALL keys must match" aggregation.
!Syrup with keys [title, author] now correctly excludes items where Syrup appears in any searched field.
Update: disregard my earlier comments about this being an architectural limitation — I found a clean solution.
The fix adds a hasInverse flag to search results. When ExtendedSearch detects inverse matchers in the query, it signals this to the aggregation layer, which then requires ALL keys to match (instead of ANY). Pure inverse queries like !Syrup are fully fixed. Mixed queries like ^hello !Syrup conservatively exclude on any key failure, which is the correct behavior in practice.
The logical query workaround is no longer needed for this case, though it remains available for more fine-grained control.
Activity
nichita-pasecinic commentedon Feb 13, 2023
I'm facing the same issue!
github-actions commentedon Jun 14, 2023
This issue is stale because it has been open 120 days with no activity. Remove stale label or comment or this will be closed in 30 days
nichita-pasecinic commentedon Jul 19, 2023
why closing though ?
docs: update TODO after triaging bugs
krisk commentedon Apr 3, 2026
This is a known limitation of how extended search interacts with multiple keys. The
!operator works correctly per-field, but the cross-key aggregation uses "include if ANY key matches" — which is wrong for inverse patterns since almost every item has at least one field that doesn't contain the excluded term.The workaround is to use logical queries, which give you explicit control over which keys are searched:
Fixing this in the general case (especially mixed queries like
^hello !syrup) requires architectural changes to how the searcher communicates match types back to the aggregation layer. Leaving this open as a known issue.docs: document inverse pattern cross-key limitation in _searchObjectList
krisk commentedon Apr 3, 2026
Some more context on why this is hard to fix:
The core issue is that
_searchObjectListsearches each key independently viasearcher.searchIn(text)and includes the item if ANY key returnsisMatch: true. This is correct for positive patterns but wrong for inverse ones:Positive
hellowith keys [title, author]:Inverse
!Syrupwith keys [title, author]:The fix requires "ANY key" aggregation for positive patterns but "ALL keys" for inverse. However,
searchIn()returns a single{ isMatch, score }with no information about whether the result came from a positive or inverse match.For mixed patterns like
^hello !Syrup, it gets worse — a key could fail because of the positive term OR the inverse term, and we can't tell which. We'd needExtendedSearch.searchInto return per-term results, which means redesigning the Searcher interface.This is documented in the source at
_searchObjectListinsrc/core/index.ts.fix(search): inverse patterns now work correctly across multiple keys
krisk commentedon Apr 3, 2026
Fixed in 9351882.
ExtendedSearch.searchInnow setshasInverseon the result when inverse matchers are involved, and_searchObjectListuses this to switch from "ANY key matches" to "ALL keys must match" aggregation.!Syrupwith keys[title, author]now correctly excludes items where Syrup appears in any searched field.krisk commentedon Apr 3, 2026
Update: disregard my earlier comments about this being an architectural limitation — I found a clean solution.
The fix adds a
hasInverseflag to search results. WhenExtendedSearchdetects inverse matchers in the query, it signals this to the aggregation layer, which then requires ALL keys to match (instead of ANY). Pure inverse queries like!Syrupare fully fixed. Mixed queries like^hello !Syrupconservatively exclude on any key failure, which is the correct behavior in practice.The logical query workaround is no longer needed for this case, though it remains available for more fine-grained control.