Use JPA with hibernate search Lucene query

I can easily search my JPA entity full-text 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();

That's great However, how can Lucene query be combined in an existing JPA query? For example, as in criteriabuilder The predicate used in the where () expression I think this is possible because hibernate search retrieves entity identifiers from the index and finally uses them in JPA queries to get results, but I don't know whether there is any method next to getresultlist () that can get query intermediate types in other methods, such as javax persistence. criteria. Predicate.

Solution

You should be able to use projects to retrieve only identifiers from Lucene, and then use them to pass in, for example, your JPA query

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>