C
C#15mo ago
Vеrsette

✅ String search by user text input algorithm

I have a list of some objects that have a "name" string, what is the best way to search for an object by getting an input string from a textbox? I tried sorting them by Levenshtein distance, but it doesn't really work that well when, for example, one string is shorter than other What algorithms are standard? I'm sure that there is a solution for this kind of thing as such "search by text input" is everywhere, but I couldn't find a good answer
8 Replies
Vеrsette
VеrsetteOP15mo ago
Search speed is a priority since it's a mobile app. The dataset is ~150 items Item names range from 5 characters to about 85
mtreit
mtreit15mo ago
150 items? You can probably get away with a linear search
Vеrsette
VеrsetteOP15mo ago
Linear search as in just checking if x string is equal to the input one or not? That wouldn't work well since then it would only give exact matches
hime
hime15mo ago
If it shouldn't be an exact match, then you can just do what you precisely need, e.g. StartsWith, EndsWith, or Contains.
mtreit
mtreit15mo ago
Right, just walk the list and do whatever check is appropriate (substring search or whatever)
Vеrsette
VеrsetteOP15mo ago
Sometimes the simplest solutions are the best, I don't know how I didn't think of that but yes, why do I even need "fuzzy" search and I can just use Contains and keep the same order. Thank you all, solved <a:PI_HeartScribble:703853250264301609>
Omnissiah
Omnissiah15mo ago
you could think of using a backing SortedList or SortedSet
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server