[JIRA] (HSEARCH-4864) Add fuzzy query in Hibernate Search 6
by Yoann Rodière (JIRA)
Yoann Rodière ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *commented* on HSEARCH-4864 ( https://hibernate.atlassian.net/browse/HSEARCH-4864?atlOrigin=eyJpIjoiZDZ... )
Re: Add fuzzy query in Hibernate Search 6 ( https://hibernate.atlassian.net/browse/HSEARCH-4864?atlOrigin=eyJpIjoiZDZ... )
Thanks for opening this.
>
>
>
> because Elasticsearch do not allow for match query with fuzziness with
> Ngram token
>
>
That seems suspicious as I wouldn’t expect the origin of tokens to matter. But as I’m not familiar with the problem, I can’t really tell for sure.
Regardless, I’m not sure it will be as useful as you seem to think. From what I can see the fuzzy predicate in Elasticsearch ( https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl... ) only accepts one term, and I don’t think it performs analysis. In general I would say fuzziness in the match / simpleQueryString predicates is more useful, but then I don’t know about your exact use case, so maybe in your specific case it isn’t? 🤷♂️
>
>
>
> Will there be support for fuzzy query in the future?
>
>
There already is if you’re willing to resort to native features ( https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_singl... ) , i.e. to write your fuzzy predicate as JSON:
String fieldName = "title_ngram";
String term = "robot";
JsonObject fuzzyPredicate = new JsonObject();
JsonObject fieldJson = new JsonObject();
fuzzyPredicate.add("fuzzy", fieldJson);
JsonObject innerJson = new JsonObject();
fieldJson.add(fieldName, fieldJson);
innerJson.addProperty("value", term);
innerJson.addProperty("fuzziness", 1);
List<Book> hits = searchSession.search( Book.class )
.extension( ElasticsearchExtension.get() )
.where( f -> f.fromJson( fuzzyPredicate ) )
.fetchHits( 20 );
Otherwise, someone can always consider contributing the feature themself. You can look at the following PRs that added support for other predicates to get hints as to where to add code, how to test it, etc.:
* https://github.com/hibernate/hibernate-search/pull/2532/files
* https://github.com/hibernate/hibernate-search/pull/2486/files
( https://hibernate.atlassian.net/browse/HSEARCH-4864#add-comment?atlOrigin... ) Add Comment ( https://hibernate.atlassian.net/browse/HSEARCH-4864#add-comment?atlOrigin... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:4a1ccf9 )
2 years, 10 months