Bug Fixes
-
index: correct doc-index alignment for
Fuse<string>collections containing blank strings (0b8e3ca)Pre-fix, blank docs in a string collection caused
records.length < _docs.length, and the mutation paths (add,removeAt,remove,removeAll) conflated records-array offset with source-array doc-index. Search results could be silently misaligned with the source array — e.g.removeAt(1)on["", "apple", "banana"]could return"banana"as a match for a search for"apple".Affects any
Fuse<string>collection where one or more docs are""or whitespace-only. Object collections are unaffected.Additionally:
Fuse.removeAt(idx)now validatesidx(integer, in range) atomically before any mutation.Fuse.add("")no longer re-ingests the previous record into the token-search inverted index, and no longer crashes on all-blank collections.FuseIndex.add,removeAt,removeAllgain cheap input guards for direct callers.
API note
FuseIndex.add gained a required second parameter:
// Before
FuseIndex<T>.add(doc: T): void
// After
FuseIndex<T>.add(doc: T, docIndex: number): IndexRecord | nullThe public Fuse.add(doc) signature is unchanged. Only code that calls FuseIndex.add directly on an instance from Fuse.createIndex() needs to update; calling without docIndex now throws INVALID_DOC_INDEX.
Persisted-index migration
If you serialized a Fuse<string> index via getIndex().toJSON() from a pre-fix instance whose collection contained blanks and you ran any add/remove/removeAt/removeAll calls before serialization, those records may misrepresent the source array. Rebuild via new Fuse(docs, options) (drop the persisted-index argument) once after upgrading.
Indexes from clean string collections (no blanks, or blanks but no mutations) and all object-collection indexes are unaffected and load normally.