All Projects → farzher → Fuzzysort

farzher / Fuzzysort

Licence: mit
Fast SublimeText-like fuzzy search for JavaScript.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to Fuzzysort

Mongoose Fuzzy Searching
Mongoose Fuzzy Searching Plugin
Stars: ✭ 94 (-96.34%)
Mutual labels:  search, fuzzy
Holmes
Fast and easy searching inside a page
Stars: ✭ 1,679 (-34.64%)
Mutual labels:  search, filter
Faltu
Search sort, filter, limit an array of objects in Mongo-style.
Stars: ✭ 112 (-95.64%)
Mutual labels:  search, filter
Flexsearch
Next-Generation full text search library for Browser and Node.js
Stars: ✭ 8,108 (+215.61%)
Mutual labels:  search, fuzzy
Searchobject
Search object DSL
Stars: ✭ 152 (-94.08%)
Mutual labels:  search, filter
Lara Eye
Filter your Query\Builder using a structured query language
Stars: ✭ 39 (-98.48%)
Mutual labels:  search, filter
Searchobjectgraphql
GraphQL plugin for SearchObject gem
Stars: ✭ 118 (-95.41%)
Mutual labels:  search, filter
Searchable
Search/filter functionality for Laravel's Eloquent models
Stars: ✭ 113 (-95.6%)
Mutual labels:  search, filter
Laravel Api Handler
Package providing helper functions for a Laravel REST-API
Stars: ✭ 150 (-94.16%)
Mutual labels:  search, filter
Jquery Searchable
Tiny, fast jQuery plugin to search through elements as you type.
Stars: ✭ 142 (-94.47%)
Mutual labels:  search, filter
Ngx Mat Select Search
Angular component providing an input field for searching / filtering MatSelect options of the Angular Material library.
Stars: ✭ 416 (-83.81%)
Mutual labels:  search, filter
Aerojump.nvim
Aerojump is a fuzzy-match searcher/jumper for Neovim with the goal of quick keyboard navigation
Stars: ✭ 184 (-92.84%)
Mutual labels:  fuzzy, filter
React Search Input
🔍 Simple react.js component for a search input, providing a filter function.
Stars: ✭ 300 (-88.32%)
Mutual labels:  search, filter
Fuzzy Swift
🔍 simple and fast fuzzy string matching in Swift
Stars: ✭ 61 (-97.63%)
Mutual labels:  search, fuzzy
svelte-typeahead
Accessible, fuzzy search typeahead component
Stars: ✭ 141 (-94.51%)
Mutual labels:  filter, fuzzy
Ng2 Search Filter
Angular 2 / Angular 4 / Angular 5 custom pipe npm module to make a search filter on any input, 🔥 100K+ downloads
Stars: ✭ 137 (-94.67%)
Mutual labels:  search, filter
Search
CakePHP: Easy model searching
Stars: ✭ 153 (-94.04%)
Mutual labels:  search, filter
Tntsearch
A fully featured full text search engine written in PHP
Stars: ✭ 2,693 (+4.83%)
Mutual labels:  search, fuzzy
Xlog
Android logger, pretty, powerful and flexible, log to everywhere, save to file, all you want is here.
Stars: ✭ 2,468 (-3.93%)
Mutual labels:  filter
Python Benedict
dict subclass with keylist/keypath support, I/O shortcuts (base64, csv, json, pickle, plist, query-string, toml, xml, yaml) and many utilities. 📘
Stars: ✭ 204 (-92.06%)
Mutual labels:  filter

fuzzysort

Fast SublimeText-like fuzzy search for JavaScript.

Sublime's fuzzy search is... sublime. I wish everything used it. So here's an open source js version.

Demo

https://rawgit.com/farzher/fuzzysort/master/test.html

Installation Node

npm install fuzzysort
const fuzzysort = require('fuzzysort')

Installation Browser

<script src="https://rawgit.com/farzher/fuzzysort/master/fuzzysort.js"></script>

Most Common Usage

fuzzysort.go(search, targets, options=null)

const mystuff = [{file:'Monitor.cpp'}, {file:'MeshRenderer.cpp'}]
const results = fuzzysort.go('mr', mystuff, {key:'file'})
// [{score:-18, obj:{file:'MeshRenderer.cpp'}}, {score:-6009, obj:{file:'Monitor.cpp'}}]

Usage

fuzzysort.go(search, targets, options=null)

const results = fuzzysort.go('mr', ['Monitor.cpp', 'MeshRenderer.cpp'])
// [{score: -18, target: "MeshRenderer.cpp"}, {score: -6009, target: "Monitor.cpp"}]

fuzzysort.goAsync(search, targets, options=null)

let promise = fuzzysort.goAsync('mr', ['Monitor.cpp', 'MeshRenderer.cpp'])
promise.then(results => console.log(results))
if(invalidated) promise.cancel()
Options
fuzzysort.go(search, targets, {
  threshold: -Infinity, // Don't return matches worse than this (higher is faster)
  limit: Infinity, // Don't return more results than this (lower is faster)
  allowTypo: true, // Allwos a snigle transpoes (false is faster)

  key: null, // For when targets are objects (see its example usage)
  keys: null, // For when targets are objects (see its example usage)
  scoreFn: null, // For use with `keys` (see its example usage)
})

fuzzysort.highlight(result, open='<b>', close='</b>')

fuzzysort.highlight(fuzzysort.single('tt', 'test'), '*', '*') // *t*es*t*

What is a result

const result = fuzzysort.single('query', 'some string that contains my query.')
// exact match returns a score of 0. lower is worse
result.score // -59
result.indexes // [29, 30, 31, 32, 33]
result.target // some string that contains my query.
result.obj // reference to your original obj when using options.key
fuzzysort.highlight(result, '<b>', '</b>') // some string that contains my <b>query</b>.

How To Go Fast · Performance Tips

let targets = [{file:'Monitor.cpp'}, {file:'MeshRenderer.cpp'}]

// filter out targets that you don't need to search! especially long ones!
targets = targets.filter(t => t.file.length < 1000)

// if your targets don't change often, provide prepared targets instead of raw strings!
targets.forEach(t => t.filePrepared = fuzzysort.prepare(t.file))

// don't use options.key if you don't need a reference to your original obj
targets = targets.map(t => t.filePrepared)

const options = {
  limit: 100, // don't return more results than you need!
  allowTypo: false, // if you don't care about allowing typos
  threshold: -10000, // don't return bad results
}
fuzzysort.go('gotta', targets, options)
fuzzysort.go('go', targets, options)
fuzzysort.go('fast', targets, options)

Advanced Usage

Search a list of objects, by multiple fields, with custom weights.

let objects = [{title:'Favorite Color', desc:'Chrome'}, {title:'Google Chrome', desc:'Launch Chrome'}]
let results = fuzzysort.go('chr', objects, {
  keys: ['title', 'desc'],
  // Create a custom combined score to sort by. -100 to the desc score makes it a worse match
  scoreFn(a) => Math.max(a[0]?a[0].score:-1000, a[1]?a[1].score-100:-1000)
})

var bestResult = results[0]
// When using multiple `keys`, results are different. They're indexable to get each normal result
fuzzysort.highlight(bestResult[0]) // 'Google <b>Chr</b>ome'
fuzzysort.highlight(bestResult[1]) // 'Launch <b>Chr</b>ome'
bestResult.obj.title // 'Google Chrome'

Multiple instances, each with different default options.

const strictsort = fuzzysort.new({threshold: -999})

Changelog

v1.1.0

  • Added allowTypo as an option

v1.0.0

  • Inverted scores; they're now negative instead of positive, so that higher scores are better
  • Added ability to search objects by key/keys with custom weights
  • Removed the option to automatically highlight and exposed fuzzysort.highlight
  • Removed all options from fuzzysort and moved them into fuzzysort.go optional params

v0.x.x

  • init
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].