MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / test_index_text

Method test_index_text

test/test_collection.py:480–499  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

478
479 @client_context.require_no_mongos
480 def test_index_text(self):
481 db = self.db
482 db.test.drop_indexes()
483 self.assertEqual("t_text", db.test.create_index([("t", TEXT)]))
484 index_info = (db.test.index_information())["t_text"]
485 self.assertIn("weights", index_info)
486
487 db.test.insert_many(
488 [{"t": "spam eggs and spam"}, {"t": "spam"}, {"t": "egg sausage and bacon"}]
489 )
490
491 # MongoDB 2.6 text search. Create 'score' field in projection.
492 cursor = db.test.find({"$text": {"$search": "spam"}}, {"score": {"$meta": "textScore"}})
493
494 # Sort by 'score' field.
495 cursor.sort([("score", {"$meta": "textScore"})])
496 results = cursor.to_list()
497 self.assertGreaterEqual(results[0]["score"], results[1]["score"])
498
499 db.test.drop_indexes()
500
501 def test_index_2dsphere(self):
502 db = self.db

Callers

nothing calls this directly

Calls 7

drop_indexesMethod · 0.45
create_indexMethod · 0.45
index_informationMethod · 0.45
insert_manyMethod · 0.45
findMethod · 0.45
sortMethod · 0.45
to_listMethod · 0.45

Tested by

no test coverage detected