简体   繁体   中英

HiberateSearch - Multiple Analyzers for a single field

How do I use multiple analyzers for a single field in my Java class?

For example, currently my class looks like this:

public class User {
   @AnalyzerDef(name = "my_analyzer",
        tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
        filters = {...
   })
   @Analyzer(definition = "my_analyzer")
   private String name;
}

I would like to define another analyzer on the name field.

You need to use @Fields on the property, specifying an array if @Field annotations. Each @Field in turn can specify its own analyzer via the analyzer property.

You cannot specify multiple top level analyzer for a single field. Of course within a @AnalyzerDef you are free to assemble filters as you like to customize the analyzer behaviour.

What makes most sense will depend on the use case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM