Skip to content

Commit 558c3e7

Browse files
committed
HSEARCH-3319 Add references to the DSL
1 parent 16ebc09 commit 558c3e7

File tree

79 files changed

+2343
-634
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+2343
-634
lines changed

engine/src/main/java/org/hibernate/search/engine/search/predicate/dsl/CommonQueryStringPredicateFieldMoreStep.java

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,25 @@
44
*/
55
package org.hibernate.search.engine.search.predicate.dsl;
66

7+
import org.hibernate.search.engine.search.reference.predicate.TypedPredicateFieldReference;
8+
import org.hibernate.search.util.common.annotation.Incubating;
9+
710
/**
811
* The step in a query string predicate definition, where the query string to match can be set
912
* (see the superinterface {@link CommonQueryStringPredicateMatchingStep}),
1013
* or optional parameters for the last targeted field(s) can be set,
1114
* or more target fields can be added.
1215
*
16+
* @param <SR> Scope root type.
17+
* @param <FR> Type of the field references.
1318
* @param <S> The "self" type (the actual exposed type of this step).
1419
* @param <N> The type of the next step.
1520
*/
1621
public interface CommonQueryStringPredicateFieldMoreStep<
17-
S extends CommonQueryStringPredicateFieldMoreStep<?, N>,
18-
N extends CommonQueryStringPredicateOptionsStep<?>>
22+
SR,
23+
S extends CommonQueryStringPredicateFieldMoreStep<SR, ?, N, FR>,
24+
N extends CommonQueryStringPredicateOptionsStep<?>,
25+
FR extends TypedPredicateFieldReference<SR, ?>>
1926
extends CommonQueryStringPredicateMatchingStep<N>, MultiFieldPredicateFieldBoostStep<S> {
2027

2128
/**
@@ -52,4 +59,48 @@ default S field(String fieldPath) {
5259
*/
5360
S fields(String... fieldPaths);
5461

62+
/**
63+
* Target the given field in the query string predicate,
64+
* as an alternative to the already-targeted fields.
65+
* <p>
66+
* Only text fields are supported.
67+
* <p>
68+
* See {@link CommonQueryStringPredicateFieldStep#field(String)} for more information on targeted fields.
69+
*
70+
* @param field The field reference representing a <a href="SearchPredicateFactory.html#field-paths">path</a> to the index field
71+
* to apply the predicate on.
72+
* @return The next step.
73+
*
74+
* @see CommonQueryStringPredicateFieldStep#field(String)
75+
*/
76+
@Incubating
77+
@SuppressWarnings("unchecked")
78+
default S field(FR field) {
79+
return fields( field );
80+
}
81+
82+
/**
83+
* Target the given fields in the query string predicate,
84+
* as an alternative to the already-targeted fields.
85+
* <p>
86+
* Only text fields are supported.
87+
* <p>
88+
* See {@link CommonQueryStringPredicateFieldStep#fields(String...)} for more information on targeted fields.
89+
*
90+
* @param fields The field reference representing <a href="SearchPredicateFactory.html#field-paths">paths</a> to the index fields
91+
* to apply the predicate on.
92+
* @return The next step.
93+
*
94+
* @see CommonQueryStringPredicateFieldStep#fields(String...)
95+
*/
96+
@Incubating
97+
@SuppressWarnings("unchecked")
98+
default S fields(FR... fields) {
99+
String[] paths = new String[fields.length];
100+
for ( int i = 0; i < fields.length; i++ ) {
101+
paths[i] = fields[i].absolutePath();
102+
}
103+
return fields( paths );
104+
}
105+
55106
}

engine/src/main/java/org/hibernate/search/engine/search/predicate/dsl/CommonQueryStringPredicateFieldStep.java

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@
44
*/
55
package org.hibernate.search.engine.search.predicate.dsl;
66

7+
import org.hibernate.search.engine.search.reference.predicate.TypedPredicateFieldReference;
8+
import org.hibernate.search.util.common.annotation.Incubating;
9+
710
/**
811
* The initial step in a query string predicate definition, where the target field can be set.
912
*
13+
* @param <SR> Scope root type.
14+
* @param <FR> Type of the field references.
1015
* @param <N> The type of the next step.
1116
*/
12-
public interface CommonQueryStringPredicateFieldStep<N extends CommonQueryStringPredicateFieldMoreStep<?, ?>> {
17+
public interface CommonQueryStringPredicateFieldStep<
18+
SR,
19+
N extends CommonQueryStringPredicateFieldMoreStep<SR, ?, ?, FR>,
20+
FR extends TypedPredicateFieldReference<SR, ?>> {
1321

1422
/**
1523
* Target the given field in the query string predicate.
@@ -49,4 +57,52 @@ default N field(String fieldPath) {
4957
*/
5058
N fields(String... fieldPaths);
5159

60+
61+
/**
62+
* Target the given field in the query string predicate.
63+
* <p>
64+
* Only text fields are supported.
65+
* <p>
66+
* Multiple fields may be targeted by the same predicate:
67+
* the predicate will match if <em>any</em> targeted field matches.
68+
* <p>
69+
* When targeting multiple fields, those fields must have compatible types.
70+
* Please refer to the reference documentation for more information.
71+
*
72+
* @param field The field reference representing a <a href="SearchPredicateFactory.html#field-paths">path</a> to the index field
73+
* to apply the predicate on.
74+
* @return The next step.
75+
*/
76+
@Incubating
77+
@SuppressWarnings("unchecked")
78+
default N field(FR field) {
79+
return fields( field );
80+
}
81+
82+
/**
83+
* Target the given fields in the query string predicate.
84+
* <p>
85+
* Only text fields are supported.
86+
* <p>
87+
* Equivalent to {@link #field(String)} followed by multiple calls to
88+
* {@link #field(String)},
89+
* the only difference being that calls to {@link CommonQueryStringPredicateFieldMoreStep#boost(float)}
90+
* and other field-specific settings on the returned step will only need to be done once
91+
* and will apply to all the fields passed to this method.
92+
*
93+
* @param fields The field reference representing <a href="SearchPredicateFactory.html#field-paths">paths</a> to the index fields
94+
* to apply the predicate on.
95+
* @return The next step.
96+
*
97+
* @see #field(String)
98+
*/
99+
@Incubating
100+
@SuppressWarnings("unchecked")
101+
default N fields(FR... fields) {
102+
String[] paths = new String[fields.length];
103+
for ( int i = 0; i < fields.length; i++ ) {
104+
paths[i] = fields[i].absolutePath();
105+
}
106+
return fields( paths );
107+
}
52108
}

engine/src/main/java/org/hibernate/search/engine/search/predicate/dsl/ExistsPredicateFieldStep.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
*/
55
package org.hibernate.search.engine.search.predicate.dsl;
66

7+
import org.hibernate.search.engine.search.reference.predicate.ExistsPredicateFieldReference;
8+
import org.hibernate.search.util.common.annotation.Incubating;
79

810
/**
911
* The initial step in an "exists" predicate definition, where the target field can be set.
1012
*
1113
* @param <N> The type of the next step.
1214
*/
13-
public interface ExistsPredicateFieldStep<N extends ExistsPredicateOptionsStep<?>> {
15+
public interface ExistsPredicateFieldStep<SR, N extends ExistsPredicateOptionsStep<?>> {
1416

1517
/**
1618
* Target the given field in the "exists" predicate.
@@ -21,4 +23,16 @@ public interface ExistsPredicateFieldStep<N extends ExistsPredicateOptionsStep<?
2123
*/
2224
N field(String fieldPath);
2325

26+
/**
27+
* Target the given field in the "exists" predicate.
28+
*
29+
* @param field The field reference representing a <a href="SearchPredicateFactory.html#field-paths">path</a> to the index field
30+
* to apply the predicate on.
31+
* @return The next step.
32+
*/
33+
@Incubating
34+
default N field(ExistsPredicateFieldReference<SR> field) {
35+
return field( field.absolutePath() );
36+
}
37+
2438
}

engine/src/main/java/org/hibernate/search/engine/search/predicate/dsl/KnnPredicateFieldStep.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
package org.hibernate.search.engine.search.predicate.dsl;
66

7+
import org.hibernate.search.engine.search.reference.predicate.KnnPredicateFieldReference;
8+
79
/**
810
* The initial step in a "knn" predicate definition, where the target field can be set.
911
* @param <SR> Scope root type.
@@ -17,4 +19,6 @@ public interface KnnPredicateFieldStep<SR> {
1719
* @return The next step in the knn predicate DSL.
1820
*/
1921
KnnPredicateVectorStep<SR> field(String fieldPath);
22+
23+
<T> KnnPredicateVectorGenericStep<SR, T> field(KnnPredicateFieldReference<SR, T> field);
2024
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.search.engine.search.predicate.dsl;
6+
7+
/**
8+
* The step in a "knn" predicate definition where the vector to match is defined.
9+
*/
10+
public interface KnnPredicateVectorGenericStep<SR, T> {
11+
/**
12+
* @param vector The vector from which to compute the distance to vectors in the indexed field.
13+
* @return The next step in the knn predicate DSL.
14+
*/
15+
KnnPredicateOptionsStep<SR> matching(T vector);
16+
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.search.engine.search.predicate.dsl;
6+
7+
/**
8+
* The step in a "match" predicate definition where the value to match can be set
9+
* (see the superinterface {@link MatchPredicateMatchingStep}),
10+
* or optional parameters for the last targeted field(s) can be set,
11+
* or more target fields can be added.
12+
*
13+
* @param <S> The "self" type (the actual exposed type of this step).
14+
* @param <N> The type of the next step.
15+
* @param <T> The type of the match value.
16+
* @param <V> The type representing the fields.
17+
*/
18+
public interface MatchPredicateFieldMoreGenericStep<
19+
S extends MatchPredicateFieldMoreGenericStep<?, N, T, V>,
20+
N extends MatchPredicateOptionsStep<?>,
21+
T,
22+
V>
23+
extends MatchPredicateMatchingGenericStep<N, T>, MultiFieldPredicateFieldBoostStep<S> {
24+
25+
/**
26+
* Target the given field in the match predicate,
27+
* as an alternative to the already-targeted fields.
28+
* <p>
29+
* See {@link MatchPredicateFieldStep#field(String)} for more information about targeting fields.
30+
*
31+
* @param field The field with a <a href="SearchPredicateFactory.html#field-paths">path</a> to the index field
32+
* to apply the predicate on.
33+
* @return The next step.
34+
*
35+
* @see MatchPredicateFieldStep#field(String)
36+
*/
37+
S field(V field);
38+
39+
/**
40+
* Target the given fields in the match predicate,
41+
* as an alternative to the already-targeted fields.
42+
* <p>
43+
* See {@link MatchPredicateFieldStep#fields(String...)} for more information about targeting fields.
44+
*
45+
* @param fieldPaths The fields with <a href="SearchPredicateFactory.html#field-paths">paths</a> to the index fields
46+
* to apply the predicate on.
47+
* @return The next step.
48+
*
49+
* @see MatchPredicateFieldStep#fields(String...)
50+
*/
51+
@SuppressWarnings("unchecked")
52+
S fields(V... fieldPaths);
53+
54+
}

engine/src/main/java/org/hibernate/search/engine/search/predicate/dsl/MatchPredicateFieldMoreStep.java

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,6 @@
1616
public interface MatchPredicateFieldMoreStep<
1717
S extends MatchPredicateFieldMoreStep<?, N>,
1818
N extends MatchPredicateOptionsStep<?>>
19-
extends MatchPredicateMatchingStep<N>, MultiFieldPredicateFieldBoostStep<S> {
20-
21-
/**
22-
* Target the given field in the match predicate,
23-
* as an alternative to the already-targeted fields.
24-
* <p>
25-
* See {@link MatchPredicateFieldStep#field(String)} for more information about targeting fields.
26-
*
27-
* @param fieldPath The <a href="SearchPredicateFactory.html#field-paths">path</a> to the index field
28-
* to apply the predicate on.
29-
* @return The next step.
30-
*
31-
* @see MatchPredicateFieldStep#field(String)
32-
*/
33-
default S field(String fieldPath) {
34-
return fields( fieldPath );
35-
}
36-
37-
/**
38-
* Target the given fields in the match predicate,
39-
* as an alternative to the already-targeted fields.
40-
* <p>
41-
* See {@link MatchPredicateFieldStep#fields(String...)} for more information about targeting fields.
42-
*
43-
* @param fieldPaths The <a href="SearchPredicateFactory.html#field-paths">paths</a> to the index fields
44-
* to apply the predicate on.
45-
* @return The next step.
46-
*
47-
* @see MatchPredicateFieldStep#fields(String...)
48-
*/
49-
S fields(String... fieldPaths);
19+
extends MatchPredicateMatchingStep<N>, MatchPredicateFieldMoreGenericStep<S, N, Object, String> {
5020

5121
}

engine/src/main/java/org/hibernate/search/engine/search/predicate/dsl/MatchPredicateFieldStep.java

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
*/
55
package org.hibernate.search.engine.search.predicate.dsl;
66

7+
import org.hibernate.search.engine.search.reference.predicate.MatchPredicateFieldReference;
78

89
/**
910
* The initial step in a "match" predicate definition, where the target field can be set.
1011
*/
11-
public interface MatchPredicateFieldStep<N extends MatchPredicateFieldMoreStep<?, ?>> {
12+
public interface MatchPredicateFieldStep<SR, N extends MatchPredicateFieldMoreStep<?, ?>> {
1213

1314
/**
1415
* Target the given field in the match predicate.
@@ -31,7 +32,7 @@ default N field(String fieldPath) {
3132
* Target the given fields in the match predicate.
3233
* <p>
3334
* Equivalent to {@link #field(String)} followed by multiple calls to
34-
* {@link MatchPredicateFieldMoreStep#field(String)},
35+
* {@link MatchPredicateFieldMoreStep#field(Object)},
3536
* the only difference being that calls to {@link MatchPredicateFieldMoreStep#boost(float)}
3637
* and other field-specific settings on the returned step will only need to be done once
3738
* and will apply to all the fields passed to this method.
@@ -43,4 +44,42 @@ default N field(String fieldPath) {
4344
* @see #field(String)
4445
*/
4546
N fields(String... fieldPaths);
47+
48+
/**
49+
* Target the given field in the match predicate.
50+
* <p>
51+
* Multiple fields may be targeted by the same predicate:
52+
* the predicate will match if <em>any</em> targeted field matches.
53+
* <p>
54+
* When targeting multiple fields, those fields must have compatible types.
55+
* Please refer to the reference documentation for more information.
56+
*
57+
* @param fieldReference The field reference representing a <a href="SearchPredicateFactory.html#field-paths">path</a> to the index field
58+
* to apply the predicate on.
59+
* @return The next step.
60+
*/
61+
@SuppressWarnings("unchecked")
62+
default <T> MatchPredicateFieldMoreGenericStep<?, ?, T, MatchPredicateFieldReference<SR, T>> field(
63+
MatchPredicateFieldReference<SR, T> fieldReference) {
64+
return fields( fieldReference );
65+
}
66+
67+
/**
68+
* Target the given fields in the match predicate.
69+
* <p>
70+
* Equivalent to {@link #field(String)} followed by multiple calls to
71+
* {@link MatchPredicateFieldMoreStep#field(Object)},
72+
* the only difference being that calls to {@link MatchPredicateFieldMoreStep#boost(float)}
73+
* and other field-specific settings on the returned step will only need to be done once
74+
* and will apply to all the fields passed to this method.
75+
*
76+
* @param fieldReferences The field references representing <a href="SearchPredicateFactory.html#field-paths">paths</a> to the index fields
77+
* to apply the predicate on.
78+
* @return The next step.
79+
*
80+
* @see #field(MatchPredicateFieldReference)
81+
*/
82+
@SuppressWarnings("unchecked")
83+
<T> MatchPredicateFieldMoreGenericStep<?, ?, T, MatchPredicateFieldReference<SR, T>> fields(
84+
MatchPredicateFieldReference<SR, T>... fieldReferences);
4685
}

0 commit comments

Comments
 (0)