Start a text search, using text indexes. Require: MongoDB server version 2.6+. :param language: The language that determines the list of stop words for the search and the rules for the stemmer and tokenizer. If not specified, the search uses the def
(self, text, language=None, text_score=True)
| 231 | return self.__call__(*q_objs, **query) |
| 232 | |
| 233 | def search_text(self, text, language=None, text_score=True): |
| 234 | """ |
| 235 | Start a text search, using text indexes. |
| 236 | Require: MongoDB server version 2.6+. |
| 237 | |
| 238 | :param language: The language that determines the list of stop words |
| 239 | for the search and the rules for the stemmer and tokenizer. |
| 240 | If not specified, the search uses the default language of the index. |
| 241 | For supported languages, see |
| 242 | `Text Search Languages <https://docs.mongodb.org/manual/reference/text-search-languages/#text-search-languages>`. |
| 243 | :param text_score: True to have it return the text_score (available through get_text_score()), False to disable that |
| 244 | Note that unless you order the results, leaving text_score=True may provide randomness in the returned documents |
| 245 | """ |
| 246 | queryset = self.clone() |
| 247 | if queryset._search_text: |
| 248 | raise OperationError("It is not possible to use search_text two times.") |
| 249 | |
| 250 | query_kwargs = SON({"$search": text}) |
| 251 | if language: |
| 252 | query_kwargs["$language"] = language |
| 253 | |
| 254 | queryset._query_obj &= Q(__raw__={"$text": query_kwargs}) |
| 255 | queryset._mongo_query = None |
| 256 | queryset._cursor_obj = None |
| 257 | queryset._search_text = text |
| 258 | queryset._search_text_score = text_score |
| 259 | |
| 260 | return queryset |
| 261 | |
| 262 | def get(self, *q_objs, **query): |
| 263 | """Retrieve the matching object raising |