Fuzzy search plugin

Note: The fuzzy search plugin is deprecated since v1.5.0, it's now bundled into List.js.

To use the plugin you first need to download it:

Via GitHub

Download list.fuzzysearch.js

Via Bower

bower install list.fuzzysearch.js

Via CDNJS

<script src="//cdnjs.cloudflare.com/ajax/libs/list.fuzzysearch.js/0.1.0/list.fuzzysearch.min.js"></script>

The difference between Fuzzy Search and List.js default search

The default search will conduct a time efficient search for an exact match in the content searched, while the fuzzy search will render results depending on if they are included anywhere in the content.

Basic example

var items = [
    { character: "Guybrush Threepwood", game: "The Secret of Monkey Island" },
    { character: "Manny Calavera", game: "Grim Fandango" },
    { character: "Bernard Bernoulli", game: "Maniac Mansion" }
];

list.search('gu thre'); // return none
list.fuzzySearch.search('gu thre') // return 1 item

Implementation

<div id="list-id">
  <input class="fuzzy-search" />
  <ul class="list">
    / A bunch of items /
  </ul>
</div>

<script>

var fuzzyOptions = {
  searchClass: "fuzzy-search",
  location: 0,
  distance: 100,
  threshold: 0.4,
    multiSearch: true
};
var options = {
  valueNames: [ 'name', 'category' ],
  plugins: [
    ListFuzzySearch(fuzzyOptions)
  ]
};

var listObj = new List('list-id', options);

// Search manually
listObj.fuzzySearch.search('my search');

// Search manually on specific columns
listObj.fuzzySearch.search('my search', { name: true });

</script>

Options

All options are optional. Simplest implementation is:

plugins: [ ListFuzzySearch() ]
  • location Int, default: 0
    Approximately where in the text is the pattern expected to be found?
  • distance Int, default: 100
    Determines how close the match must be to the fuzzy location (specified above). An exact letter match which is ‘distance’ characters away from the fuzzy location would score as a complete mismatch. A distance of 0 requires the match be at the exact location specified, a threshold of 1000 would require a perfect match to be within 800 characters of the fuzzy location to be found using a 0.8 threshold.
  • threshold Int, default: 0.4
    At what point does the match algorithm give up. A threshold of 0.0 requires a perfect match (of both letters and location), a threshold of 1.0 would match anything.
  • multiSearch Boolean, default: true
    Subtract arguments from the searchString or put searchString as only argument

A big thanks to LuukvE who made a commit from which I could create this Fuzzy Search plugin.