1 回答

TA貢獻(xiàn)1785條經(jīng)驗(yàn) 獲得超8個(gè)贊
在 Hibernate Search 5.11(以及自 5.6 或 5.7,IIRC)中,您可以使用LuceneAnalysisDefinitionProvider.
實(shí)現(xiàn)接口:
public class CustomAnalysisDefinitionProvider implements LuceneAnalysisDefinitionProvider {
? ? @Override
? ? public void register(LuceneAnalyzerDefinitionRegistryBuilder builder) {
? ? ? ? builder.analyzer( "myAnalyzer" )
? ? ? ? ? ? ? ? ? ? ? ? .tokenizer( KeywordTokenizerFactory.class )
? ? ? ? ? ? ? ? ? ? ? ? .tokenFilter( ClassicFilterFactory.class )
? ? ? ? ? ? ? ? ? ? ? ? .tokenFilter( LowerCaseFilterFactory.class )
? ? ? ? ? ? ? ? ? ? ? ? .tokenFilter( StopFilterFactory.class )
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // You can pass parameters like this
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? .param( "mapping", "org/hibernate/search/test/analyzer/stoplist.properties" )
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? .param( "ignoreCase", "true" );
? ? ? ? // You can define multiple analyzers
? ? ? ? builder.analyzer( "otherAnalyzer" )
? ? ? ? ? ? ? ? ? ? ? ? .tokenizer( ... ) ...
? ? }
}
然后告訴 Hibernate Search 使用它:
# In properties.java
hibernate.search.lucene.analysis_definition_provider = com.mycompany.CustomAnalysisDefinitionProvider;
您可以在 的實(shí)現(xiàn)中自由地執(zhí)行任何操作register,因此您可能可以檢查系統(tǒng)屬性,甚至加載配置文件。如果您的實(shí)現(xiàn)集有限,您還可以在啟動(dòng) JVM 時(shí)通過hibernate.search.lucene.analysis_definition_provider系統(tǒng)屬性設(shè)置直接覆蓋定義提供程序。
添加回答
舉報(bào)