@@ -7,7 +7,10 @@ use super::{Client, Error};
77use std:: sync:: Arc ;
88use typesense_codegen:: {
99 apis:: { configuration, documents_api} ,
10- models,
10+ models:: {
11+ self , DeleteDocumentsParameters , ExportDocumentsParameters , ImportDocumentsParameters ,
12+ UpdateDocumentsParameters ,
13+ } ,
1114} ;
1215
1316/// Provides methods for interacting with documents within a specific Typesense collection.
@@ -82,27 +85,6 @@ impl<'a> Documents<'a> {
8285 self . index ( document, "upsert" ) . await
8386 }
8487
85- /// Fetches an individual document from the collection by its ID.
86- ///
87- /// # Arguments
88- /// * `document_id` - The ID of the document to retrieve.
89- pub async fn retrieve (
90- & self ,
91- document_id : & str ,
92- ) -> Result < serde_json:: Value , Error < documents_api:: GetDocumentError > > {
93- let params = documents_api:: GetDocumentParams {
94- collection_name : self . collection_name . to_string ( ) ,
95- document_id : document_id. to_string ( ) ,
96- } ;
97-
98- self . client
99- . execute ( |config : Arc < configuration:: Configuration > | {
100- let params_for_move = params. clone ( ) ;
101- async move { documents_api:: get_document ( & config, params_for_move) . await }
102- } )
103- . await
104- }
105-
10688 // --- Bulk Operation Methods ---
10789
10890 /// Imports a batch of documents in JSONL format.
@@ -111,15 +93,23 @@ impl<'a> Documents<'a> {
11193 ///
11294 /// # Arguments
11395 /// * `documents_jsonl` - A string containing the documents in JSONL format.
114- /// * `params` - An `ImportDocumentsParams` struct containing options like `action` and `batch_size`.
115- /// The `collection_name` field will be overwritten.
96+ /// * `params` - An `ImportDocumentsParameters` struct containing options like `action` and `batch_size`.
11697 pub async fn import (
11798 & self ,
11899 documents_jsonl : String ,
119- mut params : documents_api :: ImportDocumentsParams ,
100+ params : ImportDocumentsParameters ,
120101 ) -> Result < String , Error < documents_api:: ImportDocumentsError > > {
121- params. collection_name = self . collection_name . to_string ( ) ;
122- params. body = documents_jsonl;
102+ let params = documents_api:: ImportDocumentsParams {
103+ body : documents_jsonl,
104+ collection_name : self . collection_name . to_string ( ) ,
105+
106+ action : params. action ,
107+ batch_size : params. batch_size ,
108+ dirty_values : params. dirty_values ,
109+ remote_embedding_batch_size : params. remote_embedding_batch_size ,
110+ return_doc : params. return_doc ,
111+ return_id : params. return_id ,
112+ } ;
123113
124114 self . client
125115 . execute ( |config : Arc < configuration:: Configuration > | {
@@ -132,13 +122,17 @@ impl<'a> Documents<'a> {
132122 /// Exports all documents in a collection in JSONL format.
133123 ///
134124 /// # Arguments
135- /// * `params` - An `ExportDocumentsParams` struct containing options like `filter_by` and `include_fields`.
136- /// The `collection_name` field will be overwritten.
125+ /// * `params` - An `ExportDocumentsParameters` struct containing options like `filter_by` and `include_fields`.
137126 pub async fn export (
138127 & self ,
139- mut params : documents_api :: ExportDocumentsParams ,
128+ params : ExportDocumentsParameters ,
140129 ) -> Result < String , Error < documents_api:: ExportDocumentsError > > {
141- params. collection_name = self . collection_name . to_string ( ) ;
130+ let params = documents_api:: ExportDocumentsParams {
131+ collection_name : self . collection_name . to_string ( ) ,
132+ exclude_fields : params. exclude_fields ,
133+ filter_by : params. filter_by ,
134+ include_fields : params. include_fields ,
135+ } ;
142136
143137 self . client
144138 . execute ( |config : Arc < configuration:: Configuration > | {
@@ -151,20 +145,18 @@ impl<'a> Documents<'a> {
151145 /// Deletes a batch of documents matching a specific filter condition.
152146 ///
153147 /// # Arguments
154- /// * `filter_by` - The filter condition for deleting documents.
155- /// * `batch_size` - The number of documents to delete at a time.
156- pub async fn delete_by_filter (
148+ /// * `params` - A `DeleteDocumentsParameters` describing the conditions for deleting documents.
149+ pub async fn delete (
157150 & self ,
158- filter_by : & str ,
159- batch_size : Option < i32 > ,
151+ params : DeleteDocumentsParameters ,
160152 ) -> Result < models:: DeleteDocuments200Response , Error < documents_api:: DeleteDocumentsError > >
161153 {
162154 let params = documents_api:: DeleteDocumentsParams {
163155 collection_name : self . collection_name . to_string ( ) ,
164- filter_by : Some ( filter_by . to_string ( ) ) ,
165- batch_size,
166- ignore_not_found : None ,
167- truncate : None ,
156+ filter_by : Some ( params . filter_by ) ,
157+ batch_size : params . batch_size ,
158+ ignore_not_found : params . ignore_not_found ,
159+ truncate : params . truncate ,
168160 } ;
169161 self . client
170162 . execute ( |config : Arc < configuration:: Configuration > | {
@@ -177,17 +169,17 @@ impl<'a> Documents<'a> {
177169 /// Updates a batch of documents matching a specific filter condition.
178170 ///
179171 /// # Arguments
180- /// * `filter_by` - The filter condition for updating documents.
181172 /// * `document` - A `serde_json::Value` containing the fields to update.
182- pub async fn update_by_filter (
173+ /// * `params` - A `UpdateDocumentsParameters` describing the conditions for updating documents.
174+ pub async fn update (
183175 & self ,
184- filter_by : & str ,
185176 document : serde_json:: Value ,
177+ params : UpdateDocumentsParameters ,
186178 ) -> Result < models:: UpdateDocuments200Response , Error < documents_api:: UpdateDocumentsError > >
187179 {
188180 let params = documents_api:: UpdateDocumentsParams {
189181 collection_name : self . collection_name . to_string ( ) ,
190- filter_by : Some ( filter_by . to_string ( ) ) ,
182+ filter_by : params . filter_by ,
191183 body : document,
192184 } ;
193185 self . client
0 commit comments