title: Hibernate Search with Autocomplete and Fuzzy-Functionality
body: <p>I am trying to create a <strong>Hibernate Search representation of the StingUtils <a href="http://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html#containsIgnoreCase-java.lang.CharSequence-java.lang.CharSequence-" rel="nofollow noreferrer">containsIgnoreCase()</a> method together with fuzzy-search matching</strong>.</p>
  
  <p>Assume the user writes the letter "p", and they will get all matches that include the letter "p" (regardless whether the letter is located at the beginning, middle or end of the respective matches).</p>
  
  <p>As they form words such as "Peter", they should also receive fuzzy-matches as e.g."Petar", "Petaer" and "Peder" as well.</p>
  
  <p>I am using the custom query and index Analyzers provided in the great answer <a href="https://stackoverflow.com/a/46904863/11812518">here</a>, because I need <code>minGramSize</code> at 1 to allow for the autocomplete functionality, while at the same time I also expect multi-word user input separated by white spaces such as "EUR Account of Peter", which can be in different cases (lower or upper).</p>
  
  <p>So a user should be able to type "AND" and receive the above example as a match.</p>
  
  <p>Currently, I am using the following query:</p>
  
  <pre><code>  org.apache.lucene.search.Query fuzzySearchByName = qb.keyword().fuzzy()
                                                     .withEditDistanceUpTo(1).onField("name")
                                                     .matching(userInput).createQuery();
    booleanQuery.add(fuzzySearchByName, BooleanClause.Occur.MUST);
  </code></pre>
  
  <p><strong>However</strong>, exact match cases do not receive presendence in the search results:</p>
  
  <p>If we type "petar", we get the following results:</p>
  
  <ol>
  <li><em>Petarr</em> (non-exact match)</li>
  <li><em>Petaer</em> (non-exact match)</li>
  </ol>
  
  <p>... 4. <em>PETAR</em> (<strong>exact match</strong>)</p>
  
  <p>Same applies for user input of "peter", where the first result is "Petero", and the second is "Peter" (the second should be the first).</p>
  
  <p><strong>I also need</strong> to include only exact matches on multi-word queries - e.g. if I start writing "<em>Account for...</em>", I wish all the matched results to include the phrase "<em>Account for</em>" and eventually its fuzzy-related terms based on that phrase <em>(basically the same as the containsIgnoreCase() method showed earlier on, just trying to add fuzzy support)</em>. </p>
  
  <p>I guess however that this contradics with the <code>minGramSize</code> of 1 and the <code>WhitespaceTokenizerFactory</code>?</p>