[hibernate-issues] [JIRA] (HSEARCH-3888) How to query in "Hibernate Search" fuzzy mode with FuzzyContext.withEditDistanceUpTo() with more than 2 "changes"?

Yoann Rodière (JIRA) jira at hibernate.atlassian.net
Thu Apr 23 06:46:17 EDT 2020


Yoann Rodière ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3A58fa1ced-171a-4c00-97e8-5d70d442cc4b ) *commented* on HSEARCH-3888 ( https://hibernate.atlassian.net/browse/HSEARCH-3888?atlOrigin=eyJpIjoiMzUyMTVmMjk4OGMyNDQ4OTkyNGU2ZjRjNTlhZDViZWEiLCJwIjoiaiJ9 )

Re: How to query in "Hibernate Search" fuzzy mode with FuzzyContext.withEditDistanceUpTo() with more than 2 "changes"? ( https://hibernate.atlassian.net/browse/HSEARCH-3888?atlOrigin=eyJpIjoiMzUyMTVmMjk4OGMyNDQ4OTkyNGU2ZjRjNTlhZDViZWEiLCJwIjoiaiJ9 )

I don't think we will add this to the DSL, as I doubt we can rely on the stability and overall quality of "sandbox" code. We actually explicitly exclude this artifact from our transitive dependencies.

That being said, if you want to rely on that code, you can still roll out your own "slow fuzzy query parser":

public final class SlowFuzzyQueryBuilder extends QueryBuilder {
   private final int minimumSimilarity;

   public FuzzyQueryBuilder(Analyzer analyzer, int minimumSimilarity) {
       super ( analyzer );
       this.minimumSimilarity = minimumSimilarity;
   }

   @Override
   protected Query newTermQuery(Term term) {
       return new SlowFuzzyQuery( term, minimumSimilarity );
   }
}

And get the custom analyzer from Hibernate Search:

Analyzer analyzer = fullTextSession.getSearchFactory().getAnalyzer( MyEntity.class );

(Or re-build the analyzer manually using org.apache.lucene.analysis.custom.CustomAnalyzer#builder() )

Then just do this to create the Lucene query:

SlowFuzzyQueryBuilder builder = new SlowFuzzyQueryBuilder( analyzer, 4 );
Query luceneQuery = builder.createBooleanQuery( "field_name" , "search terms" );

( https://hibernate.atlassian.net/browse/HSEARCH-3888#add-comment?atlOrigin=eyJpIjoiMzUyMTVmMjk4OGMyNDQ4OTkyNGU2ZjRjNTlhZDViZWEiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/HSEARCH-3888#add-comment?atlOrigin=eyJpIjoiMzUyMTVmMjk4OGMyNDQ4OTkyNGU2ZjRjNTlhZDViZWEiLCJwIjoiaiJ9 )

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.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8 ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100125- sha1:63ccdc5 )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20200423/68063ae8/attachment.html 


More information about the hibernate-issues mailing list