目前将hibernate search升级到5;我已经进行了迁移所需的更改,但搜索仍然返回 null
“fullTextQuery.getResultList();”返回空。
public Tuple<List<LessonBO>, Long> fullTextSearch(String searchKey,
PageRequest pageRequest) {
FullTextEntityManager fullTextEntityManager = Search
.getFullTextEntityManager(entityManager);
//BooleanQuery booleanQuery = new BooleanQuery();
BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder();
if(!searchKey.isEmpty())
{
QueryBuilder b = fullTextEntityManager.getSearchFactory()
.buildQueryBuilder().forEntity( LessonBO.class ).get();
Query luceneQuery = b.phrase().onField(ServiceConstants.SEARCH_KEY).sentence(searchKey).createQuery();
booleanQuery.add(luceneQuery, Occur.MUST);
}
else
{
booleanQuery.add(new PrefixQuery(new Term(
ServiceConstants.SEARCH_KEY, searchKey)), Occur.MUST);
}
booleanQuery.add(new TermQuery(new Term(ServiceConstants.IS_ACTIVE,
ServiceConstants.TRUE_STRING)), Occur.MUST);
booleanQuery.add(new TermQuery(new Term(
ServiceConstants.MARK_FOR_DELETION,
ServiceConstants.TRUE_STRING)), Occur.MUST_NOT);
Query finalQuery = booleanQuery.build();
FullTextQuery fullTextQuery = fullTextEntityManager
.createFullTextQuery(finalQuery, LessonBO.class);
List<LessonBO> result = fullTextQuery.getResultList();
Long count = (long) fullTextQuery.getResultSize();
return new Tuple<List<LessonBO>, Long>(result, count);
没有错误或运行时异常
可以通过检查我的 LESSONBO 类来解决它,@field 注释中的值是错误的;需要纠正这个问题,问题就解决了。