I know you can do that. But then you need to submit the filter for sorting and searching separately. The idea is to use the same filtering query and not worry about how to use it when sorting and searching differently. This is important for very complex filters, where it is necessary to use the nesting predicate once and in other cases it should not be used. PR should be able to adapt himself. Do not throw exceptions, require some complex actions.
PermissionQuery allowQuery = new PermissionQuery("prices.permissions", operation, user, true);
filter = createComplexFilter(...);
sort.add(sorter.field("prices.bruttoPrice_sort")
.asc()
.mode(SortMode.MIN)
.filter(filter));
SearchQuery<Assortment> query = session.search(scope)
.where((f) -> f.bool().must(select)
.filter(filter)
.sort(sort.toSort())
.toQuery();
.....
public static SearchPredicate createComplexFilter(...) {
PermissionQuery allowQuery = new PermissionQuery("prices.prmissions", "share", user, true);
PermissionQuery dannyQuery = new PermissionQuery("prices.prmissions", "share", user, false);
BooleanQuery query = new BooleanQuery.Builder()
.add(allowQuery, BooleanClause.Occur.MUST)
.add(dannyQuery, BooleanClause.Occur.MUST_NOT)
.build();
SearchPredicate permfilter = predicate
.nested().objectField("prices")
.nest(predicate
.extension(LuceneExtension.get())
.fromLuceneQuery(query))
.toPredicate();
SearchPredicate activefilter = ctx.predicate()
.match().field("prices.active")
.matching(true)
.toPredicate();
SearchPredicate filter = predicate.bool()
.must(activefilter)
.must(permfilter)
.toPredicate();
return filter;
}