I’m trying to decide between two options to achieve a prefix match for names (50 Millions options) with MySQL. The usage is for an autocomplete for search results. The dilemma is between building:
- An index on the VARCHAR and performing a LIKE ‘word%’ query
- A FTS (full text search) index and performing a MATCH ‘word*’ query
Which is better for such a case? Should I consider additional FTS features for such an auto-suggest autocomplete of names?
FTS and prefix matching are two different things. So the answer depends on what your actual requirement is.
Do you need to return a list of all results that exactly match the condition
column LIKE 'word%'? Specifically that the string must start with the word you’re looking for.Full text search does matching based on relevance. It’s not always going to give you things that match specific strings. It does stemming, it has stopwords, it omits results if a word is too common.
I think in this case the best answer is “Full text search doesn’t quite do what you think it does” So if you have precise requirements for matching, you should stick to the method that will work.