fuzz-aldrin-plus
fuzz-aldrin-plus copied to clipboard
allow users to filter by mutiple keys
Example:
candidates = [
{ name: 'truck', lang: 'ruby', ext: '.rb' }
{ name: 'foo', lang: 'php', ext: '.php' }
{ name: 'ruby car', lang: 'ruby', ext: '.rb' }
]
expectedCandidates = candidates.slice(0, 2)
results = filter(candidates, 'ruby', keys: ['name', 'lang'])
expect(results.length).toBe 2
expect(results[0]).toBe expectedCandidates[0]
expect(results[2]).toBe expectedCandidates[2]
@jeancroy - sorry for the unnecessary second commit 😅 . If you do decide to merge, when you merge and squash it shouldn't pollute your commit history
I do not have a problem with commit pollution, maybe I should ;) ?
I did try to keep the library "math only" in that I know the filter method is very minimalist and it should be easy to write your own. With that being said i'm not against including a simple multiple key scenario.
In such a scenario one difficulty is how to agglomerate the score across the different fields. For example if you expect that query match a field at a time max(score_field1,score_field2)
is the proper function. If you expect that a single query can match across different fields sum
or average
is better.
This library is tuned to for atom text editor: programming symbols and paths. So it's a bit more "every characters count", "power user", rather than "friendly error correcting" kind of fuzzy. For that reason one field at a time max
is probably the proper mix function for this library. (Although I do have plans to add some friendlier mode )
May I inquiry about the kind of content that need to be searched ? I do have another library that is more optimized for natural language with spelling error, support out of order words, mix and max different fields in the same query etc.
https://github.com/jeancroy/FuzzySearch