我想知道是否可以仅禁用 MongoDB 文本搜索中的停用词过滤。有时我只想搜索“you”、“I”、“was”等词。我仍然想利用词干提取。 只是不是停用词过滤。
db.collection.find({$text: {$search: "you"}})
以上不会返回任何结果。
但是像这样的传统方法
db.collection.find({shortDescription: new RegExp(".*you.*",'i')})
会给我我想要的。
那么,我怎样才能在进行文本搜索的同时也能够搜索这些单词(停用词)。
最佳答案
您可以通过在创建文本索引时更改文本索引的语言值来禁用停用词。来自 MongoDB 文档:
If you specify a language value of "none", then the text search uses simple tokenization with no list of stop words and no stemming [source].
因此创建索引使用:
db.collection.createIndex(
{ content : "text" },
{ default_language: "none" }
)
关于javascript - 在 MongoDB 文本搜索中禁用停用词过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49171693/