Does anyone have a clue why Hibernate Search FullTextQuery (FullTextEntityManager) getResultSize() never matches the getResultList().size()?
I am not passing anything to setFirstResult or setMaxResult.
For example, I do a query on one field for the word "truck" the resultSize says 50,345, but the ResultList.size() is 865. Does anyone know of any reason these would be so far off? I have cleared the Lucene indexes and rebuilt them, but it still doesn't work. I am baffled.
QueryBuilder qb = this.inventoryRepo.getSearchManager()
.getSearchFactory().buildQueryBuilder()
.forEntity(Inventory.class).get();
BooleanJunction<?> junction = this.builder.createAlgorithm(
searchRequest, qb);
org.apache.lucene.search.Query luceneQueryluceneQuery = junction.createQuery();
}
searchResult.setQuery(luceneQuery.toString());
FullTextQuery jpaQuery = this.inventoryRepo.getSearchManager()
.createFullTextQuery(luceneQuery, Inventory.class);
jpaQuery.limitExecutionTimeTo(20000,
TimeUnit.MILLISECONDS);
List<Inventory> results = jpaQuery.getResultList();
log.debug("Total Search Result Size: " + jpaQuery.getResultSize());
searchResult.setTotalSize(jpaQuery.getResultSize());
Referring to the FullTextQuery documentation and the getResultSize method section:
int getResultSize()
Returns: the number of hits for this search.
Caution: The number of results might be slightly different from list().size() because list() if the index is not in sync with the database at the time of query.
The results will be slightly different, but I think it's not the case here because there's a huge difference which is logically caused by limitExecutionTimeTo call here which is preventing the query to fetch all the results and you can see it in the documentation, so the difference is caused by this code:
jpaQuery.limitExecutionTimeTo(20000,
TimeUnit.MILLISECONDS);
Which will execute the query only for 20 seconds and return only partial results, that's why you are getting less results because the query had not finished fetching all the results.
You can use hasPartialResults() to test if all the results was fetched or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With