/** * Add a <a href="#filter">"filter" clause</a> based on an almost-built {@link SearchPredicate}. * * @param terminalContext The terminal context allowing to retrieve a {@link SearchPredicate}. * @return {@code this}, for method chaining. */ default BooleanJunctionPredicateContext filter(SearchPredicateTerminalContext terminalContext) { return filter( terminalContext.toPredicate() ); }
/** * Add a <a href="#filter">"filter" clause</a> based on an almost-built {@link SearchPredicate}. * * @param terminalContext The terminal context allowing to retrieve a {@link SearchPredicate}. * @return {@code this}, for method chaining. */ default BooleanJunctionPredicateContext filter(SearchPredicateTerminalContext terminalContext) { return filter( terminalContext.toPredicate() ); }
@Test public void filter_should() { StubMappingSearchTarget searchTarget = indexManager.createSearchTarget(); // A boolean predicate with filter + should clauses: // documents should match regardless of whether should clauses match. // Non-matching "should" clauses SearchQuery<DocumentReference> query = searchTarget.query() .asReference() .predicate( f -> f.bool() .filter( f.match().onField( "field1" ).matching( FIELD1_VALUE1 ) ) .should( f.match().onField( "field2" ).matching( FIELD2_VALUE2 ) ) .should( f.match().onField( "field3" ).matching( FIELD3_VALUE3 ) ) .toPredicate() ) .build(); assertThat( query ) .hasDocRefHitsAnyOrder( INDEX_NAME, DOCUMENT_1 ); // One matching and one non-matching "should" clause query = searchTarget.query() .asReference() .predicate( f -> f.bool() .filter( f.match().onField( "field1" ).matching( FIELD1_VALUE1 ) ) .should( f.match().onField( "field2" ).matching( FIELD2_VALUE1 ) ) .should( f.match().onField( "field3" ).matching( FIELD3_VALUE3 ) ) .toPredicate() ) .build(); assertThat( query ) .hasDocRefHitsAnyOrder( INDEX_NAME, DOCUMENT_1 ); }
.predicate( f -> f.bool() .must( f.match().onField( "string_analyzed" ).matching( "text" ) ) .filter( f.match().onField( "integer" ).matching( 1 ) ) .toPredicate()