Skip to content

Commit 85a855d

Browse files
committed
HSEARCH-5300 Introduce "generic" Any*Reference mostly for simple cases/tests
1 parent 3433247 commit 85a855d

File tree

5 files changed

+183
-0
lines changed

5 files changed

+183
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.search.engine.search.reference;
6+
7+
import org.hibernate.search.engine.search.common.ValueModel;
8+
import org.hibernate.search.engine.search.reference.aggregation.AnyAggregationReference;
9+
import org.hibernate.search.engine.search.reference.predicate.AnyPredicateReference;
10+
import org.hibernate.search.engine.search.reference.projection.AnyProjectionReference;
11+
import org.hibernate.search.engine.search.reference.sort.AnySortReference;
12+
import org.hibernate.search.util.common.annotation.Incubating;
13+
14+
/**
15+
* A set of util methods to create generic field references, mostly for testing purposes or trivial cases where just a few references are required.
16+
* <p>
17+
* While it is expected that the generated Hibernate Search static metamodel will contain
18+
* more precise field references that would match the actual field capabilities, these generic references can
19+
* be used by the users if they decide to opt-out of using the generated static metamodel
20+
* and would just want to create a few simple pre-defined references.
21+
*/
22+
@Incubating
23+
public interface FieldReferences {
24+
25+
static <SR, T> AnySortReference<SR, T> anySortReference(String absolutePath, Class<SR> scopeRootType, ValueModel valueModel,
26+
Class<T> sortType) {
27+
return new AnySortReference<>( absolutePath, scopeRootType, valueModel, sortType );
28+
}
29+
30+
static <SR, T> AnyProjectionReference<SR, T> anyProjectionReference(String absolutePath, Class<SR> scopeRootType,
31+
ValueModel valueModel, Class<T> projectionType) {
32+
return new AnyProjectionReference<>( absolutePath, scopeRootType, valueModel, projectionType );
33+
}
34+
35+
static <SR, T> AnyPredicateReference<SR, T> anyPredicateReference(String absolutePath, Class<SR> scopeRootType,
36+
ValueModel valueModel, Class<T> predicateType) {
37+
return new AnyPredicateReference<>( absolutePath, scopeRootType, valueModel, predicateType );
38+
}
39+
40+
static <SR, T> AnyAggregationReference<SR, T> anyAggregationReference(String absolutePath, Class<SR> scopeRootType,
41+
ValueModel valueModel, Class<T> aggregationType) {
42+
return new AnyAggregationReference<>( absolutePath, scopeRootType, valueModel, aggregationType );
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.search.engine.search.reference.aggregation;
6+
7+
import org.hibernate.search.engine.search.common.ValueModel;
8+
import org.hibernate.search.util.common.annotation.Incubating;
9+
10+
/**
11+
* A generic aggregated-field reference that can be manually created and passed to any aggregation-DSL methods that require a field reference.
12+
* <p>
13+
* While it is expected that the generated Hibernate Search static metamodel will contain
14+
* more precise field references that would match the actual field capabilities, this generic reference can
15+
* be used by the users if they decide to opt-out of using the generated static metamodel
16+
* and would just want to create a few simple pre-defined references.
17+
*
18+
* @param absolutePath The absolut field path.
19+
* @param scopeRootType The class representing the scope root type.
20+
* @param valueModel The model of aggregated values. See {@link ValueModel}.
21+
* @param aggregationType The class representing the type of the aggregated field, as per {@code valueModel}.
22+
* @param <SR> Scope root type
23+
* @param <T> The type of the aggregated field.
24+
*/
25+
@Incubating
26+
public record AnyAggregationReference<SR, T>( String absolutePath, Class<SR> scopeRootType, ValueModel valueModel,
27+
Class<T> aggregationType)
28+
implements AvgAggregationFieldReference<SR, T>,
29+
CountAggregationFieldReference<SR>,
30+
CountDistinctAggregationFieldReference<SR>,
31+
MaxAggregationFieldReference<SR, T>,
32+
MinAggregationFieldReference<SR, T>,
33+
RangeAggregationFieldReference<SR, T>,
34+
SumAggregationFieldReference<SR, T>,
35+
TermsAggregationFieldReference<SR, T> {
36+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.search.engine.search.reference.predicate;
6+
7+
import org.hibernate.search.engine.search.common.ValueModel;
8+
import org.hibernate.search.util.common.annotation.Incubating;
9+
10+
/**
11+
* A generic predicate-field reference that can be manually created and passed to any predicate-DSL methods that require a field reference.
12+
* <p>
13+
* While it is expected that the generated Hibernate Search static metamodel will contain
14+
* more precise field references that would match the actual field capabilities, this generic reference can
15+
* be used by the users if they decide to opt-out of using the generated static metamodel
16+
* and would just want to create a few simple pre-defined references.
17+
*
18+
* @param absolutePath The absolut field path.
19+
* @param scopeRootType The class representing the scope root type.
20+
* @param valueModel The model of values used in the predicate. See {@link ValueModel}.
21+
* @param predicateType The class representing the type of the field used in a predicate, as per {@code valueModel}.
22+
* @param <SR> Scope root type
23+
* @param <T> The type of the field used in a predicate.
24+
*/
25+
@Incubating
26+
public record AnyPredicateReference<SR, T>( String absolutePath, Class<SR> scopeRootType, ValueModel valueModel,
27+
Class<T> predicateType)
28+
implements ExistsPredicateFieldReference<SR>,
29+
KnnPredicateFieldReference<SR, T>,
30+
MatchPredicateFieldReference<SR, T>,
31+
NestedPredicateFieldReference<SR>,
32+
PhrasePredicateFieldReference<SR, T>,
33+
PrefixPredicateFieldReference<SR>,
34+
QueryStringPredicateFieldReference<SR, T>,
35+
RangePredicateFieldReference<SR, T>,
36+
RegexpPredicateFieldReference<SR>,
37+
SimpleQueryStringPredicateFieldReference<SR, T>,
38+
SpatialPredicateFieldReference<SR>,
39+
TermsPredicateFieldReference<SR>,
40+
WildcardPredicateFieldReference<SR> {
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.search.engine.search.reference.projection;
6+
7+
import org.hibernate.search.engine.search.common.ValueModel;
8+
import org.hibernate.search.util.common.annotation.Incubating;
9+
10+
/**
11+
* A generic projected-field reference that can be manually created and passed to any projection-DSL methods that require a field reference.
12+
* <p>
13+
* While it is expected that the generated Hibernate Search static metamodel will contain
14+
* more precise field references that would match the actual field capabilities, this generic reference can
15+
* be used by the users if they decide to opt-out of using the generated static metamodel
16+
* and would just want to create a few simple pre-defined references.
17+
*
18+
* @param absolutePath The absolut field path.
19+
* @param scopeRootType The class representing the scope root type.
20+
* @param valueModel The model of projected values. See {@link ValueModel}.
21+
* @param projectionType The class representing the type of the projected field, as per {@code valueModel}.
22+
* @param <SR> Scope root type
23+
* @param <T> The type of the projected field.
24+
*/
25+
@Incubating
26+
public record AnyProjectionReference<SR, T>(String absolutePath, Class<SR> scopeRootType, ValueModel valueModel,
27+
Class<T> projectionType)
28+
implements DistanceProjectionFieldReference<SR>,
29+
FieldProjectionFieldReference<SR, T>,
30+
HighlightProjectionFieldReference<SR>,
31+
ObjectProjectionFieldReference<SR> {
32+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.search.engine.search.reference.sort;
6+
7+
import org.hibernate.search.engine.search.common.ValueModel;
8+
import org.hibernate.search.util.common.annotation.Incubating;
9+
10+
/**
11+
* A generic sort-field reference that can be manually created and passed to any sort-DSL methods that require a field reference.
12+
* <p>
13+
* While it is expected that the generated Hibernate Search static metamodel will contain
14+
* more precise field references that would match the actual field capabilities, this generic reference can
15+
* be used by the users if they decide to opt-out of using the generated static metamodel
16+
* and would just want to create a few simple pre-defined references.
17+
*
18+
* @param absolutePath The absolut field path.
19+
* @param scopeRootType The class representing the scope root type.
20+
* @param valueModel The model of sort values. See {@link ValueModel}.
21+
* @param sortType The class representing the type of the sorted field, as per {@code valueModel}.
22+
* @param <SR> Scope root type
23+
* @param <T> The type of the sorted field.
24+
*/
25+
@Incubating
26+
public record AnySortReference<SR, T>(String absolutePath, Class<SR> scopeRootType, ValueModel valueModel, Class<T> sortType)
27+
implements DistanceSortFieldReference<SR>,
28+
FieldSortFieldReference<SR, T>,
29+
ScoreSortFieldReference<SR, T> {
30+
}

0 commit comments

Comments
 (0)