我需要自定义停用词列表,以便按文档
标题进行搜索。
我有以下映射:
@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
文件中不存在的停用词(例如, 将
这个词。
当前配置有什么问题? 如何使 hibernate 搜索使用自定义停用词列表?
我使用 hibernate-search-orm 5.6.1 版本。
结果在集成测试中通过即时创建的索引进行验证:
@Before
public void setUpLuceneIndex() throws InterruptedException {
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
fullTextEntityManager.createIndexer().startAndWait();
}
最佳答案
据我所知,您的配置看起来很正常。
更改停用词配置后,您是否重新索引了实体?您需要在索引时考虑新配置。
如果你这样做了但仍然不起作用,请尝试在 StopFilterFactory 构造函数中添加断点并通知方法以查看发生了什么!
关于java - Hibernate 搜索自定义停用词列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47111852/