✅ 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
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
150 items? You can probably get away with a linear search
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
If it shouldn't be an exact match, then you can just do what you precisely need, e.g. StartsWith, EndsWith, or Contains.
Right, just walk the list and do whatever check is appropriate (substring search or whatever)
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>you could think of using a backing SortedList or SortedSet
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.