Hi Everyone,
I am a beginner to lucene hibernate search. I am using hibernate search in my project to fetch the results from lucene indexes. What exactly issue I am facing is if I am searching for 50 records from lucene using query.setmaxResults(50) then l am getting 50 records and then applying my own scoring logic to those records apart from lucene scoring.
Whenever I am trying to increase the max results then I am getting extra results which should be visible in the first 50 records as per good match.
Please suggest me how can I disable lucene internal scoring and ranking also if will it impact my search results ?
Let me know if any additional information required from my side.
You cannot really sort “after the fact” if you’re using pagination. It leads to the problems you’re mentioning, and there’s no way around it. To work correctly with pagination, the sort must occur before paginating, which means it has to be performed by Lucene.
Now, what are your options?
You can sort by a specific field (by name, id, …). See here for Hibernate Search 5.x and here for Hibernate Search 6.x.
If you really want some sort of scoring, you’re stuck with Lucene’s scoring, but it can be tuned. The idea is to tune the query to change the score depending on matched predicates. See an explanation here. The explanation is for Hibernate Search 6.x only, but you can achieve similar results with Hibernate Search 5.x.
If you already have very strong knowledge of Lucene, you can also use a custom Similarity
: see here for 5.x, here for 6.x. I won’t help you there though: it’s pretty advanced stuff, so either you already know enough, or you shouldn’t even try.
1 Like