Last active
February 3, 2016 21:16
-
-
Save nod/547ff7d0a91ad251fb4a to your computer and use it in GitHub Desktop.
Use text search in mongo 3.2+ with pymongo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For pymongo against mongodb 3.2... | |
# Given a collection of documents like | |
# {'textfield': 'cool stuff in a doc', 'other': 'fields...'} | |
# | |
# To perform the query, and get results sorted by the textual score: | |
db.my_collection.create_index([('textfield','text')]) | |
cursor = db.my_collection.find( | |
{'textfield': 'some string query'}, | |
{'_txtscr': {'$meta': 'textScore'} | |
).sort([('_txtscr', {'$meta':'textScore'})]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment