Skip to content

matutter/prefix-search

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Coverage Status Build Status dependencies Status

prefix-search

Prefix search finds the item in a list that has the longest matching prefix.

Using simple prefix searches will return the shortest matching string, or object based on the criterion.

const psearch = require('prefix-search')
var searchTerm = 'awe'
var docs = [{name: 'awesome'}, {name: 'awe! Kittens'}]
var res = psearch.objects(searchTerm, 'name', 'name', docs)
// res = {name, 'awesome'}; this string matched the most

ps.search returns the index of the best matching word. ps.words returns the string best matching the prefix, though -1 is still returned when there is no match.

var words = ['aabb', 'abba']
var index = psearch.search('aa', words)
console.log(index == 0) // returns index 0
index = psearch.words('bb', words) 
console.log(index == -1) // returns -1, "no match"

(WIP) Using the complex prefix search finds the item with the best matching critia within complex strings.

var res = psearch.Objects(searchTerm, 'name', docs)
// res = {name: 'awe! Kittens'}; the string 'awe' is an exact match

About

Prefix search finds the item in a list that has the longest matching prefix.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published