title: How to make a Hibernate SearchSession return results with unique attributes?
body: <p>I am working on using the Hibernate SearchSession class in Java to perform a search against a database, the code I currently have to search a table looks something like this:</p>
  <pre><code>SearchSession searchSession = Search.session(entityManagerFactory.unwrap(SessionFactory.class).withOptions()
                  .tenantIdentifier(&quot;locations&quot;).openSession());
  
  SearchResult&lt;Location&gt; result = searchSession.search(Location.class)
                  .where(  f -&gt; f.bool()
                          .must( f.match()
                                  .field(&quot;locationName&quot;)
                                  .matching((phrase)).fuzzy())
                  ).fetch(page * limit, limit);
  </code></pre>
  <p>This search works and properly returns results from the database, but there is no uniqueness constraint on the locationName column and the database holds multiple records with the same value in locationName. As a result, when we try to display them on the UI of the application it looks like there are duplicate values, even though they're unique in the database.</p>
  <p>Is there a way to make a SearchSession only return a result if another result with an identical value (such as locationName) has not been returned before? Applying a uniqueness constraint to the database table isn't an option in this scenario, and we were hoping there's a way to handle filtering out duplicate values in the session over taking the results from the search and removing duplicate values separately.</p>