Beta preview of the MongoDB-style object query syntax. Install with npm install fuse.js@beta.
Features
- search: add MongoDB-style object query syntax (#08459a9)
Express match types structurally instead of encoding them in magic characters:
const fuse = new Fuse(books, { keys: ['title', 'author'] })
fuse.search({ title: { $startsWith: 'old' }, author: { $eq: 'Kay' } })Five operators ($fuzzy, $eq, $contains, $startsWith, $endsWith), plus $not for negation and field-local $and / $or.
| Object | String equivalent |
|---|---|
$fuzzy
| term
|
$eq
| =term
|
$contains
| 'term
|
$startsWith
| ^term
|
$endsWith
| term$
|
$not: { $contains }
| !term
|
$not: { $startsWith }
| !^term
|
$not: { $endsWith }
| !term$
|
Highlights:
- No
useExtendedSearchflag. Object operators are unambiguous, so the flag that exists to parse magic characters in strings is not needed. - Exact parity with string syntax. An object query compiles to the same matchers as its string equivalent, so
scoreandmatchesindices are identical. - Strict validation. Unknown operators, empty or non-string values, and illegal nesting throw immediately instead of silently degrading to a fuzzy search. The published types enforce the same grammar at compile time.
- Composable. Field-local
$and/$orfor a field, and object leaves work anywhere a string leaf does inside logical$and/$or. - Works with
FuseWorker, and basic builds stay lean (the compiler is behind the extended-search build flag).
$not wraps exactly one of $contains / $startsWith / $endsWith. $fuzzy and $eq have no inverse matcher, so negating them throws; $ne is reserved for a future whole-string inequality.
Docs: https://fusejs.io/extended-search#object-syntax
This is a prerelease. Feedback welcome before 7.6.0 goes stable.