Searching amongst a list of strings
I have a list of article names which are strings, and based on a user query, I need to output a best search out of that list of article names. I was thinking about what kind of an algorithm would work here. It should suggest the closest match possible, IMO. Or is there a better way of doing I have in m开发者_开发问答ind?
You can try using an edit distance algorithm with a tolerance value of n (either in absolute or in percentage) for a result to be within the scope of the search-for example, an article whose edit distance to the query is more than 50% its length may be put out of scope in most cases. Next, you can sort results by their percentual edit distance to the query string so that an exact match is a 100% match, an article whose name is 99% similar to the query is ranked as 99% similar, and so on.
Check out Lucine. This is a popular open source solution for text search. It will probably save your time preventing you from reinventing the wheel.
精彩评论