问题
@Entity
@Indexed
@AnalyzerDefs({
@AnalyzerDef(name = "en",
tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
filters = {
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = EnglishPorterFilterFactory.class
)
}),
@AnalyzerDef(name = "de",
tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
filters = {
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = GermanStemFilterFactory.class)
})
})
public class BlogEntry {
@Id
@GeneratedValue
@DocumentId
private Integer id;
@Field
@AnalyzerDiscriminator(impl = LanguageDiscriminator.class)
private String language;
@Field
private String text;
private Set<BlogEntry> references;
// standard getter/setter
// ...
}
public class LanguageDiscriminator implements Discriminator {
public String getAnalyzerDefinitionName(Object value, Object entity, String field) {
if ( value == null || !( entity instanceof Article ) ) {
return null;
}
return (String) value;
}
}
From Reference Doc,
How can I use an existing analyzer like org.apache.lucene.analysis.cjk.CJKAnalyzer
along with en
and de
ones which I have dynamically defined? I can only return name of the analyzer here and when I return CJKAnalyzer
I get not defined analyzer.
How can I add an existing analyzer to my analyzer definitions?
回答1:
That's an excellent question, and I'm surprised noone asked that before.
The answer is that it's not possible.
I have opened a feature request on the project to improve on this:
- https://hibernate.atlassian.net/browse/HSEARCH-2518
来源:https://stackoverflow.com/questions/40928584/use-existing-analyzer-in-hibernate-search-analyzerdiscriminator