gpt4 book ai didi

Mongodb 文本搜索精确短语

转载 作者:行者123 更新时间:2023-12-05 03:06:06 25 4
gpt4 key购买 nike

我有一个包含以下文档的集合:

{
"_id" : ObjectId("5ad609a2ac1a8b644180936a"),
"content" : "Coffee and cakes..."
},
{
"_id" : ObjectId("5ad609baac1a8b644180936b"),
"content" : "coffee shop..."
}

文本搜索查询的结果:

find({ $text: { $search: "\"coffee shop\" cakes" } })

仅返回第二个文档,但我期待两个文档。问题是什么?

最佳答案

这...

find({ $text: { $search: "coffee shop cakes" } })

... 将搜索任何具有 content 属性且包含“coffee”、“shop”或“cake”之一的文档

但是这...

find({ $text: { $search: "\"coffee shop\" cakes" } })

... 将搜索任何具有 content 属性且包含短语“coffee shop”的文档。

我认为当您提交一个短语(“咖啡店”)一个额外的搜索值(“蛋糕”)时,您会期待上述两种行为。但是,这不是 MongoDB 处理短语和附加术语组合的方式。

来自 the docs :

If the $search string includes a phrase and individual terms, text search will only match the documents that include the phrase.

基于 these docs查询 "\"coffee shop\"cakes" 将被评估为:

"coffee shop" AND ("cakes" or "coffee" or "shop")

这只正确匹配第二个文档。

注:text index docs与此相矛盾,根据那些文档,查询 "\"coffee shop\"cakes" 将被评估为:"coffee shop"OR "cakes" 但您的行为观察与上面引用的 $text 运算 rune 档一致。

感谢@RahulRaj raising this issue with MongoDB ,他们的回复确认文档不正确:

As you correctly note, there is an inconsistency in the documentation between these two pages. We're tracking this fix to the documentation in DOCS-10382.

https://docs.mongodb.com/manual/reference/operator/query/text/#phrases correctly describes the current implementation of this feature.

关于Mongodb 文本搜索精确短语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49882368/

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