Trigram search
Trigram-based library for fast indexing and search over large arrays of data, written in TypeScript, built for Node.js and browser.
Demo
Installation
npm i trigram-search
Usage
;// or// import Trigram from "trigram-search/build/browser";
const data = [{ id: 0, title: "Javascript" }, { id: 1, title: "Python" }, { id: 2, title: "Go" }, ...];
const searcher = new Trigram(data);
searcher.find('Py'); // will output sorted array of results
API
Constructor
items config;
items
— array of objects with id
, title
and optional sort
fields (defaults).
id
— must be unique
title
— contains text for search
sort
— can be used to prioritize specific items higher in the results, even if match rate for them is lower
config
:
Methods
count
and minRate
in arguments will take precedence over global instance settings.
;