Is there a way to define a @AnalyzerDef annotation in a xml file, so that I have to define it only once? I have multiple entity classes that should all use the same AnalyzerDef. Currently my annotation looks like this:
@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;
}
}
We don't have XML configuration for Hibernate Search.
That being said, with the annotations, you need to define your analyzer definitions only once globally.
The only constraint you have is that they need to be defined on an entity but you can choose this entity randomly and define all your analyzers on it and they will be available in all your other entities, provided you reference them using their names (as you did in your example).
In $previousJob, we defined all our generic analyzers on an entity shared by all our projects: 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.