Combine JPA with HIbernate Search Lucene Query

Viewed 740

I can easily search my JPA entities with a fulltext query using Hibernate Search:

FullTextEntityManager fullTextEntityManager = 
        Search.getFullTextEntityManager(this.entityManager);

QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory()
        .buildQueryBuilder().forEntity(MyBean.class).get();

org.apache.lucene.search.Query luceneQuery = queryBuilder.keyword()
        .onFields("foo", "bar").matching("needle").createQuery();

javax.persistence.Query jpaQuery = fullTextEntityManager
        .createFullTextQuery(luceneQuery, MyBean.class);

List<MyBean> fulltextResult = jpaQuery.getResultList();

And that's great. But, how can I combine the luceneQuery in an existing JPA Query? For example as a predicate to use in a CriteriaBuilder.where() expression. I think this could be possibile since Hibernate Search retrieves the entity identifiers from its indexes and finally use them in a JPA query to get the result, but I don't know if there is any method beside getResultList() to get the query in other intermediate types, such as a javax.persistence.criteria.Predicate.

1 Answers
Related