Hi,
I'm trying to implement keyword searching with MongoEngine. I've already extracted the keywords from my documents and put them into a 'keywords' field, which is an array of strings.
My plan is to take a query string from the user, tokenize it, do an exact match on the 1..n-1 keywords and a partial match on the nth keyword. The idea is, this is an "autocomplete" style search so the user may not be finished typing the last keyword.
I've found a query that works in the mongodb console:
db.drug.find({
keywords:{
$all:['PREDNISOLONE',/^SULFA.*/]
}
})
And a couple that don't:
db.drug.find({
keywords: {
$all:['PREDNISOLONE'],
$regex:'^SULFACE.*'
}
}).count()
db.drug.find({
$and: [
{
keywords: {
$regex:'^SULFA.*',
$options: 'i'
}
},
{
keywords: {
$all:['PREDNISOLONE']
}
},
]
})
But I'm not sure it's possible to convert the first (working) query to either a MongoEngine query or a PyMongo query for use with __raw__. Any tips?
Thanks,
-Russ