2 ms·
This reminds me of a browser-side search I once wrote using a combination of regex, Soundex, and Damerau-Levenshtein. The reason I made this browser-side is be
by ravenstine 8y ago
This reminds me of a browser-side search I once wrote using a combination of regex, Soundex, and Damerau-Levenshtein. The reason I made this browser-side is because the app doesn't have that many records that it needed to be on the server; the records were in the hundreds to thousands, not millions.
https://github.com/SCPR/fire-tracker/blob/master/app/lib/search-index.js https://github.com/SCPR/fire-tracker/blob/master/app/lib/sea...
Not the best code I've ever written by far, but it was a neat little experiment.
Basically, indexing each record with Soundex(phonetics) makes the search semi-tolerant to misspellings and also brings up similar-sounding results, while Damerau-Levenshtein is used to sort the results by closeness. I also had it index timestamps with
Here it is in action:
https://firetracker.scpr.org/archive https://firetracker.scpr.org/archive
As you can see, you can misspell search terms and it will usually get it right. Granted, a lot of unrelated records usually come up in a search, but the important thing is the user should get what they're looking for in the first few results, usually the first.
Regex is a powerful thing.