Previously in Hibernate Search 5 I had sort defined as constant. Later when issuing a search, it was applied to a query: fullTextQuery.setSort(sort);
private static final boolean REVERSE = true;
private static final boolean NATURAL = false;
private static final Sort ARTICLE_DEFAULT_SORT =
new Sort(
new SortField("importance_numeric", SortField.Type.INT, REVERSE),
new SortField("completeness_level", SortField.Type.INT, REVERSE),
SortField.FIELD_SCORE
new SortField("sortableTitle", SortField.Type.STRING, NATURAL),
new SortField("sortableManufacturer", SortField.Type.STRING, NATURAL)
);
Now with Hibernate Search 6 I’m trying to do any kind of sort, but I have to admit - I’m lost.
The only thing I managed to write is:
org.hibernate.search.engine.search.query.SearchResult<T> searchResult =
searchSession
.search(clazz)
.where(searchPredicate)
.sort(f ->
f.field("sortableTitle")
.then().field("sortableManufacturer")
)
.fetch(offset, limit);
Where clazz
is a parameter declared as Class<T> clazz
to have generic search service.
Is there any chance to create some sort supplier that will create sort depending on clazz
and other additional parameters (for example one type of sort for homepage and other type of sort for search results).
Interfaces and classes SearchSort
, SearchSortFactory
, LuceneUserProvidedLuceneSortFieldSort
, LuceneSearchIndexScope
, LuceneUserProvidedLuceneSortSort
are not well documented and there are no examples and the only thing I could do is to try to dig deep into code, but it will take too much time.
I would like to manage it as more in Hibernate Search 6 style as possible which means I want to avoid helpers that would use old code (LuceneSearchSortBuilderFactory.fromLuceneSort( OLD_SORT_HERE )
).
Please help!