I am trying to use mongodb full text search for showing suggestion will the user is typing. I have done all the necessary steps to create the text indexes and enable the full text search feature on the database and everything is working fine except from the precision of the results.
I was using regexp to implement the same logic and for example when a user typed 'blue' then there was a suggestion containing 'bluetooth' something similar to 'blue*' but using mongos full text search I am getting a result only when I type 'bluetoot'.
I have tried using the " character to match exactly e.g.'\"blue\"' and every other imaginable combination I could think of but in vain.
So my question is if there is a way to implement this in mongo? and if mongo supports something like the * character used in regexp or the used algorithm tries to do an exact match of a word?
regards, Maximos
Currently, MongoDB's text search does not support searching on partial words. The command matches on the complete stemmed word-- it's likely that 'bluetooth' and 'bluetoot' stem to the same root which is why that search term is working while 'blue' is not. (Source.) MongoDB's text search uses the open source stemmer Snowball.
If you're still interested in implementing autocompletion, using regexp or an outside autocomplete library (perhaps Typeahead.js?) is probably your best bet. For example, if you wanted to suggest article titles, you could cache the titles to a json file every few days and pass that json data to Typeahead.js.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With