Hibernate 搜索:XML 中的 AnalyzerDef

Hibernate Search: AnalyzerDef in XML

有没有办法在 xml 文件中定义 @AnalyzerDef 注释,这样我只需定义一次?我有多个实体 类,它们都应该使用相同的 AnalyzerDef。目前我的注释看起来像这样:

@Entity
@Cacheable
@Indexed
@AnalyzerDef(name = "ngram",
    tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
    filters = {
        @TokenFilterDef(factory = StandardFilterFactory.class),
        @TokenFilterDef(factory = LowerCaseFilterFactory.class),
        @TokenFilterDef(factory = NGramFilterFactory.class,
            params = {
                @Parameter(name = "minGramSize", value = "3"),
                @Parameter(name = "maxGramSize", value = "40")})
})
public class MobileDevice extends CommunicationDevicePlace implements Comparable<MobileDevice> {

    private String name;

    @Field(index = org.hibernate.search.annotations.Index.YES, analyze = Analyze.YES, store = Store.NO, analyzer = @Analyzer(definition = "ngram"))
    public String getName() {
        return name;
    }
}

我们没有 XML Hibernate Search 配置。

也就是说,有了注释,您只需在全局范围内定义一次分析器定义。

唯一的限制是它们需要在实体上定义,但您可以随机选择该实体并在其上定义所有分析器,它们将在所有其他实体中可用,前提是您使用它们引用它们他们的名字(正如您在示例中所做的那样)。

在 $previousJob 中,我们在所有项目共享的实体上定义了所有通用分析器:https://github.com/openwide-java/owsi-core-parent/blob/master/owsi-core/owsi-core-components/owsi-core-component-jpa-more/src/main/java/fr/openwide/core/jpa/more/business/parameter/model/Parameter.java and we used them in the other entities: https://github.com/openwide-java/owsi-core-parent/blob/master/owsi-core/owsi-core-components/owsi-core-component-jpa-more/src/main/java/fr/openwide/core/jpa/more/business/task/model/QueuedTaskHolder.java#L50