KeyedFuzzyIndex
A persistent multi-key fuzzy search index backed by Rust-side data.
Holds key text arrays and weights in memory on the Rust side,
avoiding repeated FFI overhead for applications that search the
same dataset multiple times with multiple keys.
Pre-computes the search representation of every key text, eliminating
per-search string conversion overhead.
Memory is freed when the JavaScript garbage collector collects the instance
or when destroy() is called explicitly.
Typically wrapped by a JS-side FuzzyObjectIndex class that maps
results back to original objects.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new KeyedFuzzyIndex(
keyTexts,weights):KeyedFuzzyIndex
Create a new KeyedFuzzyIndex.
keyTexts[k] is an array of strings for key k, one per item.
All inner arrays must have the same length (the number of items).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
keyTexts |
readonly (readonly string[])[] |
weights |
readonly number[] |
Returns
Section titled “Returns”KeyedFuzzyIndex
Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get size():
number
Return the number of items in the index.
Returns
Section titled “Returns”number
Methods
Section titled “Methods”add(
keyValues):void
Add a single item to the index.
keyValues must have the same length as the number of keys.
Throws if the length does not match.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
keyValues |
readonly string[] |
Returns
Section titled “Returns”void
addMany()
Section titled “addMany()”addMany(
itemsKeyValues):void
Add multiple items to the index at once.
Each element of itemsKeyValues is an array of key values for one item.
Throws if any element has the wrong number of key values; every element
is checked first, so on error no item is added.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
itemsKeyValues |
readonly (readonly string[])[] |
Returns
Section titled “Returns”void
closest()
Section titled “closest()”closest(
query,options?):number|null
Find the index of the closest matching item.
Returns the index of the best match, or null if no match is found:
the index of the first result of
search(query, { maxResults: 1, minScore, scoreMode, matchMode }).
The second argument accepts either a number (minScore shorthand) or a
KeyClosestOptions object: minScore makes it return null when the
best match scores below the threshold, and scoreMode and
matchMode work like the search() options of the same names
(defaults 'weighted' and 'perKey').
Use the returned index to look up the item in your own data array.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
query |
string |
options? |
number | KeyClosestOptions | null |
Returns
Section titled “Returns”number | null
destroy()
Section titled “destroy()”destroy():
void
Free the internal data. After calling this, the index is empty.
The key configuration is kept, so the index stays usable: it behaves
as an empty index and add() / addMany() work as before.
Returns
Section titled “Returns”void
remove()
Section titled “remove()”remove(
index):boolean
Remove the item at the given index.
Uses swap-remove for O(1) performance: the last item moves into the
freed slot. Returns false, removing nothing, if index is out of
range (negative, or not less than size). Throws a TypeError if
index is not a number and a RangeError if it is not an integer
(NaN, ±Infinity or a fraction), like FuzzyObjectIndex.remove().
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
index |
number |
Returns
Section titled “Returns”boolean
search()
Section titled “search()”search(
query,options?):KeySearchResult[]
Search the index for items matching the query.
Returns results sorted by combined score (best match first), exactly
like searchKeys() on the same key texts and weights.
The second argument accepts either a number (maxResults shorthand) or a
KeySearchOptions object, whose matchMode selects how the query is
matched against the keys and scoreMode how the per-key scores are
combined. maxResults must be a non-negative integer or Infinity.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
query |
string |
options? |
number | KeySearchOptions | null |
Returns
Section titled “Returns”serialize()
Section titled “serialize()”serialize():
Uint8Array
Serialize the index to a compact binary format.
The returned Buffer can be written to disk, stored in IndexedDB,
or transferred over the network. Use KeyedFuzzyIndex.deserialize() to
reconstruct the index.
Returns
Section titled “Returns”Uint8Array
deserialize()
Section titled “deserialize()”
staticdeserialize(data):KeyedFuzzyIndex
Reconstruct a KeyedFuzzyIndex from a previously serialized Buffer, or
any other Uint8Array holding the same bytes (such as the output of the
browser build’s serialize()).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
data |
Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBufferLike> |
Returns
Section titled “Returns”KeyedFuzzyIndex