Partial match search every key's value in a document with MongoDB -


i'm working on project client wants store information trucks, trailers, , other types of equipment in database. after comparing , contrasting relational databases solutions mongodb, i've found flexibility of schema-less type of database combined way data going accessed application makes mongo better choice (see schema below). there's 1 issue i'm having, , how implement autocomplete search. salesmen want able search key (model, year, price, odometer reading) , list of documents match result. example, salesman might search "freightliner" , expect example document attached below.

{   "_id": "e-123456",   "created_by": "2",   "status": "available",   "properties": [     {       "active": true,       "version": 1,       "last_modified": "2014-06-10 00:51:02",       "category": "heavy duty truck",       "subcategory": "conventional w/ sleeper",       "manufacturer": "freightliner",       "model": "cst12064st-century 120",       "year": 2009,       "price": 39950,       "wholesaleprice": 0,       "odometer": 129000     }   ],   "images": [array of image urls],   "salesman_chat": [array of chat subdocuments],   "created_at": "2014-06-10 00:51:02", } 

i able working using db.equipment.ensureindex({"$**":"text"}), , searching this: db.equipment.find({$text:{$search:"freightliner"}}). problem i'm having since acting autocomplete, want start displaying results begin typing, , i'm unable figure out how partial or wildcard matches. example, want search "e-12" return of documents _id of "e-12*".

my question is, i'm not sure if it's possible use $regex mongo's $text search. if is, how do that?

i've looked around stackoverflow while , of solutions have suggested creating separate collection _id reference , array holding values of of source document's keys (like list of keywords searched). way can while keeping structure of data same , without using other database solutions? should elasticsearch or solr?

when want search partial words, text index wrong tool use, because indexes complete words.

when want match partial words, have use normal indexes on fields searching makes sense. can search individual fields regular expressions. however, keep in mind regular expressions benefit indexes when begin begin-of-string anchor ^.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -