The similar question was asked but not solved. Here is my code
FullTextSession fullTextSession = Search.getFullTextSession(currentSession());
QueryBuilder qb = fullTextSession.getSearchFactory()
.buildQueryBuilder().forEntity(Design.class).get();
org.apache.lucene.search.Query query = qb
.keyword()
.onFields("designName", "description")
.matching(text)
.createQuery();
org.hibernate.search.FullTextQuery hibQuery =
fullTextSession.createFullTextQuery(query, Design.class);
hibQuery.setFirstResult(start);
hibQuery.setMaxResults(num);
@SuppressWarnings("unchecked")
List<Design> designList = hibQuery.list();
for (Design design : designList) {
Hibernate.initialize(design.getDesignImages());
}
return designList;
Why hibQuery.list().size() is smaller than hibQuery.getResultSize(). Because of this difference, the .setMaxResults() does not work properly.
A reason for this can be that the index and database are not in sync at the time of querying.
getResultSize
is based on the Lucene query result size whereaslist.size()
is the actual size of materialized (loaded) entities.