lucene 搜索未返回任何结果

问题描述 投票:0回答:1

目前将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);

没有错误或运行时异常

java lucene hibernate-search
1个回答
0
投票

可以通过检查我的 LESSONBO 类来解决它,@field 注释中的值是错误的;需要纠正这个问题,问题就解决了。

© www.soinside.com 2019 - 2024. All rights reserved.