Multi search support?
It's entirely possible I'm reaching for the wrong tool for this task...
I'm working on a purely client-side SPA. I have a master list of items and user input that is a comma separated list of item-like strings, and I want to filter the master list to the matching user items (while being tolerant of small misspellings/typos/casing)...
That is, given:
const allFruits = [
"Apple",
"Banana",
"Cherry",
"Grape",
"Kiwi",
"Mango",
"Orange",
"Peach",
"Pineapple",
"Strawberry"
];
const myFruits = "apple, orange, cherry";
I want to filter allFruits to ["Apple", "Cherry", "Orange"] (yes, I need to remember to set interLft=2 to avoid including "Pineapple").
I certainly can handle running n searches, and unioning the results. Will that be less than optimally performant (having to re-perform a lot search prep)? Would it ever make sense for uFuzzy to offer a multi filter API that accepted an array of "needles"?
Here's my current definition of multiFilter; functional, but likely somewhat suboptimal:
function multiFilter(haystack: string[], needles: string[]) {
return [
...new Set(needles.flatMap((needle) => uf.filter(haystack, needle)!)),
].toSorted((a, z) => a - z);
}
probably worth giving this a shot, it should be possible. https://github.com/leeoniya/uFuzzy/issues/58.
my original thinking was that i'd have to use | in the regexp, which makes it incompatible with the current design, but i can simply make each term optional to keep the needle-to-capture-groups mapping 1:1.
That's a clever-looking solution!