Question

I'm using Hibernate Search DSL to make the query and I need to search some keyword in French.

For example, when I use this query:

Query query = queryBuilder.keyword().onField("normVal").matching("asthme").createQuery();

It just matches the word asthme on field "normVal", but I want the query can find the word "l'asthme" or "d'asthme" too.

Is someone know how can I do this in Hibernate Search?????????

Was it helpful?

Solution

You can use the matching method with wildcard characters in your string: ? represents a single character and * represents any character sequence

So your code, for example, could be:

 Query query = queryBuilder.keyword().onField("normVal").matching("*asthme*").createQuery();

You can find more details here

Edit after OP comment

If you have fixed values to search, like words with articles, you can also try something like this instead of wildcars:

Query query = queryBuilder.bool()
.should(queryBuilder.keyword().onField("normVal").matching("l'asthme").createQuery())
.should(queryBuilder.keyword().onField("normVal").matching("d'asthme").createQuery())
.should(queryBuilder.keyword().onField("normVal").matching("asthme").createQuery())
.createQuery();

Please notice that the should method will work like an OR query operator

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top