Take the 2-minute tour ×

I have a blog and I want to search titles with mongodb, not with solr or elastic search, for example, I have those titles,

wolkswagen polo
wolkswagen passat

In wolkswagen, I have the history of wolkswagen, in polo and passat, I have those cars' definitions, I tokenized titles by space. When I type "wolkswagen", polo and passat are on top, but wolkswagen should be on top, what should be the algorithm to take wolkswagen on top ?

thank you :)

share|improve this question
How are you searching in MongoDB? Are you using the new fts feature in 2.4? –  Sammaye Feb 3 '13 at 14:50
no I tokenize the titles by their spaces, and add the keywords in an embedded array, If i use fts, do i get wolkswagen on top ? –  user1794257 Feb 3 '13 at 14:54
add comment

1 Answer

up vote 2 down vote accepted

Ok well you have two options here:

You can use the new FTS feature in 2.4: http://architects.dzone.com/articles/mongodb-full-text-search . I should mention that FTS is experimental and very badly documented so this might not suite you. It sorts by relevance by default so the pattern of results you are looking for is automatically applied.

You can do client processing (not advised for large sets) whereby you get the results out and you manually actually test for the relevance to each word in the search block. As to the algorithm for that maybe something like:

  • iterate every word separated by a space
  • assign a value of 0 - 1 for how complete of a word it is, if it matches a complete word then assign 1
  • Add this up and place it back into the row for each result.
  • Use client side sorting to sort by the score of each result.

I am afraid that without knowledge of your programming language that is about the best the I can do.

share|improve this answer
thsnk you :) this one helped :) –  user1794257 Feb 3 '13 at 16:10
add comment

Your Answer


