I have a field which has a custom analyzer.
@Analyzer(definition = "edgeNgram")
@Field(index = Index.YES, analyze = Analyze.YES, store = Store.YES)
@Lob
String value;
Here is the analyzer on my class.
@AnalyzerDef(name = "edgeNgram",
tokenizer = @TokenizerDef(factory = WhitespaceTokenizerFactory.class),
filters = {
@TokenFilterDef(factory = ASCIIFoldingFilterFactory.class), // Replace accented characters by their simpler counterpart (è => e, etc.)
@TokenFilterDef(factory = LowerCaseFilterFactory.class), // Lowercase all characters
@TokenFilterDef(
factory = EdgeNGramFilterFactory.class, // Generate prefix tokens
params = {
@org.hibernate.search.annotations.Parameter(name = "minGramSize", value = "4"),
@org.hibernate.search.annotations.Parameter(name = "maxGramSize", value = "10")
}
)
})
And here I create my query.
query = queryBuilder
.simpleQueryString()
.boostedTo(3f) // This whole query is boosted so exact matches will obtain a better score
.onFields("title.value", "keyword.values.value")
.boostedTo(2f)
.andField("description.values.value")
//.withAndAsDefaultOperator()
.matching(Arrays.stream(searchTerm.split(" ")).map(e -> e + "*").collect(Collectors.joining(" ")).toLowerCase())
.createQuery();
I don't know how (and couldn't find in the docs of Hibernate Search) to set an Analyzer for the searching term searchTerm
. Basically I started splitting manually and setting it to lower case in Java. But that doesn't seem right.
What I want is to apply another analyzer to my query term such as:
@AnalyzerDef(name = "edgeNGram_query",
tokenizer = @TokenizerDef(factory = WhitespaceTokenizerFactory.class),
filters = {
@TokenFilterDef(factory = ASCIIFoldingFilterFactory.class), // Replace accented characeters by their simpler counterpart (è => e, etc.)
@TokenFilterDef(factory = LowerCaseFilterFactory.class) // Lowercase all characters
})
Do you know how to set a custom analyzer for the query term and why is it not applied by default? If I search "bouees" it works but if I search "bouées" it doesn't.
Thanks!
SOLUTION:
My issue was that I was making a simpleQueryString
, when I should have been doing a keyword
query. The simpleQueryString
doesn't seem to run the analyzer on the search term! Then I just had to follow @yrodiere .overridesForField( "description.values.value", "edgeNGram_query" )
to use the right search term analyzer.