[hibernate-issues] [JIRA] (HSEARCH-3889) Exception Predicate targets unexpected fields when use nested() in sort filter

Waldemar Kłaczyński (JIRA) jira at hibernate.atlassian.net
Tue Apr 14 14:57:17 EDT 2020


Waldemar Kłaczyński ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3A77e50cac-bda3-4af4-9bb3-6461f4d10eea ) *commented* on HSEARCH-3889 ( https://hibernate.atlassian.net/browse/HSEARCH-3889?atlOrigin=eyJpIjoiZWEzNzA4ZDdhZjhhNGU2YzgwZjY1NmM4NzI2YjUzMTAiLCJwIjoiaiJ9 )

Re: Exception Predicate targets unexpected fields when use nested() in sort filter ( https://hibernate.atlassian.net/browse/HSEARCH-3889?atlOrigin=eyJpIjoiZWEzNzA4ZDdhZjhhNGU2YzgwZjY1NmM4NzI2YjUzMTAiLCJwIjoiaiJ9 )

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 );

           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 = 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;   
}            
                

In this case it would not be possible. My patch makes it possible. Just when building a query, it decides by context how to build a filter.

( https://hibernate.atlassian.net/browse/HSEARCH-3889#add-comment?atlOrigin=eyJpIjoiZWEzNzA4ZDdhZjhhNGU2YzgwZjY1NmM4NzI2YjUzMTAiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/HSEARCH-3889#add-comment?atlOrigin=eyJpIjoiZWEzNzA4ZDdhZjhhNGU2YzgwZjY1NmM4NzI2YjUzMTAiLCJwIjoiaiJ9 )

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.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8 ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100124- sha1:185bad4 )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20200414/0c99f85e/attachment.html 


More information about the hibernate-issues mailing list