| You are mixing two approaches here, which may be the reason you're getting this exception. *Step objects, like the one you're storing in the "select" and "sort" variables, are not meant to be passed around at all. For that, you should call toPredicate()/toSort() etc. and then you will get a SearchPredicate/SearchSort/etc. that you can safely pass around and even re-use. Try this:
if (searchFullText != null) { select = scope.predicate().simpleQueryString() .field("shoppingName") .matching(searchFullText) .defaultOperator(BooleanOperator.AND).toPredicate(); }
else { select = scope.predicate().matchAll().toPredicate(); }
SearchQuery<Assortment> query = session.search(scope)
.where(select)
.sort(sort).toQuery();
or this:
SearchQuery<Assortment> query = session.search(scope)
.where(f -> {
if (searchFullText != null) { return f.simpleQueryString() .field("shoppingName") .matching(searchFullText) .defaultOperator(BooleanOperator.AND); }
else { return f.matchAll(); }
} )
.sort( f -> ... ).toQuery();
|