Skip to content

Commit 856867a

Browse files
committed
removing CRTP
1 parent 266b0a5 commit 856867a

34 files changed

+2441
-432
lines changed

File

Whitespace-only changes.

Preferences...

Whitespace-only changes.

Resources

Whitespace-only changes.

astra-db-java/src/main/java/com/datastax/astra/client/collections/Collection.java

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import com.datastax.astra.internal.serdes.DataAPISerializer;
6969
import com.datastax.astra.internal.serdes.collections.DocumentSerializer;
7070
import com.datastax.astra.internal.utils.Assert;
71+
import com.datastax.astra.internal.utils.EscapeUtils;
7172
import lombok.Getter;
7273
import lombok.extern.slf4j.Slf4j;
7374

@@ -1132,6 +1133,28 @@ public CompletableFuture<Page<T>> findPageASync(Filter filter, CollectionFindOpt
11321133
// --- distinct ----
11331134
// -------------------------
11341135

1136+
/**
1137+
* Return a list of distinct values for the given field name.
1138+
*
1139+
* @param fieldPath
1140+
* chunks of the paths
1141+
* @param filter
1142+
* filter to apply
1143+
* @param resultClass
1144+
* class of the result
1145+
* @param <R>
1146+
* type of the result
1147+
* @return
1148+
* list of distinct values
1149+
*/
1150+
public <R> Set<R> distinct(String[] fieldPath, Filter filter, Class<R> resultClass) {
1151+
Assert.notNull(fieldPath, "field path");
1152+
if (fieldPath.length == 0) {
1153+
throw new IllegalArgumentException("field path must not be empty");
1154+
}
1155+
return distinct(EscapeUtils.escapeFieldNames(fieldPath), filter, resultClass, null);
1156+
}
1157+
11351158
/**
11361159
* Return a list of distinct values for the given field name.
11371160
*
@@ -1150,6 +1173,26 @@ public <R> Set<R> distinct(String fieldName, Filter filter, Class<R> resultClass
11501173
return distinct(fieldName, filter, resultClass, null);
11511174
}
11521175

1176+
/**
1177+
* Return a list of distinct values for the given field name.
1178+
*
1179+
* @param fieldPath
1180+
* segments of the path
1181+
* @param resultClass
1182+
* class of the result
1183+
* @param <R>
1184+
* type of the result
1185+
* @return
1186+
* list of distinct values
1187+
*/
1188+
public <R> Set<R> distinct(String[] fieldPath, Class<R> resultClass) {
1189+
Assert.notNull(fieldPath, "field path");
1190+
if (fieldPath.length == 0) {
1191+
throw new IllegalArgumentException("field path must not be empty");
1192+
}
1193+
return distinct(EscapeUtils.escapeFieldNames(fieldPath), null, resultClass, null);
1194+
}
1195+
11531196
/**
11541197
* Return a list of distinct values for the given field name.
11551198
*
@@ -1187,7 +1230,7 @@ public <R> Set<R> distinct(String fieldName, Filter filter, Class<R> resultClass
11871230
Assert.notNull(resultClass, "resultClass");
11881231
// Building a convenient find options
11891232
CollectionFindOptions findOptions = new CollectionFindOptions()
1190-
.projection(Projection.include(fieldName));
1233+
.projection(Projection.include( fieldName.replaceAll("\\[\\d+\\]", "")));
11911234
// Overriding options
11921235
if (options != null && options.getDataAPIClientOptions() != null) {
11931236
findOptions.dataAPIClientOptions(options.getDataAPIClientOptions());

astra-db-java/src/main/java/com/datastax/astra/client/collections/definition/CollectionDefinition.java

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@
2020
* #L%
2121
*/
2222

23+
import com.datastax.astra.client.core.lexical.LexicalAnalyzers;
24+
import com.datastax.astra.client.core.lexical.LexicalOptions;
25+
import com.datastax.astra.client.core.reranking.RerankingOptions;
26+
import com.datastax.astra.client.core.reranking.RerankingProvider;
27+
import com.datastax.astra.client.core.reranking.RerankingServiceOptions;
2328
import com.datastax.astra.client.core.vector.SimilarityMetric;
2429
import com.datastax.astra.client.core.vector.VectorOptions;
2530
import com.datastax.astra.client.core.vectorize.VectorServiceOptions;
26-
import lombok.NoArgsConstructor;
2731
import lombok.NonNull;
2832
import lombok.Setter;
2933
import lombok.experimental.Accessors;
@@ -54,6 +58,16 @@ public class CollectionDefinition {
5458
*/
5559
private IndexingOptions indexing;
5660

61+
/**
62+
* Lexical options
63+
*/
64+
private LexicalOptions lexical;
65+
66+
/**
67+
* Reranking options
68+
*/
69+
private RerankingOptions reranking;
70+
5771
/**
5872
* Default constructor.
5973
*/
@@ -145,6 +159,7 @@ public VectorOptions getVector() {
145159
return vector;
146160
}
147161

162+
148163
/**
149164
* Access the indexing options.
150165
*
@@ -154,6 +169,24 @@ public IndexingOptions getIndexing() {
154169
return indexing;
155170
}
156171

172+
/**
173+
* Gets lexical
174+
*
175+
* @return value of lexical
176+
*/
177+
public LexicalOptions getLexical() {
178+
return lexical;
179+
}
180+
181+
/**
182+
* Gets reranking
183+
*
184+
* @return value of reranking
185+
*/
186+
public RerankingOptions getReranking() {
187+
return reranking;
188+
}
189+
157190
/**
158191
* Gets defaultId
159192
*
@@ -175,6 +208,35 @@ public CollectionDefinition defaultId(CollectionDefaultIdTypes type) {
175208
return this;
176209
}
177210

211+
/**
212+
* Builder pattern.
213+
*
214+
* @param analyzers size
215+
* @return self reference
216+
*/
217+
public CollectionDefinition lexical(LexicalAnalyzers analyzers) {
218+
if (getLexical() == null) {
219+
lexical = new LexicalOptions();
220+
}
221+
getLexical().enabled(true).analyzer(analyzers);
222+
return this;
223+
}
224+
225+
/**
226+
* Builder pattern.
227+
*
228+
* @param reranker
229+
* reranker
230+
* @return self reference
231+
*/
232+
public CollectionDefinition reranking(String reranker) {
233+
if (getReranking() == null) {
234+
reranking = new RerankingOptions();
235+
}
236+
getReranking().service(new RerankingServiceOptions().provider(reranker));
237+
return this;
238+
}
239+
178240
/**
179241
* Builder pattern.
180242
*

astra-db-java/src/main/java/com/datastax/astra/client/collections/definition/documents/Document.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,18 @@ public Document vectorize(String text) {
355355
return appendIfNotNull(DataAPIKeywords.VECTORIZE.getKeyword(), text);
356356
}
357357

358+
/**
359+
* Add a vectorize attribute to the document.
360+
*
361+
* @param text
362+
* value for the vectorize attribute
363+
* @return
364+
* self reference
365+
*/
366+
public Document lexical(String text) {
367+
return appendIfNotNull(DataAPIKeywords.LEXICAL.getKeyword(), text);
368+
}
369+
358370
/**
359371
* Access attribute with vectorize name if any.
360372
*

astra-db-java/src/main/java/com/datastax/astra/client/core/DataAPIKeywords.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,17 @@ public enum DataAPIKeywords {
102102
/**
103103
* VECTORIZE.
104104
*/
105-
VECTORIZE("$vectorize");
105+
VECTORIZE("$vectorize"),
106+
107+
/**
108+
* LEXICAL.
109+
*/
110+
LEXICAL("$lexical"),
111+
112+
/**
113+
* HYBRID.
114+
*/
115+
HYBRID("$hybrid");;
106116

107117
/**
108118
* Keyword.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.datastax.astra.client.core.lexical;
2+
3+
/*-
4+
* #%L
5+
* Data API Java Client
6+
* --
7+
* Copyright (C) 2024 - 2025 DataStax
8+
* --
9+
* Licensed under the Apache License, Version 2.0
10+
* You may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
* #L%
21+
*/
22+
23+
import lombok.Getter;
24+
25+
@Getter
26+
public enum LexicalAnalyzers {
27+
28+
/**
29+
* Filters StandardTokenizer output that divides text
30+
* into terms on word boundaries and then uses the LowerCaseFilter.
31+
*/
32+
STANDARD("standard"),
33+
34+
LETTER("letter"),
35+
36+
LOWERCASE("lowercase"),
37+
38+
WHITESPACE("whitespace"),
39+
40+
N_GRAM("n-gram"),
41+
42+
EDGE_N_GRAM("edge_n-gram"),
43+
44+
KEYWORD("keyword");
45+
46+
final String value;
47+
48+
LexicalAnalyzers(String value) {
49+
this.value = value;
50+
}
51+
52+
/**
53+
* Build from the key.
54+
*
55+
* @param value
56+
* string value
57+
* @return
58+
* enum value
59+
*/
60+
public static LexicalFilters fromValue(String value) {
61+
for (LexicalFilters filter : LexicalFilters.values()) {
62+
if (filter.getValue().equalsIgnoreCase(value)) {
63+
return filter;
64+
}
65+
}
66+
throw new IllegalArgumentException("Unknown LexicalFilters: " + value);
67+
}
68+
69+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.datastax.astra.client.core.lexical;
2+
3+
/*-
4+
* #%L
5+
* Data API Java Client
6+
* --
7+
* Copyright (C) 2024 - 2025 DataStax
8+
* --
9+
* Licensed under the Apache License, Version 2.0
10+
* You may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
* #L%
21+
*/
22+
23+
import com.datastax.astra.client.core.vector.SimilarityMetric;
24+
import lombok.Getter;
25+
26+
@Getter
27+
public enum LexicalFilters {
28+
29+
/**
30+
* Filters StandardTokenizer output that divides text
31+
* into terms on word boundaries and then uses the LowerCaseFilter.
32+
*/
33+
LOWERCASE("lowercase"),
34+
35+
STOP("stop"),
36+
37+
SYNONYM("synonym"),
38+
39+
SYNONYM_GRAPH("synonym_graph");
40+
41+
final String value;
42+
43+
LexicalFilters(String value) {
44+
this.value = value;
45+
}
46+
47+
/**
48+
* Build from the key.
49+
*
50+
* @param value
51+
* string value
52+
* @return
53+
* enum value
54+
*/
55+
public static LexicalFilters fromValue(String value) {
56+
for (LexicalFilters filter : LexicalFilters.values()) {
57+
if (filter.getValue().equalsIgnoreCase(value)) {
58+
return filter;
59+
}
60+
}
61+
throw new IllegalArgumentException("Unknown LexicalFilters: " + value);
62+
}
63+
64+
}

0 commit comments

Comments
 (0)