Use .and() syntax by default with .where(BiFunction) and .nested() predicate

Description

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 for and 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 the bool 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 the nested predicate: an or would be equivalent to not using the nested predicate to begin with, and advanced features of the bool 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" ) ) ))

Activity

Show:
Steve Ebersole
updated the WorkflowSeptember 14, 2023 at 5:02 PM
Expanded Workflow with pull request
Expanded Workflow
Yoann Rodière
changed the StatusJuly 3, 2023 at 11:28 AM
Resolved
Closed
Yoann Rodière
updated the RankAugust 29, 2022 at 12:06 PM
None
Ranked lower
Yoann Rodière
updated the RankAugust 29, 2022 at 12:06 PM
None
Ranked higher
Yoann Rodière
changed the StatusAugust 25, 2022 at 8:48 AM
Pull Request Sent
Resolved
Yoann Rodière
updated the Fix versionsAugust 25, 2022 at 8:48 AM
6.2-backlog
None
Yoann Rodière
updated the ResolutionAugust 25, 2022 at 8:48 AM
None
Fixed
Yoann Rodière
updated the Fix versionsAugust 25, 2022 at 8:48 AM
None
6.2.0.Alpha2
Automation for Jira
changed the StatusAugust 24, 2022 at 2:33 PM
In Progress
Pull Request Sent
Automation for Jira
updated the Pull RequestAugust 24, 2022 at 2:33 PM
None
https://github.com/hibernate/hibernate-search/pull/3209
Yoann Rodière
updated the SummaryAugust 24, 2022 at 2:33 PM
Use .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 PM
Open
In Progress
Yoann Rodière
updated the RankAugust 24, 2022 at 1:46 PM
None
Ranked lower
Yoann Rodière
updated the SprintAugust 24, 2022 at 1:46 PM
HSEARCH - 2022-17
HSEARCH - 2022-16
Yoann Rodière
changed the AssigneeAugust 24, 2022 at 12:12 PM
Unassigned
Yoann Rodière
Yoann Rodière
updated the SprintAugust 22, 2022 at 12:19 PM
None
HSEARCH - 2022-17
Yoann Rodière
updated the LinkAugust 17, 2022 at 1:45 PM
None
This issue follows up on HSEARCH-4601
Yoann Rodière
updated the RankAugust 17, 2022 at 1:45 PM
None
Ranked higher
Yoann Rodière
created the IssueAugust 17, 2022 at 1:45 PM
Fixed

Details

Assignee

Yoann Rodière

Reporter

Components

Sprint

Fix versions

Priority

Created August 17, 2022 at 1:45 PM
Updated July 3, 2023 at 11:28 AM
Resolved August 25, 2022 at 8:48 AM