我在使用 MongoDB 中的全文搜索功能时遇到了一些问题。假设我有这个:
db.test.insert({fname:"blah.dll"})
db.test.insert({fname:"something.dll"})
db.test.ensureIndex({fname:"text"})
然后我...
db.test.runCommand("text", { search: "blah.dll" })
这将返回两个文档。似乎这段时间导致它成为:blah OR dll。
在这种情况下,正确的搜索方式是什么?
谢谢。
最佳答案
正如 Ben Fortune 在对原始问题的评论中所指出的,您可以通过用引号将搜索词括起来来防止拆分:
db.test.runCommand("text", { search: '"blah.dll"' })
一个重要的问题是,这样做也会改变查询的语义,因为每个引用的词都需要匹配:
'blah.dll something' - 返回包含 blah 或 dll 或其他内容的文档。
'blahdll something' - 返回包含 blahdll 或其他内容的文档。
'"blah.dll"something' - 返回包含 blah.dll(必需)和某些内容(可选)的文档。
'"blah.dll""something"' - 返回包含 blah.dll(必需)和 something(必需)的文档。
关于javascript - 带句点的 MongoDB 文本搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24532117/