To use the library, create a searcher using SearcherFactory.createDefaultSearcher(), index your entities with indexEntities, and perform searches using getMatches with a Query object.
Entities are identified by a unique ID. You provide a getId function and a getTerms function that returns an array of strings (features) to be indexed for each entity.
import * as fuzzySearch from './path/to/fuzzy-search.module.js';
const searcher = fuzzySearch.SearcherFactory.createDefaultSearcher();
const persons = [
{ id: 23501, firstName: 'Alice', lastName: 'King' },
{ id: 99234, firstName: 'Bob', lastName: 'Bishop' }
];
// Index entities
// getId: (e) => e.id
// getTerms: (e) => [e.firstName, e.lastName, `${e.firstName} ${e.lastName}`]
const indexingMeta = searcher.indexEntities(
persons,
(e) => e.id,
(e) => [e.firstName, e.lastName, `${e.firstName} ${e.lastName}`]
);
// Perform a search
const result = searcher.getMatches(new fuzzySearch.Query('alice kign'));
console.log(result.matches);