Skip to content

Commit

Permalink
Added text search convenience methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
James Bliss committed Jun 13, 2013
1 parent c557360 commit 49d7d1b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mongokit/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,9 @@ def find_random(self):
num = random.randint(0, max-1)
return self.find().skip(num).next()

def text(self, search, **kwargs):
"""
Executes a full-text search. Additional parameters may be passed as keyword arguments.
"""
return self.database.command("text", self.name, search=search, **kwargs)

10 changes: 10 additions & 0 deletions mongokit/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,16 @@ def find_random(self):
num = random.randint(0, max-1)
return self.find().skip(num).next()

def text(self, search, **kwargs):
"""
Executes a full-text search. Additional parameters may be passed as keyword arguments.
"""
rv = self.collection.database.command("text", self.collection.name, search=search, **kwargs)
if 'results' in rv:
for res in rv['results']:
res['obj'] = self._obj_class(res['obj'])
return rv

def get_from_id(self, id):
"""
return the document which has the id
Expand Down

0 comments on commit 49d7d1b

Please sign in to comment.