MongoDB$text $search找不到关键字:['by','and','me'...]



我有一个关于使用find搜索关键字'by'、'和'的问题。。。在我的收藏中,但在某些情况下出现了问题,有人知道如何修复吗?

这是我的收藏&索引:

db.stores.insert(
[
{ _id: 1, name: "Java Hut", description: "Coffee and cakes by Me" },
{ _id: 2, name: "Burger Buns", description: "by" },
{ _id: 3, name: "Coffee Shop", description: "Just coffee" },
{ _id: 4, name: "Clothes Clothes Clothes", description: "By Clothes" }
]
)
db.stores.createIndex( { name: "text", description: "text" } )

这个脚本会很好

db.stores.find({description: /by/})
db.stores.find({description: /and/})
db.stores.find( { $text: { $search: "java coffee shop" } } )
db.stores.find( { $text: { $search: ""coffee shop"" } } )
db.stores.find( { $text: { $search: ""and cakes by"" } } )
db.stores.find( { $text: { $search: "and cakes by" } } )
db.stores.find( { $text: { $search: "cakes" } } )
db.stores.find( { $text: { $search: "coffee" } } )

但这里出了问题,我不明白为什么关键字"by"、"and"、"me"。。。无法在此查询中使用。为什么我在文本搜索中单独使用它会出错?

db.stores.find( { $text: { $search: "by" } } )
db.stores.find( { $text: { $search: "and" } } )

如果你有关于这件事的文档或链接,请给我。或者如果这个问题在其他地方存在,也请告诉我。

谢谢!

编辑时间:类似的问题还有另一个在MongoDB文本搜索中禁用停止词过滤

@D.SM的答案是完美的。除此之外,

如果指定语言值";无";,然后文本索引使用简单的标记化,没有停止词列表,也没有词干

db.quotes.createIndex(
{ name : "text" },
{ default_language: "none" } ---> Note here
)

MongoDB支持各种语言的文本搜索。文本索引删除特定于语言的停止词(如英语、the、an、a和等(,并使用简单的特定于语言后缀词干。有关支持的语言列表,请参阅文本搜索语言。

这些被称为停止词,通常对.搜索没有用处

若要搜索短语,请将该短语括在引号中。

最新更新