@@ -543,6 +543,97 @@ def browse_all(self, params=None):
543543 """
544544 return IndexIterator (self , params = params )
545545
546+ def save_synonym (self , content , object_id , forward_to_slaves = False ):
547+ """
548+ Add a synonym in this index.
549+
550+ @param content contains the synonyms set to add to the index.
551+ The object is represented by an associative array
552+ @param object_id unique identifier for the new synonym.
553+ If the identifier already exists, the old synonym is replaced
554+ @param forward_to_slaves (optional) should the changes be forwarded to
555+ slave indexes
556+ """
557+ path = '/synonyms/%s' % safe (object_id )
558+ params = {'forwardToSlaves' : forward_to_slaves }
559+ return self ._perform_request (self .write_hosts , path , 'PUT' ,
560+ body = content , params = params )
561+
562+ def batch_synonyms (self , synonyms , forward_to_slaves = False ,
563+ replace_existing_synonyms = False ):
564+ """
565+ Add several synonyms in this index.
566+
567+ @param synonyms array of synonyms to add
568+ @param forward_to_slaves (optional) should the changes be forwarded to
569+ slave indexes
570+ @param replace_existing_synonyms (optional) should the index be cleared
571+ of existing synonyms
572+ """
573+ params = {
574+ 'forwardToSlaves' : forward_to_slaves ,
575+ 'replaceExistingSynonyms' : replace_existing_synonyms
576+ }
577+
578+ return self ._perform_request (self .write_hosts , '/synonyms/batch' ,
579+ 'POST' , body = synonyms , params = params )
580+
581+ def get_synonym (self , object_id ):
582+ """
583+ Get a synonym from this index.
584+
585+ @param object_id unique identifier of the synonym to retrieve
586+ """
587+ path = '/synonyms/%s' % safe (object_id )
588+ return self ._perform_request (self .read_hosts , path , 'GET' )
589+
590+ def delete_synonym (self , object_id , forward_to_slaves = False ):
591+ """
592+ Delete a synonym from the index.
593+
594+ @param object_id the unique identifier of the synonyms set to delete
595+ @param forward_to_slaves (optional) should the changes be forwarded to
596+ slave indexes
597+ """
598+ path = '/synonyms/%s' % safe (object_id )
599+ params = {'forwardToSlaves' : forward_to_slaves }
600+ return self ._perform_request (self .write_hosts , path , 'DELETE' ,
601+ params = params )
602+
603+ def clear_synonyms (self , forward_to_slaves = False ):
604+ """
605+ Delete all synonyms from the index.
606+
607+ @param forward_to_slaves (optional) should the changes be forwarded to
608+ slave indexes
609+ """
610+ path = '/synonyms/clear'
611+ params = {'forwardToSlaves' : forward_to_slaves }
612+ return self ._perform_request (self .write_hosts , path , 'POST' ,
613+ params = params )
614+
615+ def search_synonyms (self , query , types = [], page = 0 , hits_per_page = 100 ):
616+ """
617+ Search for synonyms from this index.
618+
619+ @param query the full text query
620+ @param types (optional) the types of the synonyms to search for.
621+ @param page (optional integer) the page to fetch
622+ @param hits_per_page (optional integer) the number of hits per page
623+ """
624+ if isinstance (types , str ):
625+ types = [] if len (types ) == 0 else [types ]
626+
627+ body = {
628+ 'query' : query ,
629+ 'type' : ',' .join (types ),
630+ 'page' : page ,
631+ 'hitsPerPage' : hits_per_page
632+ }
633+
634+ return self ._perform_request (self .read_hosts , '/synonyms/search' ,
635+ 'POST' , body = body , is_search = True )
636+
546637 @deprecated
547638 def waitTask (self , task_id , time_before_retry = 100 ):
548639 return self .wait_task (task_id , time_before_retry )
@@ -569,7 +660,9 @@ def getSettings(self):
569660
570661 def get_settings (self ):
571662 """Get settings of this index."""
572- return self ._perform_request (self .read_hosts , '/settings' , 'GET' )
663+ params = {'getVersion' : 2 }
664+ return self ._perform_request (self .read_hosts , '/settings' , 'GET' ,
665+ params = params )
573666
574667 @deprecated
575668 def clearIndex (self ):
0 commit comments