1010from azure .core .paging import ItemPaged
1111
1212from ._generated import SearchServiceClient as _SearchServiceClient
13- from ._generated .models import SynonymMap as _SynonymMap
1413from ._utils import (
1514 unpack_search_index ,
1615 pack_search_index ,
17- unpack_synonyms ,
18- pack_search_resource_encryption_key ,
16+ unpack_synonym_map ,
17+ pack_synonym_map ,
1918 get_access_conditions ,
2019 normalize_endpoint ,
2120)
@@ -55,7 +54,7 @@ def __exit__(self, *args):
5554
5655 def close (self ):
5756 # type: () -> None
58- """Close the :class:`~azure.search.documents.SearchIndexClient` session.
57+ """Close the :class:`~azure.search.documents.indexes. SearchIndexClient` session.
5958
6059 """
6160 return self ._client .close ()
@@ -77,7 +76,7 @@ def list_indexes(self, **kwargs):
7776 """List the indexes in an Azure Search service.
7877
7978 :return: List of indexes
80- :rtype: list[~azure.search.documents.SearchIndex]
79+ :rtype: list[~azure.search.documents.indexes.models. SearchIndex]
8180 :raises: ~azure.core.exceptions.HttpResponseError
8281
8382 """
@@ -86,14 +85,14 @@ def list_indexes(self, **kwargs):
8685 return self ._client .indexes .list (cls = lambda objs : [unpack_search_index (x ) for x in objs ], ** kwargs )
8786
8887 @distributed_trace
89- def get_index (self , index_name , ** kwargs ):
88+ def get_index (self , name , ** kwargs ):
9089 # type: (str, **Any) -> SearchIndex
9190 """
9291
93- :param index_name : The name of the index to retrieve.
94- :type index_name : str
92+ :param name : The name of the index to retrieve.
93+ :type name : str
9594 :return: SearchIndex object
96- :rtype: ~azure.search.documents.SearchIndex
95+ :rtype: ~azure.search.documents.indexes.models. SearchIndex
9796 :raises: ~azure.core.exceptions.HttpResponseError
9897
9998 .. admonition:: Example:
@@ -106,7 +105,7 @@ def get_index(self, index_name, **kwargs):
106105 :caption: Get an index.
107106 """
108107 kwargs ["headers" ] = self ._merge_client_headers (kwargs .get ("headers" ))
109- result = self ._client .indexes .get (index_name , ** kwargs )
108+ result = self ._client .indexes .get (name , ** kwargs )
110109 return unpack_search_index (result )
111110
112111 @distributed_trace
@@ -118,7 +117,7 @@ def get_index_statistics(self, index_name, **kwargs):
118117 :param index_name: The name of the index to retrieve.
119118 :type index_name: str
120119 :return: Statistics for the given index, including a document count and storage usage.
121- :rtype: ~azure.search.documents.GetIndexStatisticsResult
120+ :rtype: dict
122121 :raises: ~azure.core.exceptions.HttpResponseError
123122
124123 """
@@ -133,7 +132,7 @@ def delete_index(self, index, **kwargs):
133132 provided instead of the name to use the access conditions.
134133
135134 :param index: The index to retrieve.
136- :type index: str or ~search.models.SearchIndex
135+ :type index: str or ~azure. search.documents.indexes .models.SearchIndex
137136 :keyword match_condition: The match condition to use upon the etag
138137 :type match_condition: ~azure.core.MatchConditions
139138 :raises: ~azure.core.exceptions.HttpResponseError
@@ -166,9 +165,9 @@ def create_index(self, index, **kwargs):
166165 """Creates a new search index.
167166
168167 :param index: The index object.
169- :type index: ~azure.search.documents.SearchIndex
168+ :type index: ~azure.search.documents.indexes.models. SearchIndex
170169 :return: The index created
171- :rtype: ~azure.search.documents.SearchIndex
170+ :rtype: ~azure.search.documents.indexes.models. SearchIndex
172171 :raises: ~azure.core.exceptions.HttpResponseError
173172
174173 .. admonition:: Example:
@@ -187,15 +186,13 @@ def create_index(self, index, **kwargs):
187186
188187 @distributed_trace
189188 def create_or_update_index (
190- self , index_name , index , allow_index_downtime = None , ** kwargs
189+ self , index , allow_index_downtime = None , ** kwargs
191190 ):
192- # type: (str, SearchIndex, bool, **Any) -> SearchIndex
191+ # type: (SearchIndex, bool, **Any) -> SearchIndex
193192 """Creates a new search index or updates an index if it already exists.
194193
195- :param index_name: The name of the index.
196- :type index_name: str
197194 :param index: The index object.
198- :type index: ~azure.search.documents.SearchIndex
195+ :type index: ~azure.search.documents.indexes.models. SearchIndex
199196 :param allow_index_downtime: Allows new analyzers, tokenizers, token filters, or char filters
200197 to be added to an index by taking the index offline for at least a few seconds. This
201198 temporarily causes indexing and query requests to fail. Performance and write availability of
@@ -205,7 +202,7 @@ def create_or_update_index(
205202 :keyword match_condition: The match condition to use upon the etag
206203 :type match_condition: ~azure.core.MatchConditions
207204 :return: The index created or updated
208- :rtype: :class:`~azure.search.documents.SearchIndex`
205+ :rtype: :class:`~azure.search.documents.indexes.models. SearchIndex`
209206 :raises: :class:`~azure.core.exceptions.ResourceNotFoundError`, \
210207 :class:`~azure.core.exceptions.ResourceModifiedError`, \
211208 :class:`~azure.core.exceptions.ResourceNotModifiedError`, \
@@ -228,7 +225,7 @@ def create_or_update_index(
228225 kwargs .update (access_condition )
229226 patched_index = pack_search_index (index )
230227 result = self ._client .indexes .create_or_update (
231- index_name = index_name ,
228+ index_name = index . name ,
232229 index = patched_index ,
233230 allow_index_downtime = allow_index_downtime ,
234231 error_map = error_map ,
@@ -246,7 +243,7 @@ def analyze_text(self, index_name, analyze_request, **kwargs):
246243 :param analyze_request: The text and analyzer or analysis components to test.
247244 :type analyze_request: ~azure.search.documents.AnalyzeRequest
248245 :return: AnalyzeResult
249- :rtype: ~azure.search.documents.AnalyzeResult
246+ :rtype: ~azure.search.documents.indexes.models. AnalyzeResult
250247 :raises: ~azure.core.exceptions.HttpResponseError
251248
252249 .. admonition:: Example:
@@ -285,7 +282,7 @@ def get_synonym_maps(self, **kwargs):
285282 """
286283 kwargs ["headers" ] = self ._merge_client_headers (kwargs .get ("headers" ))
287284 result = self ._client .synonym_maps .list (** kwargs )
288- return [unpack_synonyms (x ) for x in result .synonym_maps ]
285+ return [unpack_synonym_map (x ) for x in result .synonym_maps ]
289286
290287 @distributed_trace
291288 def get_synonym_map_names (self , ** kwargs ):
@@ -324,7 +321,7 @@ def get_synonym_map(self, name, **kwargs):
324321 """
325322 kwargs ["headers" ] = self ._merge_client_headers (kwargs .get ("headers" ))
326323 result = self ._client .synonym_maps .get (name , ** kwargs )
327- return unpack_synonyms (result )
324+ return unpack_synonym_map (result )
328325
329326 @distributed_trace
330327 def delete_synonym_map (self , synonym_map , ** kwargs ):
@@ -334,7 +331,7 @@ def delete_synonym_map(self, synonym_map, **kwargs):
334331 the name of the synonym map to delete unconditionally.
335332
336333 :param name: The Synonym Map to delete
337- :type name: str or ~search.models.SynonymMap
334+ :type name: str or ~azure. search.documents.indexes .models.SynonymMap
338335 :keyword match_condition: The match condition to use upon the etag
339336 :type match_condition: ~azure.core.MatchConditions
340337 :return: None
@@ -364,14 +361,12 @@ def delete_synonym_map(self, synonym_map, **kwargs):
364361 )
365362
366363 @distributed_trace
367- def create_synonym_map (self , name , synonyms , ** kwargs ):
368- # type: (str, Sequence[str] , **Any) -> SynonymMap
364+ def create_synonym_map (self , synonym_map , ** kwargs ):
365+ # type: (SynonymMap , **Any) -> SynonymMap
369366 """Create a new Synonym Map in an Azure Search service
370367
371- :param name: The name of the Synonym Map to create
372- :type name: str
373- :param synonyms: The list of synonyms in SOLR format
374- :type synonyms: List[str]
368+ :param synonym_map: The Synonym Map object
369+ :type synonym_map: ~azure.search.documents.indexes.models.SynonymMap
375370 :return: The created Synonym Map
376371 :rtype: ~azure.search.documents.indexes.models.SynonymMap
377372
@@ -386,21 +381,18 @@ def create_synonym_map(self, name, synonyms, **kwargs):
386381
387382 """
388383 kwargs ["headers" ] = self ._merge_client_headers (kwargs .get ("headers" ))
389- solr_format_synonyms = "\n " .join (synonyms )
390- synonym_map = _SynonymMap (name = name , synonyms = solr_format_synonyms )
391- result = self ._client .synonym_maps .create (synonym_map , ** kwargs )
392- return unpack_synonyms (result )
384+ patched_synonym_map = pack_synonym_map (synonym_map )
385+ result = self ._client .synonym_maps .create (patched_synonym_map , ** kwargs )
386+ return unpack_synonym_map (result )
393387
394388 @distributed_trace
395- def create_or_update_synonym_map (self , synonym_map , synonyms = None , ** kwargs ):
396- # type: (Union[str, SynonymMap], Optional[Sequence[str]] , **Any) -> SynonymMap
389+ def create_or_update_synonym_map (self , synonym_map , ** kwargs ):
390+ # type: (SynonymMap, **Any) -> SynonymMap
397391 """Create a new Synonym Map in an Azure Search service, or update an
398392 existing one.
399393
400- :param synonym_map: The name of the Synonym Map to create or update
401- :type synonym_map: str or ~azure.search.documents.SynonymMap
402- :param synonyms: A list of synonyms in SOLR format
403- :type synonyms: List[str]
394+ :param synonym_map: The Synonym Map object
395+ :type synonym_map: ~azure.search.documents.indexes.models.SynonymMap
404396 :keyword match_condition: The match condition to use upon the etag
405397 :type match_condition: ~azure.core.MatchConditions
406398 :return: The created or updated Synonym Map
@@ -412,22 +404,14 @@ def create_or_update_synonym_map(self, synonym_map, synonyms=None, **kwargs):
412404 synonym_map , kwargs .pop ("match_condition" , MatchConditions .Unconditionally )
413405 )
414406 kwargs .update (access_condition )
415- try :
416- name = synonym_map .name
417- if synonyms :
418- synonym_map .synonyms = "\n " .join (synonyms )
419- synonym_map .encryption_key = pack_search_resource_encryption_key (synonym_map .encryption_key )
420- except AttributeError :
421- name = synonym_map
422- solr_format_synonyms = "\n " .join (synonyms )
423- synonym_map = _SynonymMap (name = name , synonyms = solr_format_synonyms )
407+ patched_synonym_map = pack_synonym_map (synonym_map )
424408 result = self ._client .synonym_maps .create_or_update (
425- synonym_map_name = name ,
426- synonym_map = synonym_map ,
409+ synonym_map_name = synonym_map . name ,
410+ synonym_map = patched_synonym_map ,
427411 error_map = error_map ,
428412 ** kwargs
429413 )
430- return unpack_synonyms (result )
414+ return unpack_synonym_map (result )
431415
432416 @distributed_trace
433417 def get_service_statistics (self , ** kwargs ):
0 commit comments