【发布时间】:2016-02-06 05:04:45
【问题描述】:
当我想执行索引文本搜索时,我使用以下命令:
text_results = db.command('text', 'foo', search=query)
我现在想知道如何查询几个单词。我已经尝试将查询设置为query = ['word1', 'word2'],但这不起作用。
【问题讨论】:
标签: mongodb indexing pymongo text-search multi-query
当我想执行索引文本搜索时,我使用以下命令:
text_results = db.command('text', 'foo', search=query)
我现在想知道如何查询几个单词。我已经尝试将查询设置为query = ['word1', 'word2'],但这不起作用。
【问题讨论】:
标签: mongodb indexing pymongo text-search multi-query
使用搜索字符串"word1 word2" 搜索术语word1 或术语word2:
text_results = db.command('text', 'foo', search='word1 word2')
另外,这里引用 docs 的一句话:
如果搜索字符串包含短语,则搜索执行 AND 与 搜索字符串中的任何其他术语;例如搜索“\”闪烁 twinkle\" little star" 搜索 "twinkle twinkle" 和 ("little" or “星”)。
所以要搜索该字段包含"word1" AND "word2" 的位置,请选择
text_results = db.command('text', 'foo', search="\"word1\" \"word2\"")
【讨论】: