85
85
* (endpoint, authentication). A Collection has a name, which is its unique identifier for a namespace and
86
86
* options to specialize the usage as vector collections or advanced indexing parameters.
87
87
* </p>
88
- *
89
88
* <p>
90
89
* A Collection is typed object designed to work both with default @{@link com.datastax.astra.client.model.Document} (wrapper for a Map) and application
91
90
* plain old java objects (pojo). The serialization is performed with Jackson and application beans can be annotated.
92
91
* </p>
93
- *
94
92
* <p>Example usage:</p>
95
93
* <pre>
96
94
* {@code
@@ -119,6 +117,7 @@ public class Collection<DOC> extends AbstractCommandRunner {
119
117
protected final Class <DOC > documentClass ;
120
118
121
119
/** keep reference to namespace client. */
120
+ @ Getter
122
121
private final Database database ;
123
122
124
123
/** Api Endpoint for the Database. */
@@ -143,35 +142,20 @@ protected Collection(Database db, String collectionName, Class<DOC> clazz) {
143
142
}
144
143
145
144
// ----------------------------
146
- // --- Global Informations ----
145
+ // --- Global Information ----
147
146
// ----------------------------
148
147
149
- public String getNamespaceName () {
150
- return getDatabase ().getNamespaceName ();
151
- }
152
-
153
148
/**
154
- * Retrieves the parent {@link Database} instance.
155
- * This parent namespace is used for performing CRUD (Create, Read, Update, Delete) operations on collections.
156
- *
157
- * <p>Example usage:</p>
158
- * <pre>
159
- * {@code
160
- * // Given a collection
161
- * DataApiCollection<Document> collection;
162
- * // TODO
163
- * }
164
- * </pre>
165
- *
166
- * @return parent namespace client.
149
+ * Access the parent namespace associated to the collection
150
+ * @return
151
+ * the name of the parent namespace for current collection.
167
152
*/
168
- public Database getDatabase () {
169
- return database ;
153
+ public String getNamespaceName () {
154
+ return getDatabase (). getNamespaceName () ;
170
155
}
171
156
172
157
/**
173
158
* Retrieves the full definition of the collection with its name and options.
174
- * <p></p>
175
159
* <p>Example usage:</p>
176
160
* <pre>
177
161
* {@code
@@ -187,9 +171,7 @@ public Database getDatabase() {
187
171
* }
188
172
* </pre>
189
173
*
190
- * @return the full collection definition.
191
- *
192
- * @see CollectionDefinition##getOptions()
174
+ * @return the full collection definition
193
175
*/
194
176
public CollectionDefinition getDefinition () {
195
177
return database
@@ -266,12 +248,10 @@ public String getName() {
266
248
/**
267
249
* Insert a single document in the collection in an atomic operation.
268
250
*
269
- * <p>
270
251
* <blockquote><b>Note:</b>If an `_id` is explicitly provided, which corresponds to a document
271
252
* that exists already in the collection, an error is raised and the insertion fails.
272
253
* Inserts the provided document. If the document is missing an identifier, the server will generate one.
273
254
* </blockquote>
274
- * </p>
275
255
*
276
256
* @param document
277
257
* the document expressing the document to insert. The `_id` field of the document can be left out, in which case it will be created automatically.
@@ -510,74 +490,112 @@ public FindIterable<DOC> find(Filter filter, FindOptions options) {
510
490
* @param filter The {@link Filter} specifying the conditions that the document must meet to be considered
511
491
* a match. This parameter determines how the search is conducted and what criteria the
512
492
* document must satisfy to be retrieved.
513
- * @return A {@link CompletableFuture<Optional<DOC>>} that, when completed, will contain the result of
493
+ * @return CompletableFuture that, when completed, will contain the result of
514
494
* the search operation. If a matching document is found, the {@link Optional} is non-empty;
515
495
* otherwise, it is empty to indicate the absence of a matching document. This future allows for
516
496
* non-blocking operations and facilitates the integration of asynchronous programming patterns.
517
497
*/
518
498
public CompletableFuture <Optional <DOC >> findOneASync (Filter filter ) {
519
499
return CompletableFuture .supplyAsync (() -> findOne (filter ));
520
500
}
521
-
522
501
/**
523
- * Create a filter by id.
502
+ * Retrieves a document by its identifier from the collection.
503
+ * <p>
504
+ * This method searches for a document with the specified {@code id}. If a matching document is found,
505
+ * it is returned wrapped in an {@link Optional}, otherwise, an empty {@link Optional} is returned.
506
+ * This approach provides a null-safe way to handle the presence or absence of a document.
507
+ * </p>
524
508
*
525
- * @param id
526
- * value for identifier
527
- * @return
528
- * document if it exists
509
+ * @param id The identifier of the document to find.
510
+ * @return An {@link Optional} containing the found document, or an empty {@link Optional} if no document
511
+ * matches the provided {@code id}.
529
512
*/
530
513
public Optional <DOC > findById (Object id ) {
531
514
return findOne (Filters .eq (id ));
532
515
}
533
516
534
517
/**
535
- * Finds all documents in the collection.
518
+ * Retrieves all documents in the collection.
519
+ * <p>
520
+ * This method returns an iterable interface that allows iterating over all documents in the collection,
521
+ * without applying any filters. It leverages the default {@link FindOptions} for query execution.
522
+ * </p>
536
523
*
537
- * @return
538
- * the find iterable interface
524
+ * @return A {@link FindIterable} for iterating over all documents in the collection.
539
525
*/
540
526
public FindIterable <DOC > find () {
541
527
return find (null , new FindOptions ());
542
528
}
543
529
544
530
/**
545
- * Finds all documents in the collection.
531
+ * Retrieves documents in the collection that match the specified filter.
532
+ * <p>
533
+ * This method returns an iterable interface for documents that meet the criteria defined by the {@code filter}.
534
+ * It uses default {@link FindOptions} for query execution, allowing for customization of the query if needed.
535
+ * </p>
546
536
*
547
- * @param filter
548
- * the query filter
549
- * @return
550
- * the find iterable interface
537
+ * @param filter The query filter to apply when retrieving documents.
538
+ * @return A {@link FindIterable} for iterating over the documents that match the filter.
551
539
*/
552
540
public FindIterable <DOC > find (Filter filter ) {
553
541
return find (filter , new FindOptions ());
554
542
}
555
543
556
544
/**
557
- * Finds all documents in the collection.
545
+ * Finds documents in the collection that match the specified filter and sorts them based on their similarity
546
+ * to a provided vector, limiting the number of results returned.
547
+ * <p>
548
+ * This method is particularly useful for vector-based search operations where documents are ranked according
549
+ * to their distance from a reference vector. The {@code limit} parameter controls the maximum number of documents
550
+ * to return, allowing for efficient retrieval of the most relevant documents.
551
+ * </p>
558
552
*
559
- * @param filter
560
- * the query filter
561
- * @return
562
- * the find iterable interface
553
+ * @param filter The query filter to apply when retrieving documents.
554
+ * @param vector A float array representing the vector used to sort the documents.
555
+ * @param limit The maximum number of documents to return.
556
+ * @return A {@link FindIterable} for iterating over the sorted and limited documents.
563
557
*/
564
558
public FindIterable <DOC > find (Filter filter , float [] vector , int limit ) {
565
559
return find (filter , new FindOptions ().sortingByVector (vector ).limit (limit ));
566
560
}
567
561
568
562
/**
569
- * Finds all documents in the collection.
563
+ * Finds all documents in the collection, applying the specified find options.
564
+ * <p>
565
+ * This method allows for detailed control over the query execution through {@link FindOptions}, which can
566
+ * specify sorting, projection, limits, and other query parameters. If no filter is applied, all documents
567
+ * in the collection are considered.
568
+ * </p>
570
569
*
571
- * @param options
572
- * options of find one
573
- * @return
574
- * the find iterable interface
570
+ * @param options The {@link FindOptions} to apply when executing the find operation.
571
+ * @return A {@link FindIterable} for iterating over the documents according to the specified options.
575
572
*/
576
573
public FindIterable <DOC > find (FindOptions options ) {
577
574
return find (null , options );
578
575
}
579
576
580
- /** {@inheritDoc} */
577
+ /**
578
+ * Executes a paginated 'find' query on the collection using the specified filter and find options.
579
+ * <p>
580
+ * This method constructs and executes a command to fetch a specific page of documents from the collection that match
581
+ * the provided filter criteria. It allows for detailed control over the query through {@code FindOptions}, such as sorting,
582
+ * projection, pagination, and more. The result is wrapped in a {@link Page} object, which includes the documents found,
583
+ * the page size, and the state for fetching subsequent pages.
584
+ * </p>
585
+ * <p>
586
+ * Pagination is facilitated by the {@code skip}, {@code limit}, and {@code pageState} parameters within {@code FindOptions},
587
+ * enabling efficient data retrieval in scenarios where the total dataset is too large to be fetched in a single request.
588
+ * Optionally, similarity scoring can be included if {@code includeSimilarity} is set, which is useful for vector-based search queries.
589
+ * </p>
590
+ * <p>
591
+ * The method processes the command's response, mapping each document to the specified document class and collecting them into a list.
592
+ * This list, along with the maximum page size and the next page state, is used to construct the {@link Page} object returned by the method.
593
+ * </p>
594
+ *
595
+ * @param filter The filter criteria used to select documents from the collection.
596
+ * @param options The {@link FindOptions} providing additional query parameters, such as sorting and pagination.
597
+ * @return A {@link Page} object containing the documents that match the query, along with pagination information.
598
+ */
581
599
public Page <DOC > findPage (Filter filter , FindOptions options ) {
582
600
Command findCommand = Command
583
601
.create ("find" )
@@ -808,8 +826,7 @@ public DeleteResult deleteAll() {
808
826
*
809
827
* <p>
810
828
* This method delegates the existence check to the {@code existCollection} method of the associated
811
- * namespace, determined by {@link #getDatabase()}, and evaluates the existence based on the
812
- * collection's name, as retrieved by {@link #getName()}.
829
+ * namespace, evaluates the existence based on the collection's name, as retrieved by getName().
813
830
* </p>
814
831
*
815
832
* @return {@code true} if the collection exists within the namespace, {@code false} otherwise.
0 commit comments