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.
public List<Object> getSearchVorgangResult( final int mandantId, final String searchValue, final List<Integer> 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<String> fieldNames = new ArrayList<>();
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();
}
I have no idea why the result is always empty.