title: Search in database for text (with Hibernate Search)
body: <p>I want to implement a search query that searches the database for a text.
  But I always get back an empty result, although the text appears in a DataSet.</p>
  
  <pre><code>  public List&lt;Object&gt; getSearchVorgangResult( final int mandantId, final String searchValue, final List&lt;Integer&gt; projektIds,
                                                final Field field,
                                                final boolean isGrossKlein )
    {
      final EntityManager em = getEntityManager();
  
      final FullTextEntityManager fullTextEntityManager =
          org.hibernate.search.jpa.Search.getFullTextEntityManager( em );
  
      // create native Lucene query unsing the query DSL
      // alternatively you can write the Lucene query using the Lucene query parser
      // or the Lucene programmatic API. The Hibernate Search DSL is recommended though
      final QueryBuilder qb = fullTextEntityManager.getSearchFactory()
          .buildQueryBuilder().forEntity( Vorgang.class ).get();
  
      final List&lt;String&gt; fieldNames = new ArrayList&lt;&gt;();
      System.out.println( field );
      if ( field == null )
      {
        for ( final Field classField : Vorgang.class.getDeclaredFields() )
        {
          fieldNames.add( classField.getName() );
        }
      }
      else
      {
        fieldNames.add( field.getName() );
      }
      String[] fields = new String[fieldNames.size()];
      fields = fieldNames.toArray( fields );
  
      final org.apache.lucene.search.Query luceneQuery = qb
          .keyword()
          .onFields( fields ).ignoreAnalyzer()
          .matching( searchValue )
          .createQuery();
  
      // wrap Lucene query in a javax.persistence.Query
      final javax.persistence.Query jpaQuery =
          fullTextEntityManager.createFullTextQuery( luceneQuery, Vorgang.class );
  
      // execute search
      return jpaQuery.getResultList();
    }
  </code></pre>
  
  <p>I have no idea why the result is always empty.</p>