(self)
| 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 |
nothing calls this directly
no test coverage detected