简体   繁体   English

如何在pymongo的索引字段中查询几个单词?

[英]How can I query several words in indexed fields in pymongo?

When I want to execute a indexed text search i use the following command: 当我想执行索引文本搜索时,请使用以下命令:

text_results = db.command('text', 'foo', search=query)

I am now wondering how I can query several words. 我现在想知道如何查询几个单词。 I tried already to set the query to query = ['word1', 'word2'] but that does not work. 我已经尝试将查询设置为query = ['word1', 'word2']但这不起作用。

Using the the search string "word1 word2" searches for the term word1 OR the term word2 : 使用搜索字符串"word1 word2"搜索单词word1或单词word2

text_results = db.command('text', 'foo', search='word1 word2')

Also, here's a quote from docs : 另外,这是docs的引文:

If the search string includes phrases, the search performs an AND with any other terms in the search string; 如果搜索字符串包含短语,则搜索将与搜索字符串中的任何其他术语进行“与”运算; eg search for "\\"twinkle twinkle\\" little star" searches for "twinkle twinkle" and ("little" or "star"). 例如,搜索“ \\”,“小星星”和“(小”或“星”)。

So to search where the field contains "word1" AND "word2" , go for 因此要搜索包含"word1""word2"的字段,请转到

text_results = db.command('text', 'foo', search="\"word1\" \"word2\"")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM