@@ -82,7 +82,6 @@ def __init__(self, client, index_name):
8282 self .index_name = index_name
8383 self ._request_path = '/1/indexes/%s' % safe (self .index_name )
8484
85-
8685 @deprecated
8786 def addObject (self , content , object_id = None ):
8887 return self .add_object (content , object_id )
@@ -141,19 +140,20 @@ def get_object(self, object_id, attributes_to_retrieve=None):
141140 def getObjects (self , object_ids ):
142141 return self .get_objects (object_ids )
143142
144- def get_objects (self , object_ids ):
143+ def get_objects (self , object_ids , attributes_to_retrieve = None ):
145144 """
146145 Get several objects from this index.
147146
148147 @param object_ids the array of unique identifier of objects to retrieve
148+ @param attributes_to_retrieve (optional) if set, contains the list
149+ of attributes to retrieve as a string separated by a comma
149150 """
150-
151151 requests = []
152152 for object_id in object_ids :
153- requests . append ({
154- 'indexName' : self . index_name ,
155- 'objectID' : object_id
156- } )
153+ request = { 'indexName' : self . index_name , 'objectID' : object_id }
154+ if attributes_to_retrieve is not None :
155+ request [ 'attributesToRetrieve' ] = "," . join ( attributes_to_retrieve )
156+ requests . append ( request )
157157 data = {'requests' : requests }
158158 path = '/1/indexes/*/objects' # Use client._req()
159159 return self .client ._req (True , path , 'POST' , data = data )
@@ -162,26 +162,32 @@ def get_objects(self, object_ids):
162162 def partialUpdateObject (self , partial_object ):
163163 return self .partial_update_object (partial_object )
164164
165- def partial_update_object (self , partial_object ):
165+ def partial_update_object (self , partial_object , no_create = False ):
166166 """
167167 Update partially an object (only update attributes passed in argument).
168168
169169 @param partial_object contains the object attributes to override, the
170170 object must contains an objectID attribute
171+ @param no_create specifies whether or not a missing object must be
172+ created
171173 """
172174 path = '/%s/partial' % safe (partial_object ['objectID' ])
175+ if no_create :
176+ path += '?createIfNotExists=false'
173177 return self ._req (False , path , 'POST' , data = partial_object )
174178
175179 @deprecated
176180 def partialUpdateObjects (self , objects ):
177181 return self .partial_update_objects (objects )
178182
179- def partial_update_objects (self , objects ):
183+ def partial_update_objects (self , objects , no_create = False ):
180184 """
181185 Partially Override the content of several objects.
182186
183187 @param objects contains an array of objects to update (each object
184188 must contains a objectID attribute)
189+ @param no_create specifies whether or not a missing object must be
190+ created
185191 """
186192 requests = []
187193 for obj in objects :
@@ -190,7 +196,7 @@ def partial_update_objects(self, objects):
190196 'objectID' : obj ['objectID' ],
191197 'body' : obj
192198 })
193- return self .batch (requests )
199+ return self .batch (requests , no_create = no_create )
194200
195201 @deprecated
196202 def saveObject (self , obj ):
@@ -487,7 +493,7 @@ def search_disjunctive_faceting(self, query, disjunctive_facets,
487493 for i in range (1 , len (answers ['results' ])):
488494 for facet in answers ['results' ][i ]['facets' ]:
489495 aggregated_answer ['disjunctiveFacets' ][facet ] = (
490- answers ['results' ][i ]['facets' ][facet ])
496+ answers ['results' ][i ]['facets' ][facet ])
491497
492498 if facet not in disjunctive_refinements :
493499 continue
@@ -876,11 +882,15 @@ def update_user_key(self, key, obj, validity=None,
876882 path = '/keys/%s' % key
877883 return self ._req (False , path , 'PUT' , data = obj )
878884
879- def batch (self , requests ):
885+ def batch (self , requests , no_create = False ):
880886 """Send a batch requests."""
881887 if isinstance (requests , (list , tuple )):
882888 requests = {'requests' : requests }
883889
890+ path = '/batch'
891+ if no_create :
892+ path += '?createIfNotExists=false'
893+
884894 return self ._req (False , '/batch' , 'POST' , data = requests )
885895
886896 def _req (self , is_search , path , meth , params = None , data = None ):
0 commit comments