Search code examples
mongodbfull-text-searchtext-search

MongoDB - searching text


What is the best strategy for selecting mongodb entries in which a string value contains a set of words or phrases? I'm thinking of something equivalent to mysql's LIKE function, e.g.

    WHERE (TEXT LIKE "% apple %") or (TEXT LIKE "% banana %")

I've seen options that involve tokenizing the string, but this would involve building unigrams for all the text, which would be huge no?


Solution

  • MongoDB has no full text search capability right now, but it's easy to use external search engines like SOLR.

    I strongly discourage you trying to rebuild text search with Regex or word stemming etc. yourself. You should rather focus on your app own features :)

    I am using this combination: Mongoid, Sunspot and Mongoid-Sunspot. It works very well in production, and development setup is easy.