在 MongoDB 文本搜索中禁用停用词过滤 [英] Disable stop word filtering in a MongoDB text search
问题描述
我想知道是否可以在 MongoDB 文本搜索中仅禁用停用词过滤.有时我只想搜索诸如you"、I"、was"等词.我仍然想利用词干.不是停用词过滤.
I am wondering if it would be possible to disable only the stop word filtering in the MongoDB text search. Sometimes I just want to search for words like "you", "I", "was", etc. I would still like to take advantage of the stemming. Just not the stop word filtering.
db.collection.find({$text: {$search: "you"}})
以上不会返回任何结果.
The above would not return any results.
但是像
db.collection.find({shortDescription: new RegExp(".*you.*",'i')})
会给我我想要的.
那么,我怎样才能在进行文本搜索的同时还能搜索这些词(停用词).
So, how can I have the text search but also be able to search these words (stop words).
推荐答案
您可以通过在创建文本索引时更改文本索引的语言值来禁用停用词.来自 MongoDB 文档:
You can disable stop words by changing the language value of your text index when you create it. From the MongoDB documentation:
如果您将语言值指定为none",则文本搜索使用简单的标记化,没有停用词列表和词干 [源].
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].
因此使用以下方法创建索引:
So create your index using:
db.collection.createIndex(
{ content : "text" },
{ default_language: "none" }
)
这篇关于在 MongoDB 文本搜索中禁用停用词过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!