Use existing analyzer in hibernate search AnalyzerDiscriminator

十年热恋 提交于 2019-12-21 18:34:02

问题


@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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!