How can i implement a sublime-like fuzzy search on select2?
Example, typing "sta jav sub" would match "Stackoverflow javascript sublime like"
For example, if a user types "Misissippi" into Yahoo or Google -- both of which use fuzzy matching -- a list of hits is returned along with the question, "Did you mean Mississippi?" Alternative spellings and words that sound the same but are spelled differently are given.
A fuzzy search searches for text that matches a term closely instead of exactly. Fuzzy searches help you find relevant results even when the search terms are misspelled. To perform a fuzzy search, append a tilde (~) at the end of the search term.
6 min · Sabesh Bharathi. Fuzzy Search refers to the process of approximately searching for a given search query. It may also be called as a “typo tolerant search”.
Here's an alternate matching function. http://jsfiddle.net/trevordixon/pXzj3/4/
function match(search, text) { search = search.toUpperCase(); text = text.toUpperCase(); var j = -1; // remembers position of last found character // consider each search character one at a time for (var i = 0; i < search.length; i++) { var l = search[i]; if (l == ' ') continue; // ignore spaces j = text.indexOf(l, j+1); // search for character & update position if (j == -1) return false; // if it's not found, exclude this item } return true; }
This one's faster (according to this test in Chrome), which may start to matter if you're filtering a lot of items.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With