2

I search all fields of objects with "Hibernate Search".

My Query:

 final org.apache.lucene.search.Query luceneQuery = qb
          .keyword().wildcard()
          .onFields( fields )
          .matching( valueToSearch )
          .createQuery();

 // wrap Lucene query in a javax.persistence.Query
 final javax.persistence.Query jpaQuery =
            fullTextEntityManager.createFullTextQuery( luceneQuery, Vorgang.class );

 // execute search
 final List<Vorgang> resultList = new ArrayList<>();

 ((List<Vorgang>) jpaQuery.getResultList()).stream().filter( t -> projektIds.contains( t.getProjektFk().getId() ) )
            .forEach( vorgang -> resultList.add( vorgang ) );

I want to know in which fields there was a match?

My Idea was:

final List<Vorgang> resultList = new ArrayList<>();
for ( final String field : fields )
{
   final org.apache.lucene.search.Query luceneQuery = qb
          .keyword().wildcard()
          .onField( field )
          .matching( valueToSearch )
          .createQuery();

   // wrap Lucene query in a javax.persistence.Query
   final javax.persistence.Query jpaQuery =
          fullTextEntityManager.createFullTextQuery( luceneQuery, Vorgang.class );

   // execute search
   ((List<Vorgang>) jpaQuery.getResultList()).stream().filter( t -> projektIds.contains( t.getProjektFk().getId() ) )
          .forEach( vorgang -> resultList.add( vorgang ) );
}

But the performance is not good. I want to know the fields, where there was a match.

MWiesner
  • 8,868
  • 11
  • 36
  • 70
espirio
  • 189
  • 14
  • luceneQuery will be change in every loop and you will get always the last luceneQuery only with only the last field and not all your fields. – Bilal BBB Jul 14 '15 at 15:06
  • In the loop, I run the query. But the processing takes too long. @BoutayaBilal – espirio Jul 15 '15 at 06:25

0 Answers0