Sorting based on relevance score and field

First, I’d advise against this, because you will end up with all sorts of problems when you start considering paging (i.e. scrolling to the second page of results).

If you really want it, sure, you can do it. Just ask Hibernate Search to sort by creation date, limit the results to the top 100 hits, and project on both the entity and score so that you can sort the resulting list manually, with Collections.sort(List, Comparator).

But really, I’d advise you to clarify the requirements instead. Because that’s your real problem: the requirements do not make sense. You cannot sort on two (almost) unique values (creation date and score) simultaneously. Find out what the problems of your users are exactly. Maybe they just need a toggle in the UI between “sort by score” and “sort by creation date”. I’m afraid I cannot help you with that, it’s between you and your user :slight_smile:

1 Like