/** * Set the inner predicate to an almost-built {@link SearchPredicate}. * <p> * Matching documents are those for which at least one element of the nested object field * matches the inner predicate. * * @param terminalContext The terminal context allowing to retrieve a {@link SearchPredicate}. * @return A context allowing to get the resulting predicate. */ default SearchPredicateTerminalContext nest(SearchPredicateTerminalContext terminalContext) { return nest( terminalContext.toPredicate() ); }
/** * Set the inner predicate to an almost-built {@link SearchPredicate}. * <p> * Matching documents are those for which at least one element of the nested object field * matches the inner predicate. * * @param terminalContext The terminal context allowing to retrieve a {@link SearchPredicate}. * @return A context allowing to get the resulting predicate. */ default SearchPredicateTerminalContext nest(SearchPredicateTerminalContext terminalContext) { return nest( terminalContext.toPredicate() ); }
@Override public List<Book> searchByMedium(String terms, BookMedium medium, int offset, int limit) { FullTextQuery<Book> query = entityManager.search( Book.class ).query() .asEntity() .predicate( f -> f.bool( b -> { if ( terms != null && !terms.isEmpty() ) { b.must( f.match() .onField( "title" ).boostedTo( 2.0f ) .orField( "summary" ) .matching( terms ) ); } b.must( f.nested().onObjectField( "copies" ) .nest( f.match().onField( "copies.medium" ).matching( medium ) ) ); } ) ) .sort( b -> b.byField( "title_sort" ) ) .build(); query.setFirstResult( offset ); query.setMaxResults( limit ); return query.getResultList(); }
@Override public List<Book> searchByMedium(String terms, BookMedium medium, int offset, int limit) { FullTextSearchTarget<Book> target = entityManager.search( Book.class ); BooleanJunctionPredicateContext booleanBuilder = target.predicate().bool(); if ( terms != null && !terms.isEmpty() ) { booleanBuilder.must( target.predicate().match() .onField( "title" ).boostedTo( 2.0f ) .orField( "summary" ) .matching( terms ) ); } booleanBuilder.must( target.predicate().nested().onObjectField( "copies" ) .nest( target.predicate().match().onField( "copies.medium" ).matching( medium ) ) ); FullTextQuery<Book> query = entityManager.search( Book.class ).query() .asEntity() .predicate( booleanBuilder.toPredicate() ) .sort( target.sort().byField( "title_sort" ).toSort() ) .build(); query.setFirstResult( offset ); query.setMaxResults( limit ); return query.getResultList(); }
.asReference() .predicate( f -> f.nested().onObjectField( "nestedObject" ) .nest( f.bool() .must( f.match().onField( "nestedObject.string" ).matching( "text 1_2" ) ) .must( f.match().onField( "nestedObject.integer" ).matching( 101 ) ) .asReference() .predicate( f -> f.nested().onObjectField( "nestedObject" ) .nest( f.bool() .must( f.match().onField( "nestedObject.string" ).matching( "text 1_1" ) ) .must( f.match().onField( "nestedObject.integer" ).matching( 101 ) )
.asReference() .predicate( f -> f.nested().onObjectField( "nestedObject" ) .nest( f.bool() .must( f.match().onField( "nestedObject.string" ).matching( MATCHING_STRING ) ) .must( f.match().onField( "nestedObject.string_analyzed" ).matching( MATCHING_STRING_ANALYZED ) )
.asReference() .predicate( f -> f.nested().onObjectField( "nestedObject" ) .nest( f.bool() .must( f.range().onField( "nestedObject.string" ) .from( MATCHING_STRING ).to( MATCHING_STRING )