Hibernate 搜索自定义停用词列表

Hibernate search custom stop words list

我需要自定义停用词列表以按 Document 标题进行搜索。
我有以下映射:

@Entity
@Indexed
@AnalyzerDef(
        name = "documentAnalyzer",
        tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
        filters = {
                @TokenFilterDef(factory = ASCIIFoldingFilterFactory.class),
                @TokenFilterDef(factory = LowerCaseFilterFactory.class),
                @TokenFilterDef(
                        factory = StopFilterFactory.class,
                        params = {
                                @Parameter(name = "words", value = "stoplist.properties"),
                                @Parameter(name = "ignoreCase", value = "true")
                        }
                )
        }
)
public class Document {

    ...

    @Field(analyzer = @Analyzer(definition = "documentAnalyzer"))
    private String title;

    ...
}

stoplist.properties 文件位于 resources 目录中,包含与 StandardAnalyzer 默认值不同的停用词。

但如果我使用默认启用但不存在于我的 stoplist.properties 文件中的停用词,则搜索不会 return 任何结果,例如will.

这个词

当前配置有什么问题? 如何让休眠搜索使用自定义停用词列表?

我用的是hibernate-search-orm5.6.1版本

结果在创建索引的集成测试中得到验证 on-the-fly:

@Before
public void setUpLuceneIndex() throws InterruptedException {
    FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
    fullTextEntityManager.createIndexer().startAndWait();
}

据我所知,您的配置看起来很正常。

您是否在更改停用词配置后重新索引您的实体?您需要在索引时考虑新配置。

如果你这样做了,但它仍然不起作用,请尝试在 StopFilterFactory 构造函数中添加一个断点并通知方法以查看发生了什么!