我需要在多个实体上实现搜索(有效),我需要在搜索上实现分页(这不起作用)。
所以我做的是:
//creates the initial BooleanJunction from the first QueryBuilder
boolJunc = allQueryBuilders.get(0).bool();
for (QueryBuilder buildeForCurrentEntity: allQueryBuilders) {
boolJunc.should(buildeForCurrentEntity.keyword().onFields(searchedFields).matching(searchText).createQuery());
}
//after all BolleanJunctions are set, creates the final lucene query
org.apache.lucene.search.Query mainLuceneQuery = boolJunc.createQuery();
FullTextQuery jpaQuery = fullTextSession.createFullTextQuery(mainLuceneQuery, classes); //classes is array of all classes used to make those QueryBuilder's
//set pagination parameters
jpaQuery.setFirstResult(firstResultIndex);
jpaQuery.setMaxResults(maxNumberOfResults);
List<?> result = jpaQuery.list();
对于找到10个结果的搜索字词:
if i set my paging parameters as firstResultIndex = 0 and maxNumberOfResults = 50, then it works normally
if its firstResultIndex = 0 and maxNumberOfResults = 5 then it dosn't return anything
if its firstResultIndex = 4 and maxNumberOfResults = 50 then it ignores firstResultIndex and just returns all 10 results
我有什么遗失的吗?我如何在我的案例中进行分页工作?