我可以清除 lucene.net 中的停用词列表以使完全匹配更好地发挥作用吗?

Can I clear the stopword list in lucene.net in order for exact matches to work better?

在处理完全匹配时,我得到了这样一个真实世界的查询:

"not in education, employment, or training"

转换为删除停用词的 Lucene 查询得到:

+Content:"? ? education employment ? training" 

这是一个更人为的例子:

"there is no such thing"

转换为删除停用词的 Lucene 查询得到:

+Content:"? ? ? ? thing" 

我的目标是让此类搜索仅与用户输入的内容完全匹配。

一种解决方案是清除停用词列表吗?会不会有不良影响?如果是这样呢? (我的 google-fu 失败了)

这完全取决于您使用的分析仪。 StandardAnalyzer 使用停用词并将其删除,实际上 StopAnalyzerStandardAnalyzer 从中获取停用词的地方。

使用 WhitespaceAnalyzer 或通过继承最适合您需求的一个来创建您自己的,然后将其修改为您想要的。

或者,如果您喜欢 StandardAnalyzer,您可以使用自定义停用词列表新建一个:

//This is what the default stop word list is in case you want to use or filter this
var defaultStopWords = StopAnalyzer.ENGLISH_STOP_WORDS_SET;

//create a new StandardAnalyzer with custom stop words
var sa = new StandardAnalyzer(
    Version.LUCENE_29, //depends on your version
    new HashSet<string> //pass in your own stop word list
    {
        "hello",
        "world"
    });