@@ -144,13 +144,13 @@ def __del__(self):
144
144
self .commit ()
145
145
146
146
def add_document (self , doc_id , nosave = False , score = 1.0 , payload = None ,
147
- replace = False , partial = False , ** fields ):
147
+ replace = False , partial = False , no_create = False , ** fields ):
148
148
"""
149
149
Add a document to the batch query
150
150
"""
151
151
self .client ._add_document (doc_id , conn = self .pipeline , nosave = nosave , score = score ,
152
152
payload = payload , replace = replace ,
153
- partial = partial , ** fields )
153
+ partial = partial , no_create = no_create , ** fields )
154
154
self .current_chunk += 1
155
155
self .total += 1
156
156
if self .current_chunk >= self .chunk_size :
@@ -232,14 +232,14 @@ def drop_index(self):
232
232
return self .redis .execute_command (self .DROP_CMD , self .index_name )
233
233
234
234
def _add_document (self , doc_id , conn = None , nosave = False , score = 1.0 , payload = None ,
235
- replace = False , partial = False , language = None , ** fields ):
235
+ replace = False , partial = False , language = None , no_create = False , ** fields ):
236
236
"""
237
237
Internal add_document used for both batch and single doc indexing
238
238
"""
239
239
if conn is None :
240
240
conn = self .redis
241
241
242
- if partial :
242
+ if partial or no_create :
243
243
replace = True
244
244
245
245
args = [self .ADD_CMD , self .index_name , doc_id , score ]
@@ -252,14 +252,16 @@ def _add_document(self, doc_id, conn=None, nosave=False, score=1.0, payload=None
252
252
args .append ('REPLACE' )
253
253
if partial :
254
254
args .append ('PARTIAL' )
255
+ if no_create :
256
+ args .append ('NOCREATE' )
255
257
if language :
256
258
args += ['LANGUAGE' , language ]
257
259
args .append ('FIELDS' )
258
260
args += list (itertools .chain (* fields .items ()))
259
261
return conn .execute_command (* args )
260
262
261
263
def add_document (self , doc_id , nosave = False , score = 1.0 , payload = None ,
262
- replace = False , partial = False , language = None , ** fields ):
264
+ replace = False , partial = False , language = None , no_create = False , ** fields ):
263
265
"""
264
266
Add a single document to the index.
265
267
@@ -274,12 +276,15 @@ def add_document(self, doc_id, nosave=False, score=1.0, payload=None,
274
276
This has the added benefit that any fields specified with `no_index`
275
277
will not be reindexed again. Implies `replace`
276
278
- **language**: Specify the language used for document tokenization.
279
+ - **no_create**: if True, the document is only updated and reindexed if it already exists.
280
+ If the document does not exist, an error will be returned. Implies `replace`
277
281
- **fields** kwargs dictionary of the document fields to be saved and/or indexed.
278
282
NOTE: Geo points shoule be encoded as strings of "lon,lat"
279
283
"""
280
284
return self ._add_document (doc_id , conn = None , nosave = nosave , score = score ,
281
285
payload = payload , replace = replace ,
282
- partial = partial , language = language , ** fields )
286
+ partial = partial , language = language ,
287
+ no_create = no_create ,** fields )
283
288
284
289
def delete_document (self , doc_id , conn = None ):
285
290
"""
0 commit comments