I am creating db mongoDB to allow (simple) keyword searches using multikeys, as recommended here . The entry also looks:
{ title: { title: "A river runs through", _keywords: ["a","river","runs","through"] ) , ... }
I am using nodejs server side, so I am using javascript. The following query will match (this was done in the mongo terminal):
> db.torrents_sorted.find({'title._keywords' : {"$all" : ["river","the"]} }).count() 210
However, it is not:
> db.torrents_sorted.find({'title._keywords' : {"$all" : ["/river/i","/the/i"]} }).count() 0 > db.torrents_sorted.find({'title._keywords' : {"$all" : [{ "$regex" : "river", "$options" : "i" },{ "$regex" : "the", "$options" : "i" }]} }).count() 0
Using one regular expression (without using $ and or $ all) corresponds to:
db.torrents_sorted.find ({'title._keywords': {"$ regex": "river", "$ options": "i"}}). count () One thousand four hundred sixty one
Interestingly, using python and pymongo to compile regular expressions really works:
>>> db.torrents_sorted.find({'title._keywords': { '$all': [re.compile('river'), re.compile('the')]}}).count(); 236
I'm not necessarily looking for a solution that uses regular expressions, but it requires the keywords to be matched on shorter lines, so "riv" matches "river", which seems ideal for regular expressions (or LIKE in sql).
My next idea is to try switching to a javascript function that matches regular expressions in a list or maybe passes a separate function for each regular expression (this seems to scream hacking me :), although I assume it will be slower and the performance is very is important.