Yoann Rodière (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *commented* on HSEARCH-3889 (
https://hibernate.atlassian.net/browse/HSEARCH-3889?atlOrigin=eyJpIjoiYWU...
)
Re: Exception Predicate targets unexpected fields when use nested() in sort filter (
https://hibernate.atlassian.net/browse/HSEARCH-3889?atlOrigin=eyJpIjoiYWU...
)
This exception is on purpose. The predicate passed as sort filter should only be referring
to fields in the same nested document as the sort field, or a more deeply nested document;
otherwise the filter just cannot work. See HSEARCH-3885 (
https://hibernate.atlassian.net/browse/HSEARCH-3885 ) Resolved.
This code would work just fine:
PermissionQuery allowQuery = new PermissionQuery(
"prices.permissions" , operation, user, true );
PermissionQuery dannyQuery = new PermissionQuery(
"prices.permissions" , operation, user, false );
BooleanQuery query = new BooleanQuery.Builder()
.add(allowQuery, BooleanClause.Occur.MUST)
.add(dannyQuery, BooleanClause.Occur.MUST_NOT)
.build();
filter = predicate.extension(LuceneExtension.get()).fromLuceneQuery(query)
.toPredicate();
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(f.nested().objectField( "prices" ).nest(filter))
.sort(sort.toSort())
.toQuery();
Note that's a bit complicated, but only because of the native query. Without it, we
wouldn't have to use an explicit nested predicate to begin with.
As to your patch, I'm a bit concerned it will allow "nesting" multiple
nested predicates on the same object field, which I do not think will work correctly.
Something like this:
SearchQuery<Assortment> query = session.search(scope)
.where(f -> f.nested().objectField( "prices" ).nest(
f.nested().objectField( "prices"
).nest(
f.nested().objectField(
"prices" ).nest(
f.match().field( "prices.thing" ).matching( "foo" )
)
)
))
.toQuery();
I will close this ticket for now, as I provided a solution to your problem. If that's
not an acceptable solution, please feel free to re-open this ticket.
(
https://hibernate.atlassian.net/browse/HSEARCH-3889#add-comment?atlOrigin...
) Add Comment (
https://hibernate.atlassian.net/browse/HSEARCH-3889#add-comment?atlOrigin...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100124- sha1:185bad4 )