Keyword searching with MongoEngine

109 views
Skip to first unread message

Russ Weeks

unread,
Mar 15, 2013, 7:36:33 PM3/15/13
to mongoeng...@googlegroups.com
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

Laurent Payot

unread,
Mar 18, 2013, 10:10:48 AM3/18/13
to mongoeng...@googlegroups.com
Note that text search will be available in MongoDB 2.4 via text indexes: see http://docs.mongodb.org/manual/release-notes/2.4/#text-indexes


2013/3/16 Russ Weeks <rwe...@newbrightidea.com>

--
You received this message because you are subscribed to the Google Groups "MongoEngine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoengine-us...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ross Lawley

unread,
Mar 19, 2013, 6:10:07 AM3/19/13
to mongoeng...@googlegroups.com
Yes, might be easier to wrap using full text search - 2.4 should be released soon.

Ross

Gustavo Gawryszewski

unread,
Mar 19, 2013, 6:41:08 AM3/19/13
to mongoeng...@googlegroups.com
I don't know exactly what are going to be mongos capabilities for fulltext search, but I always avoid this kind of thing in mongo. I usually have some fulltext search server indexing mongo content like ElasticSearch which is way faster and powerful for text search then mongo.

-- 
Gustavo Gawryszewski

Laurent Payot

unread,
Mar 19, 2013, 7:55:23 AM3/19/13
to mongoeng...@googlegroups.com
They don't say it too loud but ElasticSearch is written in Java and I try to keep my servers Java-Free.


2013/3/19 Gustavo Gawryszewski <gustav...@gmail.com>
Reply all
Reply to author
Forward
0 new messages