Skip to content

Commit 1cc780c

Browse files
committed
HSEARCH-3319 Add references to the DSL
1 parent edf375b commit 1cc780c

File tree

56 files changed

+1795
-505
lines changed

Some content is hidden

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

56 files changed

+1795
-505
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
@@ -6,18 +6,25 @@
66
*/
77
package org.hibernate.search.engine.search.predicate.dsl;
88

9+
import org.hibernate.search.engine.search.reference.predicate.TypedPredicateFieldReference;
10+
import org.hibernate.search.util.common.annotation.Incubating;
11+
912
/**
1013
* The step in a query string predicate definition, where the query string to match can be set
1114
* (see the superinterface {@link CommonQueryStringPredicateMatchingStep}),
1215
* or optional parameters for the last targeted field(s) can be set,
1316
* or more target fields can be added.
1417
*
18+
* @param <SR> Scope root type.
19+
* @param <FR> Type of the field references.
1520
* @param <S> The "self" type (the actual exposed type of this step).
1621
* @param <N> The type of the next step.
1722
*/
1823
public interface CommonQueryStringPredicateFieldMoreStep<
19-
S extends CommonQueryStringPredicateFieldMoreStep<?, N>,
20-
N extends CommonQueryStringPredicateOptionsStep<?>>
24+
SR,
25+
S extends CommonQueryStringPredicateFieldMoreStep<SR, ?, N, FR>,
26+
N extends CommonQueryStringPredicateOptionsStep<?>,
27+
FR extends TypedPredicateFieldReference<SR, ?>>
2128
extends CommonQueryStringPredicateMatchingStep<N>, MultiFieldPredicateFieldBoostStep<S> {
2229

2330
/**
@@ -54,4 +61,48 @@ default S field(String fieldPath) {
5461
*/
5562
S fields(String... fieldPaths);
5663

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

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
@@ -6,12 +6,20 @@
66
*/
77
package org.hibernate.search.engine.search.predicate.dsl;
88

9+
import org.hibernate.search.engine.search.reference.predicate.TypedPredicateFieldReference;
10+
import org.hibernate.search.util.common.annotation.Incubating;
11+
912
/**
1013
* The initial step in a query string predicate definition, where the target field can be set.
1114
*
15+
* @param <SR> Scope root type.
16+
* @param <FR> Type of the field references.
1217
* @param <N> The type of the next step.
1318
*/
14-
public interface CommonQueryStringPredicateFieldStep<N extends CommonQueryStringPredicateFieldMoreStep<?, ?>> {
19+
public interface CommonQueryStringPredicateFieldStep<
20+
SR,
21+
N extends CommonQueryStringPredicateFieldMoreStep<SR, ?, ?, FR>,
22+
FR extends TypedPredicateFieldReference<SR, ?>> {
1523

1624
/**
1725
* Target the given field in the query string predicate.
@@ -51,4 +59,52 @@ default N field(String fieldPath) {
5159
*/
5260
N fields(String... fieldPaths);
5361

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

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
@@ -6,13 +6,15 @@
66
*/
77
package org.hibernate.search.engine.search.predicate.dsl;
88

9+
import org.hibernate.search.engine.search.reference.predicate.ExistsPredicateFieldReference;
10+
import org.hibernate.search.util.common.annotation.Incubating;
911

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

1719
/**
1820
* Target the given field in the "exists" predicate.
@@ -23,4 +25,16 @@ public interface ExistsPredicateFieldStep<N extends ExistsPredicateOptionsStep<?
2325
*/
2426
N field(String fieldPath);
2527

28+
/**
29+
* Target the given field in the "exists" predicate.
30+
*
31+
* @param field The field reference representing 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+
@Incubating
36+
default N field(ExistsPredicateFieldReference<SR> field) {
37+
return field( field.absolutePath() );
38+
}
39+
2640
}

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
@@ -6,6 +6,8 @@
66
*/
77
package org.hibernate.search.engine.search.predicate.dsl;
88

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

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
@@ -18,36 +18,6 @@
1818
public interface MatchPredicateFieldMoreStep<
1919
S extends MatchPredicateFieldMoreStep<?, N>,
2020
N extends MatchPredicateOptionsStep<?>>
21-
extends MatchPredicateMatchingStep<N>, MultiFieldPredicateFieldBoostStep<S> {
22-
23-
/**
24-
* Target the given field in the match predicate,
25-
* as an alternative to the already-targeted fields.
26-
* <p>
27-
* See {@link MatchPredicateFieldStep#field(String)} for more information about targeting fields.
28-
*
29-
* @param fieldPath The <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-
* @see MatchPredicateFieldStep#field(String)
34-
*/
35-
default S field(String fieldPath) {
36-
return fields( fieldPath );
37-
}
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 <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-
S fields(String... fieldPaths);
21+
extends MatchPredicateMatchingStep<N>, MatchPredicateFieldMoreGenericStep<S, N, Object, String> {
5222

5323
}

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
@@ -6,11 +6,12 @@
66
*/
77
package org.hibernate.search.engine.search.predicate.dsl;
88

9+
import org.hibernate.search.engine.search.reference.predicate.MatchPredicateFieldReference;
910

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

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

0 commit comments

Comments
 (0)