-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-3319 Use single impl for field sort options
- Loading branch information
1 parent
4bf0e27
commit b8ad37a
Showing
4 changed files
with
201 additions
and
220 deletions.
There are no files selected for viewing
197 changes: 197 additions & 0 deletions
197
...org/hibernate/search/engine/search/sort/dsl/impl/AbstractFieldSortOptionsGenericStep.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,197 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.search.engine.search.sort.dsl.impl; | ||
|
||
import java.util.function.Function; | ||
|
||
import org.hibernate.search.engine.search.common.SortMode; | ||
import org.hibernate.search.engine.search.common.ValueModel; | ||
import org.hibernate.search.engine.search.predicate.SearchPredicate; | ||
import org.hibernate.search.engine.search.predicate.dsl.PredicateFinalStep; | ||
import org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory; | ||
import org.hibernate.search.engine.search.reference.sort.FieldSortFieldReference; | ||
import org.hibernate.search.engine.search.sort.SearchSort; | ||
import org.hibernate.search.engine.search.sort.dsl.FieldSortMissingValueBehaviorGenericStep; | ||
import org.hibernate.search.engine.search.sort.dsl.FieldSortMissingValueBehaviorStep; | ||
import org.hibernate.search.engine.search.sort.dsl.FieldSortOptionsGenericStep; | ||
import org.hibernate.search.engine.search.sort.dsl.FieldSortOptionsStep; | ||
import org.hibernate.search.engine.search.sort.dsl.SortOrder; | ||
import org.hibernate.search.engine.search.sort.dsl.spi.AbstractSortThenStep; | ||
import org.hibernate.search.engine.search.sort.dsl.spi.SearchSortDslContext; | ||
import org.hibernate.search.engine.search.sort.spi.FieldSortBuilder; | ||
import org.hibernate.search.engine.search.sort.spi.SearchSortIndexScope; | ||
import org.hibernate.search.engine.search.sort.spi.SortTypeKeys; | ||
|
||
public abstract class AbstractFieldSortOptionsGenericStep< | ||
SR, | ||
T, | ||
PDF extends SearchPredicateFactory<SR>, | ||
S extends AbstractFieldSortOptionsGenericStep<SR, T, PDF, S, N>, | ||
N extends FieldSortMissingValueBehaviorGenericStep<T, S>> | ||
extends AbstractSortThenStep<SR> | ||
implements | ||
FieldSortOptionsGenericStep<SR, | ||
T, | ||
S, | ||
N, | ||
PDF> { | ||
|
||
|
||
private final SearchSortDslContext<SR, ?, ? extends PDF> dslContext; | ||
protected final FieldSortBuilder builder; | ||
|
||
public AbstractFieldSortOptionsGenericStep(SearchSortDslContext<SR, ?, ? extends PDF> dslContext, | ||
String fieldPath) { | ||
super( dslContext ); | ||
this.dslContext = dslContext; | ||
this.builder = dslContext.scope().fieldQueryElement( fieldPath, SortTypeKeys.FIELD ); | ||
} | ||
|
||
public static < | ||
T, | ||
SR, | ||
SC extends SearchSortIndexScope<?>, | ||
PDF extends SearchPredicateFactory< | ||
SR>> FieldSortOptionsGenericStep<SR, T, ?, ?, ? extends SearchPredicateFactory<SR>> create( | ||
SearchSortDslContext<SR, SC, PDF> dslContext, | ||
FieldSortFieldReference<? super SR, T> fieldReference) { | ||
return new FieldReferenceFieldSortOptionsStep<>( dslContext, fieldReference ); | ||
} | ||
|
||
public static < | ||
PDF extends SearchPredicateFactory<SR>, | ||
SR, | ||
SC extends SearchSortIndexScope<?>> FieldSortOptionsStep<SR, ?, PDF> create( | ||
SearchSortDslContext<SR, SC, PDF> dslContext, String fieldPath) { | ||
return new StringFieldSortOptionsStep<>( dslContext, fieldPath ); | ||
} | ||
|
||
@Override | ||
public S order(SortOrder order) { | ||
builder.order( order ); | ||
return thisAsS(); | ||
} | ||
|
||
@Override | ||
public S mode(SortMode mode) { | ||
builder.mode( mode ); | ||
return thisAsS(); | ||
} | ||
|
||
@Override | ||
public N missing() { | ||
return thisAsN(); | ||
} | ||
|
||
@Override | ||
public S filter( | ||
Function<? super PDF, ? extends PredicateFinalStep> clauseContributor) { | ||
SearchPredicate predicate = clauseContributor.apply( dslContext.predicateFactory() ).toPredicate(); | ||
|
||
return filter( predicate ); | ||
} | ||
|
||
@Override | ||
public S filter(SearchPredicate searchPredicate) { | ||
builder.filter( searchPredicate ); | ||
return thisAsS(); | ||
} | ||
|
||
public S first() { | ||
builder.missingFirst(); | ||
return thisAsS(); | ||
} | ||
|
||
public S last() { | ||
builder.missingLast(); | ||
return thisAsS(); | ||
} | ||
|
||
public S highest() { | ||
builder.missingHighest(); | ||
return thisAsS(); | ||
} | ||
|
||
public S lowest() { | ||
builder.missingLowest(); | ||
return thisAsS(); | ||
} | ||
|
||
|
||
@Override | ||
protected SearchSort build() { | ||
return builder.build(); | ||
} | ||
|
||
protected abstract S thisAsS(); | ||
|
||
protected abstract N thisAsN(); | ||
|
||
|
||
private static class FieldReferenceFieldSortOptionsStep<SR, T, PDF extends SearchPredicateFactory<SR>> | ||
extends | ||
AbstractFieldSortOptionsGenericStep<SR, | ||
T, | ||
PDF, | ||
FieldReferenceFieldSortOptionsStep<SR, T, PDF>, | ||
FieldReferenceFieldSortOptionsStep<SR, T, PDF>> | ||
implements FieldSortMissingValueBehaviorGenericStep<T, FieldReferenceFieldSortOptionsStep<SR, T, PDF>> { | ||
private final ValueModel valueModel; | ||
|
||
public FieldReferenceFieldSortOptionsStep(SearchSortDslContext<SR, ?, ? extends PDF> dslContext, | ||
FieldSortFieldReference<? super SR, ?> fieldReference) { | ||
super( dslContext, fieldReference.absolutePath() ); | ||
this.valueModel = fieldReference.valueModel(); | ||
} | ||
|
||
@Override | ||
public FieldReferenceFieldSortOptionsStep<SR, T, PDF> use(T value) { | ||
builder.missingAs( value, valueModel ); | ||
return this; | ||
} | ||
|
||
@Override | ||
protected FieldReferenceFieldSortOptionsStep<SR, T, PDF> thisAsS() { | ||
return this; | ||
} | ||
|
||
@Override | ||
protected FieldReferenceFieldSortOptionsStep<SR, T, PDF> thisAsN() { | ||
return this; | ||
} | ||
} | ||
|
||
private static class StringFieldSortOptionsStep<SR, PDF extends SearchPredicateFactory<SR>> | ||
extends | ||
AbstractFieldSortOptionsGenericStep<SR, | ||
Object, | ||
PDF, | ||
StringFieldSortOptionsStep<SR, PDF>, | ||
FieldSortMissingValueBehaviorStep<StringFieldSortOptionsStep<SR, PDF>>> | ||
implements FieldSortOptionsStep<SR, StringFieldSortOptionsStep<SR, PDF>, PDF>, | ||
FieldSortMissingValueBehaviorStep<StringFieldSortOptionsStep<SR, PDF>> { | ||
|
||
public StringFieldSortOptionsStep(SearchSortDslContext<SR, ?, ? extends PDF> dslContext, | ||
String fieldPath) { | ||
super( dslContext, fieldPath ); | ||
} | ||
|
||
@Override | ||
public StringFieldSortOptionsStep<SR, PDF> use(Object value, ValueModel valueModel) { | ||
builder.missingAs( value, valueModel ); | ||
return this; | ||
} | ||
|
||
@Override | ||
protected StringFieldSortOptionsStep<SR, PDF> thisAsS() { | ||
return this; | ||
} | ||
|
||
@Override | ||
protected StringFieldSortOptionsStep<SR, PDF> thisAsN() { | ||
return this; | ||
} | ||
} | ||
} |
112 changes: 0 additions & 112 deletions
112
...ava/org/hibernate/search/engine/search/sort/dsl/impl/FieldSortOptionsGenericStepImpl.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.