gpt4 book ai didi

mongodb - 无法在 mongodb 中搜索 "once"

转载 作者:可可西里 更新时间:2023-11-01 10:08:48 27 4
gpt4 key购买 nike

我正在像这样在 mongodb 中进行文本搜索:

db.getCollection('textsearches').find({"$text" : {"$search" : "once"}})

这没有给我任何结果。当我尝试将搜索修改为如下内容时:

db.getCollection('textsearches').find({"$text" : {"$search" : "once upon"}});

它给了我正确的结果,其中明显有一个字段中包含短语“once upon”。为什么它不适用于关键字“一次”?这与词干提取在 mongodb 中的工作方式有什么关系吗?

最佳答案

来自docs

MongoDB supports text search for various languages. text indexes drop language-specific stop words (e.g. in English, the, an, a, and, etc.) and use simple language-specific suffix stemming. For a list of the supported languages, see Text Search Languages.

If you specify a language value of "none", then the text index uses simple tokenization with no list of stop words and no stemming.

因此您可以通过将 default_language 指定为 nonecreateIndex

db.getCollection("textsearches").createIndex(
{ "field" : "text" },
{ "default_language": "none" }
)

关于mongodb - 无法在 mongodb 中搜索 "once",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54402050/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com