Fast Fuzzy Search In Pure JavaScript – fuzzysort

Category: Javascript , Recommended | October 8, 2018
Author: farzher
Views Total: 1,827
Official Page: Go to website
Last Update: October 8, 2018
License: MIT

Preview:

Fast Fuzzy Search In Pure JavaScript – fuzzysort

Description:

fuzzysort is a dependency-free JavaScript that provides fast, Sublime Text-like, client-side fuzzy search/live filter functionality with keyword highlighting for your large datasets.

How to use it:

Download and import the JavaScript file ‘fuzzysort.js’ into the document.

<script src="fuzzysort.js"></script>

Basic usages.

require('fuzzysort').single('fs', 'Fuzzy Search')
// {score: 0.1, highlighted: '<b>F</b>uzzy <b>S</b>earch'}

require('fuzzysort').single('test', 'test')
// {score: 0, highlighted}

require('fuzzysort').single('doesnt exist', 'target')
// {}

Advanced usages.

fuzzysort.single('query', 'some string that contains my query.')
// {score: 59, highlighted: "some string that contains my <b>query</b>."}
fuzzysort.single('query', 'irrelevant string') // null
// exact match returns a score of 0. lower score is better
fuzzysort.single('query', 'query') // {score: 0, highlighted: "<b>query</b>"}


fuzzysort.go('mr', ['Monitor.cpp', 'MeshRenderer.cpp'])
// [{score: 18, highlighted: "<b>M</b>esh<b>R</b>enderer.cpp"}
// ,{score: 6009, highlighted: "<b>M</b>onito<b>r</b>.cpp"}]

let promise = fuzzysort.goAsync('mr', ['Monitor.cpp', 'MeshRenderer.cpp'])
promise.then(results => console.log(results))
if(invalidated) promise.cancel()

Possible options with default values.

{
  noMatchLimit: 100, // if there's no match for a span this long, give up
  highlightMatches: true,
  highlightOpen: '<b>',
  highlightClose: '</b>',
  limit: null, // don't return more results than this
}

Changelog:

v1.1.4 (10/08/2018)

  • optimization

You Might Be Interested In:


Leave a Reply