Use .and() syntax by default with .where(BiFunction) and .nested() predicate
Activity
Show:
Steve Ebersole
updated the WorkflowSeptember 14, 2023 at 5:02 PMExpanded Workflow with pull request
Expanded Workflow
Yoann Rodière
changed the StatusJuly 3, 2023 at 11:28 AMResolved
Closed
Yoann Rodière
updated the RankAugust 29, 2022 at 12:06 PMNone
Ranked lower
Yoann Rodière
updated the RankAugust 29, 2022 at 12:06 PMNone
Ranked higher
Yoann Rodière
changed the StatusAugust 25, 2022 at 8:48 AMPull Request Sent
Resolved
Yoann Rodière
updated the Fix versionsAugust 25, 2022 at 8:48 AM6.2-backlog
None
Yoann Rodière
updated the ResolutionAugust 25, 2022 at 8:48 AMNone
Fixed
Yoann Rodière
updated the Fix versionsAugust 25, 2022 at 8:48 AMNone
6.2.0.Alpha2
Automation for Jira
changed the StatusAugust 24, 2022 at 2:33 PMIn Progress
Pull Request Sent
Automation for Jira
updated the Pull RequestAugust 24, 2022 at 2:33 PMNone
https://github.com/hibernate/hibernate-search/pull/3209
Yoann Rodière
updated the SummaryAugust 24, 2022 at 2:33 PMUse .and() syntax by default with .where(BiFunction) and .nested() predicate?
Use .and() syntax by default with .where(BiFunction) and .nested() predicate
Yoann Rodière
changed the StatusAugust 24, 2022 at 1:46 PMOpen
In Progress
Yoann Rodière
updated the RankAugust 24, 2022 at 1:46 PMNone
Ranked lower
Yoann Rodière
updated the SprintAugust 24, 2022 at 1:46 PMHSEARCH - 2022-17
HSEARCH - 2022-16
Yoann Rodière
changed the AssigneeAugust 24, 2022 at 12:12 PMUnassigned
Yoann Rodière
Yoann Rodière
updated the SprintAugust 22, 2022 at 12:19 PMNone
HSEARCH - 2022-17
Yoann Rodière
updated the LinkAugust 17, 2022 at 1:45 PMNone
This issue follows up on HSEARCH-4601
Yoann Rodière
updated the RankAugust 17, 2022 at 1:45 PMNone
Ranked higher
Yoann Rodière
created the IssueAugust 17, 2022 at 1:45 PMFixed
Details
Assignee
Reporter
Yoann Rodière
Yoann RodièreComponents
Sprint
None
Fix versions
Priority
Major
Created August 17, 2022 at 1:45 PM
Updated July 3, 2023 at 11:28 AM
Resolved August 25, 2022 at 8:48 AM
Follows up on HSEARCH-4601: Syntactic sugar for OR/AND predicatesClosed
The .where(BiFunction) syntax uses a
bool
predicate:MySearchParameters searchParameters = getSearchParameters(); List<Book> hits = searchSession.search( Book.class ) .where( (f, b) -> { b.must( f.matchAll() ); if ( searchParameters.getGenreFilter() != null ) { b.must( f.match().field( "genre" ) .matching( searchParameters.getGenreFilter() ) ); } if ( searchParameters.getFullTextFilter() != null ) { b.must( f.match().fields( "title", "description" ) .matching( searchParameters.getFullTextFilter() ) ); } if ( searchParameters.getPageCountMaxFilter() != null ) { b.must( f.range().field( "pageCount" ) .atMost( searchParameters.getPageCountMaxFilter() ) ); } } ) .fetchHits( 20 );
But most of the time, I expect people will want an
and
, and we just introduced a simpler syntax forand
predicates ( https://hibernate.atlassian.net/browse/HSEARCH-4601 ).It would probably be better to use the
and
syntax there:MySearchParameters searchParameters = getSearchParameters(); List<Book> hits = searchSession.search( Book.class ) .where( (f, b) -> { b.add( f.matchAll() ); if ( searchParameters.getGenreFilter() != null ) { b.add( f.match().field( "genre" ) .matching( searchParameters.getGenreFilter() ) ); } if ( searchParameters.getFullTextFilter() != null ) { b.add( f.match().fields( "title", "description" ) .matching( searchParameters.getFullTextFilter() ) ); } if ( searchParameters.getPageCountMaxFilter() != null ) { b.add( f.range().field( "pageCount" ) .atMost( searchParameters.getPageCountMaxFilter() ) ); } } ) .fetchHits( 20 );
Similarly, the current syntax for adding clauses to a
nested
predicate is that of thebool
predicate:.where( f -> f.and() .add( f.range().field( "summary.total" ) .atLeast( new BigDecimal( "20.0" ) ) ) .add( f.range().field( "summary.shipping" ) .atMost( new BigDecimal( "10.0" ) ) ) .add( f.nested( "lineItems" ) .must( f.range().field( "lineItems.amount" ) .between( new BigDecimal( "7.0" ), new BigDecimal( "9.0" ) ) ) .must( f.match().field( "lineItems.category" ) .matching( "BOOK" ) ) ))
However, most of the time one will simply want an
and
inside thenested
predicate: anor
would be equivalent to not using the nested predicate to begin with, and advanced features of thebool
predicate are… well, for advanced users.We should probably use an (implicit)
and
there as well:.where( f -> f.and() .add( f.range().field( "summary.total" ) .atLeast( new BigDecimal( "20.0" ) ) ) .add( f.range().field( "summary.shipping" ) .atMost( new BigDecimal( "10.0" ) ) ) .add( f.nested( "lineItems" ) .add( f.range().field( "lineItems.amount" ) .between( new BigDecimal( "7.0" ), new BigDecimal( "9.0" ) ) ) .add( f.match().field( "lineItems.category" ) .matching( "BOOK" ) ) ))