Makes an empty index.
When fields names no field or gives a weight that is not a finite number above 0, when
passageFields names a field fields does not or one twice, or when editMinLength, passages or
passageWidth is not a whole number of at least 1, 0 and 1.
When tokenize is given and is not a function.
Adds a document, replacing one of the same id, which then counts as added last. Fields the index was not made with
are left out, and a field given as undefined is taken as not given. A refused document leaves the index as it was.
When the id is not a text, fields is not an object, or a field is not a text or a list of
texts.
When the id is empty.
When the tokenizer answers a word that is not a stretch of its text.
Adds several documents, in order. A document that is refused throws, and those before it stay added.
Searches. A query with no word in it, such as an empty one or punctuation alone, finds nothing.
The query text.
topK and match; see FuzzySearchOptions.
The documents found, highest score first, a tie in the order they were added.
When the query is not a text.
When topK is not a whole number of 0 or more or Infinity, or match is not 'all' or
'any'.
The index as plain JSON: its settings and each document's id and fields, in the order they were added.
Static fromJSONA saved index restored: its settings and documents from the JSON, its tokenizer from options (the default
unless given). A saved index holds texts, so the restore reads them again with that tokenizer.
Optional tokenize?: FuzzyTokenizerWhen the saved index is of another version or is not one FuzzyIndex.toJSON could have written; the message names what is wrong.
A ranked search over a caller's documents. Each document is a set of named fields, a text or a list of short texts each, and each field has the weight the index was made with. A query is read in NFC and cut into words by the tokenizer, and each word, folded to lower case with its accents dropped, matches a word of a document that is:
editMinLengthletters or more, which counts 0.5.A document's score is
sum over the query's words q of (max over its fields f and their words t of weight(f) * kind(q, t)): each query word's best match, its kind times the weight of the field it is in, summed over the query's words, each counted once. Withmatch: 'all'(the default) every query word must match somewhere in the document; with'any', at least one. Hits come highest score first; a tie keeps the order the documents were added in, a document added again under its id counting as added last.A hit holds each field of the document with its matched words marked, and up to
passagessentences or lines of the passage fields that hold a match: those that hold the most query words, then the earliest, shown in the order of the text, each clipped to aboutpassageWidthcharacters around its first match. A document matched only in another field shows the opening of its text, unmarked. A mark is a whole word at UTF-16 offsets into the text as the index holds it, in NFC; the marks of a text are in order and never overlap.A search reads the words near each query word's, not every word the index holds: it looks a query word up in two orders of the index's words, by how they begin and by how they end. It reads the words that begin with the query word's first half, the query word itself and the words it begins among them, the words that end with its second half, and the one word with the two letters on either side of its middle swapped; a query word under
editMinLengthletters reads only the words it begins. The first search after a document is added brings the two orders up to date. The fields of the hits a search answers are then read again to mark them.Pure and synchronous: it reads and writes nothing outside itself and imports nothing but the library's word rule, so a page can hold it. It is saved with FuzzyIndex.toJSON and restored with FuzzyIndex.fromJSON.
Example