@@ -7,7 +7,10 @@ use super::{Client, Error};
7
7
use std:: sync:: Arc ;
8
8
use typesense_codegen:: {
9
9
apis:: { configuration, documents_api} ,
10
- models,
10
+ models:: {
11
+ self , DeleteDocumentsParameters , ExportDocumentsParameters , ImportDocumentsParameters ,
12
+ UpdateDocumentsParameters ,
13
+ } ,
11
14
} ;
12
15
13
16
/// Provides methods for interacting with documents within a specific Typesense collection.
@@ -82,27 +85,6 @@ impl<'a> Documents<'a> {
82
85
self . index ( document, "upsert" ) . await
83
86
}
84
87
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
-
106
88
// --- Bulk Operation Methods ---
107
89
108
90
/// Imports a batch of documents in JSONL format.
@@ -111,15 +93,23 @@ impl<'a> Documents<'a> {
111
93
///
112
94
/// # Arguments
113
95
/// * `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`.
116
97
pub async fn import (
117
98
& self ,
118
99
documents_jsonl : String ,
119
- mut params : documents_api :: ImportDocumentsParams ,
100
+ params : ImportDocumentsParameters ,
120
101
) -> 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
+ } ;
123
113
124
114
self . client
125
115
. execute ( |config : Arc < configuration:: Configuration > | {
@@ -132,13 +122,17 @@ impl<'a> Documents<'a> {
132
122
/// Exports all documents in a collection in JSONL format.
133
123
///
134
124
/// # 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`.
137
126
pub async fn export (
138
127
& self ,
139
- mut params : documents_api :: ExportDocumentsParams ,
128
+ params : ExportDocumentsParameters ,
140
129
) -> 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
+ } ;
142
136
143
137
self . client
144
138
. execute ( |config : Arc < configuration:: Configuration > | {
@@ -151,20 +145,18 @@ impl<'a> Documents<'a> {
151
145
/// Deletes a batch of documents matching a specific filter condition.
152
146
///
153
147
/// # 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 (
157
150
& self ,
158
- filter_by : & str ,
159
- batch_size : Option < i32 > ,
151
+ params : DeleteDocumentsParameters ,
160
152
) -> Result < models:: DeleteDocuments200Response , Error < documents_api:: DeleteDocumentsError > >
161
153
{
162
154
let params = documents_api:: DeleteDocumentsParams {
163
155
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 ,
168
160
} ;
169
161
self . client
170
162
. execute ( |config : Arc < configuration:: Configuration > | {
@@ -177,17 +169,17 @@ impl<'a> Documents<'a> {
177
169
/// Updates a batch of documents matching a specific filter condition.
178
170
///
179
171
/// # Arguments
180
- /// * `filter_by` - The filter condition for updating documents.
181
172
/// * `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 (
183
175
& self ,
184
- filter_by : & str ,
185
176
document : serde_json:: Value ,
177
+ params : UpdateDocumentsParameters ,
186
178
) -> Result < models:: UpdateDocuments200Response , Error < documents_api:: UpdateDocumentsError > >
187
179
{
188
180
let params = documents_api:: UpdateDocumentsParams {
189
181
collection_name : self . collection_name . to_string ( ) ,
190
- filter_by : Some ( filter_by . to_string ( ) ) ,
182
+ filter_by : params . filter_by ,
191
183
body : document,
192
184
} ;
193
185
self . client
0 commit comments