-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-4676 Use .and() syntax by default with the nested() predicate
- Loading branch information
Showing
22 changed files
with
209 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...ava/org/hibernate/search/engine/search/predicate/dsl/NestedPredicateClausesCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.engine.search.predicate.dsl; | ||
|
||
/** | ||
* An object where the <a href="SimpleBooleanOperatorPredicateClausesCollector.html#clauses">clauses</a> | ||
* of a {@link SearchPredicateFactory#nested(String) nested predicate} can be set. | ||
* <p> | ||
* The resulting nested predicate must match <em>all</em> inner clauses, | ||
* similarly to an {@link SearchPredicateFactory#and() "and" predicate}. | ||
*/ | ||
public interface NestedPredicateClausesCollector<S extends NestedPredicateClausesCollector<?>> | ||
extends SimpleBooleanOperatorPredicateClausesCollector<S> { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
...ava/org/hibernate/search/engine/search/predicate/dsl/NestedPredicateOptionsCollector.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...h/engine/search/predicate/dsl/impl/AbstractSimpleBooleanOperatorPredicateClausesStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.engine.search.predicate.dsl.impl; | ||
|
||
import java.util.function.BiConsumer; | ||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
|
||
import org.hibernate.search.engine.search.predicate.SearchPredicate; | ||
import org.hibernate.search.engine.search.predicate.dsl.BooleanPredicateOptionsCollector; | ||
import org.hibernate.search.engine.search.predicate.dsl.GenericSimpleBooleanOperatorPredicateClausesStep; | ||
import org.hibernate.search.engine.search.predicate.dsl.PredicateFinalStep; | ||
import org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory; | ||
import org.hibernate.search.engine.search.predicate.dsl.SimpleBooleanOperatorPredicateClausesCollector; | ||
import org.hibernate.search.engine.search.predicate.dsl.SimpleBooleanOperatorPredicateClausesStep; | ||
import org.hibernate.search.engine.search.predicate.dsl.spi.AbstractPredicateFinalStep; | ||
import org.hibernate.search.engine.search.predicate.dsl.spi.SearchPredicateDslContext; | ||
import org.hibernate.search.engine.search.predicate.spi.BooleanPredicateBuilder; | ||
|
||
public abstract class AbstractSimpleBooleanOperatorPredicateClausesStep<S extends C, C extends SimpleBooleanOperatorPredicateClausesCollector<?>> | ||
extends AbstractPredicateFinalStep | ||
implements GenericSimpleBooleanOperatorPredicateClausesStep<S, C> { | ||
|
||
public enum SimpleBooleanPredicateOperator | ||
implements BiConsumer<BooleanPredicateBuilder, SearchPredicate> { | ||
AND { | ||
@Override | ||
public void accept(BooleanPredicateBuilder builder, | ||
SearchPredicate searchPredicate) { | ||
builder.must( searchPredicate ); | ||
} | ||
}, | ||
OR { | ||
@Override | ||
public void accept(BooleanPredicateBuilder builder, | ||
SearchPredicate searchPredicate) { | ||
builder.should( searchPredicate ); | ||
} | ||
} | ||
} | ||
|
||
private final SimpleBooleanPredicateOperator operator; | ||
|
||
private final BooleanPredicateBuilder builder; | ||
|
||
private final SearchPredicateFactory factory; | ||
|
||
AbstractSimpleBooleanOperatorPredicateClausesStep(SimpleBooleanPredicateOperator operator, | ||
SearchPredicateDslContext<?> dslContext, | ||
SearchPredicateFactory factory) { | ||
super( dslContext ); | ||
this.operator = operator; | ||
this.builder = dslContext.scope().predicateBuilders().bool(); | ||
this.factory = factory; | ||
} | ||
|
||
protected abstract S self(); | ||
|
||
@Override | ||
public S add(SearchPredicate searchPredicate) { | ||
operator.accept( builder, searchPredicate ); | ||
return self(); | ||
} | ||
|
||
@Override | ||
public S add(Function<? super SearchPredicateFactory, ? extends PredicateFinalStep> clauseContributor) { | ||
return add( clauseContributor.apply( factory ) ); | ||
} | ||
|
||
public S boost(float boost) { | ||
builder.boost( boost ); | ||
return self(); | ||
} | ||
|
||
public S constantScore() { | ||
builder.constantScore(); | ||
return self(); | ||
} | ||
|
||
@Override | ||
public S with(Consumer<? super C> contributor) { | ||
contributor.accept( self() ); | ||
return self(); | ||
} | ||
|
||
@Override | ||
protected SearchPredicate build() { | ||
return builder.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.