Reputation: 49823
I'm planning to build a full text search in my php application powered with Mongo db.
The full text search will be hover collection's documents stored like this:
title: "the title" STRING
description: "the description" STRING
So, as the Mongo Db official guide says, i must split the field where i must search into keywords and push keywords inside a new document field (_keywords), and this could be done in the insert statment.
So if i want to search inside both title and description fields i must split them both ?
Also does i need only 1 _keywords:{} field in the document or i need 2 separated _keywords fields (1 for title and 1 for description)?
Then is there someone can explain how can i add some sort of priorities when searching inside _keywords or even which are the best practice to do that (PHP does it, Mongo does it, others does it)?
Upvotes: 1
Views: 1577
Reputation: 9210
Mongodb isnt designed to be a full text search engine, and I wouldn't try to make it act like one. It will probably hurt your performance in the long run as you'll need to index those tokenized keywords and thats going to be quite a bit of data. Since Mongodb tries to keep your indexes in memory, doing this will increase your chance of pushing more important data out of memory, effectively killing your performance.
Instead, consider using Lucene, Solr, or ElasticSearch.
I am using Solr to power my search effort where MongoDB doesnt quite cut it. I've read great things about ElasticSearch - seems like you have to do almost no configuration on it which makes it great for people who are new to Lucene.
EDIT: This information was accurate as the the time of writing but MongoDB has since added Full text searching. You can read more about this here: http://docs.mongodb.org/manual/core/text-search/
I still believe that support for this was hacked in as an afterthought but if all you need to do is return a document based on matching a keyword, then this will suffice. However, if you are after a slightly more robust search tool, a Lucene derivative is still your best bet.
Upvotes: 3
Reputation: 2794
Full text search is available as of Version 2.4
Check out @ http://docs.mongodb.org/manual/core/text-search/
Text search supports the search of string content in documents of a collection. Text search introduces a new text index type and a new text command.
The text search process:
tokenizes and stems the search term(s) during both the index creation and the text command execution. assigns a score to each document that contains the search term in the indexed fields. The score determines the relevance of a document to a given search query.
Upvotes: 1