From 58030493693cb4cdd965fdb6a81135046045abdd Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 20 May 2020 19:05:39 -0700 Subject: [PATCH 01/12] synonym_maps_client & indexes_client --- .../documents/_service/_indexes_client.py | 199 --------- .../_service/_search_index_client.py | 418 ++++++++++++++++++ .../_service/_search_service_client.py | 17 - .../_service/_synonym_maps_client.py | 150 ------- .../tests/test_service_live.py | 39 +- 5 files changed, 438 insertions(+), 385 deletions(-) create mode 100644 sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_indexes_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_indexes_client.py index bd65a30a3b87..be259290bf21 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_indexes_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/_indexes_client.py @@ -59,202 +59,3 @@ def close(self): """ return self._client.close() - - @distributed_trace - def list_indexes(self, **kwargs): - # type: (**Any) -> ItemPaged[SearchIndex] - """List the indexes in an Azure Search service. - - :return: List of indexes - :rtype: list[~azure.search.documents.SearchIndex] - :raises: ~azure.core.exceptions.HttpResponseError - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - - def get_next(_token): - return self._client.indexes.list(**kwargs) - - def extract_data(response): - return None, [listize_flags_for_index(x) for x in response.indexes] - - return ItemPaged(get_next=get_next, extract_data=extract_data) - - @distributed_trace - def get_index(self, index_name, **kwargs): - # type: (str, **Any) -> SearchIndex - """ - - :param index_name: The name of the index to retrieve. - :type index_name: str - :return: SearchIndex object - :rtype: ~azure.search.documents.SearchIndex - :raises: ~azure.core.exceptions.HttpResponseError - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_index_crud_operations.py - :start-after: [START get_index] - :end-before: [END get_index] - :language: python - :dedent: 4 - :caption: Get an index. - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = self._client.indexes.get(index_name, **kwargs) - return listize_flags_for_index(result) - - @distributed_trace - def get_index_statistics(self, index_name, **kwargs): - # type: (str, **Any) -> dict - """Returns statistics for the given index, including a document count - and storage usage. - - :param index_name: The name of the index to retrieve. - :type index_name: str - :return: Statistics for the given index, including a document count and storage usage. - :rtype: ~azure.search.documents.GetIndexStatisticsResult - :raises: ~azure.core.exceptions.HttpResponseError - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = self._client.indexes.get_statistics(index_name, **kwargs) - return result.as_dict() - - @distributed_trace - def delete_index(self, index, **kwargs): - # type: (Union[str, SearchIndex], **Any) -> None - """Deletes a search index and all the documents it contains. The model must be - provided instead of the name to use the access conditions. - - :param index: The index to retrieve. - :type index: str or ~search.models.SearchIndex - :keyword match_condition: The match condition to use upon the etag - :type match_condition: ~azure.core.MatchConditions - :raises: ~azure.core.exceptions.HttpResponseError - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_index_crud_operations.py - :start-after: [START delete_index] - :end-before: [END delete_index] - :language: python - :dedent: 4 - :caption: Delete an index. - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - error_map, access_condition = get_access_conditions( - index, kwargs.pop("match_condition", MatchConditions.Unconditionally) - ) - kwargs.update(access_condition) - try: - index_name = index.name - except AttributeError: - index_name = index - self._client.indexes.delete( - index_name=index_name, error_map=error_map, **kwargs - ) - - @distributed_trace - def create_index(self, index, **kwargs): - # type: (SearchIndex, **Any) -> SearchIndex - """Creates a new search index. - - :param index: The index object. - :type index: ~azure.search.documents.SearchIndex - :return: The index created - :rtype: ~azure.search.documents.SearchIndex - :raises: ~azure.core.exceptions.HttpResponseError - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_index_crud_operations.py - :start-after: [START create_index] - :end-before: [END create_index] - :language: python - :dedent: 4 - :caption: Creating a new index. - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - patched_index = delistize_flags_for_index(index) - result = self._client.indexes.create(patched_index, **kwargs) - return result - - @distributed_trace - def create_or_update_index( - self, index_name, index, allow_index_downtime=None, **kwargs - ): - # type: (str, SearchIndex, bool, **Any) -> SearchIndex - """Creates a new search index or updates an index if it already exists. - - :param index_name: The name of the index. - :type index_name: str - :param index: The index object. - :type index: ~azure.search.documents.SearchIndex - :param allow_index_downtime: Allows new analyzers, tokenizers, token filters, or char filters - to be added to an index by taking the index offline for at least a few seconds. This - temporarily causes indexing and query requests to fail. Performance and write availability of - the index can be impaired for several minutes after the index is updated, or longer for very - large indexes. - :type allow_index_downtime: bool - :keyword match_condition: The match condition to use upon the etag - :type match_condition: ~azure.core.MatchConditions - :return: The index created or updated - :rtype: :class:`~azure.search.documents.SearchIndex` - :raises: :class:`~azure.core.exceptions.ResourceNotFoundError`, \ - :class:`~azure.core.exceptions.ResourceModifiedError`, \ - :class:`~azure.core.exceptions.ResourceNotModifiedError`, \ - :class:`~azure.core.exceptions.ResourceNotFoundError`, \ - :class:`~azure.core.exceptions.ResourceExistsError` - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_index_crud_operations.py - :start-after: [START update_index] - :end-before: [END update_index] - :language: python - :dedent: 4 - :caption: Update an index. - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - error_map, access_condition = get_access_conditions( - index, kwargs.pop("match_condition", MatchConditions.Unconditionally) - ) - kwargs.update(access_condition) - patched_index = delistize_flags_for_index(index) - result = self._client.indexes.create_or_update( - index_name=index_name, - index=patched_index, - allow_index_downtime=allow_index_downtime, - error_map=error_map, - **kwargs - ) - return result - - @distributed_trace - def analyze_text(self, index_name, analyze_request, **kwargs): - # type: (str, AnalyzeRequest, **Any) -> AnalyzeResult - """Shows how an analyzer breaks text into tokens. - - :param index_name: The name of the index for which to test an analyzer. - :type index_name: str - :param analyze_request: The text and analyzer or analysis components to test. - :type analyze_request: ~azure.search.documents.AnalyzeRequest - :return: AnalyzeResult - :rtype: ~azure.search.documents.AnalyzeResult - :raises: ~azure.core.exceptions.HttpResponseError - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_analyze_text.py - :start-after: [START simple_analyze_text] - :end-before: [END simple_analyze_text] - :language: python - :dedent: 4 - :caption: Analyze text - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = self._client.indexes.analyze( - index_name=index_name, request=analyze_request, **kwargs - ) - return result diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py new file mode 100644 index 000000000000..d9dcbc3b04b1 --- /dev/null +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py @@ -0,0 +1,418 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from azure.core import MatchConditions +from azure.core.tracing.decorator import distributed_trace +from azure.core.paging import ItemPaged + +from ._generated import SearchServiceClient as _SearchServiceClient +from ._generated.models import SynonymMap +from ._utils import ( + delistize_flags_for_index, + listize_flags_for_index, + listize_synonyms, + get_access_conditions, +) +from .._headers_mixin import HeadersMixin +from .._version import SDK_MONIKER + +if TYPE_CHECKING: + # pylint:disable=unused-import,ungrouped-imports + from typing import Any, Dict, List, Sequence, Union, Optional + from azure.core.credentials import AzureKeyCredential + + +class SearchIndexClient(HeadersMixin): + """A client to interact with Azure search service index. + + """ + + _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str + + def __init__(self, endpoint, credential, **kwargs): + # type: (str, AzureKeyCredential, **Any) -> None + + self._endpoint = endpoint # type: str + self._credential = credential # type: AzureKeyCredential + self._client = _SearchServiceClient( + endpoint=endpoint, sdk_moniker=SDK_MONIKER, **kwargs + ) # type: _SearchServiceClient + + def __enter__(self): + # type: () -> SearchIndexClient + self._client.__enter__() # pylint:disable=no-member + return self + + def __exit__(self, *args): + # type: (*Any) -> None + return self._client.__exit__(*args) # pylint:disable=no-member + + def close(self): + # type: () -> None + """Close the :class:`~azure.search.documents.SearchSynonymMapsClient` session. + + """ + return self._client.close() + + @distributed_trace + def list_indexes(self, **kwargs): + # type: (**Any) -> ItemPaged[SearchIndex] + """List the indexes in an Azure Search service. + + :return: List of indexes + :rtype: list[~azure.search.documents.SearchIndex] + :raises: ~azure.core.exceptions.HttpResponseError + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + + def get_next(_token): + return self._client.indexes.list(**kwargs) + + def extract_data(response): + return None, [listize_flags_for_index(x) for x in response.indexes] + + return ItemPaged(get_next=get_next, extract_data=extract_data) + + @distributed_trace + def get_index(self, index_name, **kwargs): + # type: (str, **Any) -> SearchIndex + """ + + :param index_name: The name of the index to retrieve. + :type index_name: str + :return: SearchIndex object + :rtype: ~azure.search.documents.SearchIndex + :raises: ~azure.core.exceptions.HttpResponseError + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_index_crud_operations.py + :start-after: [START get_index] + :end-before: [END get_index] + :language: python + :dedent: 4 + :caption: Get an index. + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = self._client.indexes.get(index_name, **kwargs) + return listize_flags_for_index(result) + + @distributed_trace + def get_index_statistics(self, index_name, **kwargs): + # type: (str, **Any) -> dict + """Returns statistics for the given index, including a document count + and storage usage. + + :param index_name: The name of the index to retrieve. + :type index_name: str + :return: Statistics for the given index, including a document count and storage usage. + :rtype: ~azure.search.documents.GetIndexStatisticsResult + :raises: ~azure.core.exceptions.HttpResponseError + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = self._client.indexes.get_statistics(index_name, **kwargs) + return result.as_dict() + + @distributed_trace + def delete_index(self, index, **kwargs): + # type: (Union[str, SearchIndex], **Any) -> None + """Deletes a search index and all the documents it contains. The model must be + provided instead of the name to use the access conditions. + + :param index: The index to retrieve. + :type index: str or ~search.models.SearchIndex + :keyword match_condition: The match condition to use upon the etag + :type match_condition: ~azure.core.MatchConditions + :raises: ~azure.core.exceptions.HttpResponseError + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_index_crud_operations.py + :start-after: [START delete_index] + :end-before: [END delete_index] + :language: python + :dedent: 4 + :caption: Delete an index. + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + error_map, access_condition = get_access_conditions( + index, kwargs.pop("match_condition", MatchConditions.Unconditionally) + ) + kwargs.update(access_condition) + try: + index_name = index.name + except AttributeError: + index_name = index + self._client.indexes.delete( + index_name=index_name, error_map=error_map, **kwargs + ) + + @distributed_trace + def create_index(self, index, **kwargs): + # type: (SearchIndex, **Any) -> SearchIndex + """Creates a new search index. + + :param index: The index object. + :type index: ~azure.search.documents.SearchIndex + :return: The index created + :rtype: ~azure.search.documents.SearchIndex + :raises: ~azure.core.exceptions.HttpResponseError + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_index_crud_operations.py + :start-after: [START create_index] + :end-before: [END create_index] + :language: python + :dedent: 4 + :caption: Creating a new index. + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + patched_index = delistize_flags_for_index(index) + result = self._client.indexes.create(patched_index, **kwargs) + return result + + @distributed_trace + def create_or_update_index( + self, index_name, index, allow_index_downtime=None, **kwargs + ): + # type: (str, SearchIndex, bool, **Any) -> SearchIndex + """Creates a new search index or updates an index if it already exists. + + :param index_name: The name of the index. + :type index_name: str + :param index: The index object. + :type index: ~azure.search.documents.SearchIndex + :param allow_index_downtime: Allows new analyzers, tokenizers, token filters, or char filters + to be added to an index by taking the index offline for at least a few seconds. This + temporarily causes indexing and query requests to fail. Performance and write availability of + the index can be impaired for several minutes after the index is updated, or longer for very + large indexes. + :type allow_index_downtime: bool + :keyword match_condition: The match condition to use upon the etag + :type match_condition: ~azure.core.MatchConditions + :return: The index created or updated + :rtype: :class:`~azure.search.documents.SearchIndex` + :raises: :class:`~azure.core.exceptions.ResourceNotFoundError`, \ + :class:`~azure.core.exceptions.ResourceModifiedError`, \ + :class:`~azure.core.exceptions.ResourceNotModifiedError`, \ + :class:`~azure.core.exceptions.ResourceNotFoundError`, \ + :class:`~azure.core.exceptions.ResourceExistsError` + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_index_crud_operations.py + :start-after: [START update_index] + :end-before: [END update_index] + :language: python + :dedent: 4 + :caption: Update an index. + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + error_map, access_condition = get_access_conditions( + index, kwargs.pop("match_condition", MatchConditions.Unconditionally) + ) + kwargs.update(access_condition) + patched_index = delistize_flags_for_index(index) + result = self._client.indexes.create_or_update( + index_name=index_name, + index=patched_index, + allow_index_downtime=allow_index_downtime, + error_map=error_map, + **kwargs + ) + return result + + @distributed_trace + def analyze_text(self, index_name, analyze_request, **kwargs): + # type: (str, AnalyzeRequest, **Any) -> AnalyzeResult + """Shows how an analyzer breaks text into tokens. + + :param index_name: The name of the index for which to test an analyzer. + :type index_name: str + :param analyze_request: The text and analyzer or analysis components to test. + :type analyze_request: ~azure.search.documents.AnalyzeRequest + :return: AnalyzeResult + :rtype: ~azure.search.documents.AnalyzeResult + :raises: ~azure.core.exceptions.HttpResponseError + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_analyze_text.py + :start-after: [START simple_analyze_text] + :end-before: [END simple_analyze_text] + :language: python + :dedent: 4 + :caption: Analyze text + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = self._client.indexes.analyze( + index_name=index_name, request=analyze_request, **kwargs + ) + return result + + @distributed_trace + def get_synonym_maps(self, **kwargs): + # type: (**Any) -> List[Dict[Any, Any]] + """List the Synonym Maps in an Azure Search service. + + :return: List of synonym maps + :rtype: list[dict] + :raises: ~azure.core.exceptions.HttpResponseError + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_synonym_map_operations.py + :start-after: [START get_synonym_maps] + :end-before: [END get_synonym_maps] + :language: python + :dedent: 4 + :caption: List Synonym Maps + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = self._client.synonym_maps.list(**kwargs) + return [listize_synonyms(x) for x in result.as_dict()["synonym_maps"]] + + @distributed_trace + def get_synonym_map(self, name, **kwargs): + # type: (str, **Any) -> dict + """Retrieve a named Synonym Map in an Azure Search service + + :param name: The name of the Synonym Map to get + :type name: str + :return: The retrieved Synonym Map + :rtype: dict + :raises: :class:`~azure.core.exceptions.ResourceNotFoundError` + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_synonym_map_operations.py + :start-after: [START get_synonym_map] + :end-before: [END get_synonym_map] + :language: python + :dedent: 4 + :caption: Get a Synonym Map + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = self._client.synonym_maps.get(name, **kwargs) + return listize_synonyms(result.as_dict()) + + @distributed_trace + def delete_synonym_map(self, synonym_map, **kwargs): + # type: (Union[str, SynonymMap], **Any) -> None + """Delete a named Synonym Map in an Azure Search service. To use access conditions, + the SynonymMap model must be provided instead of the name. It is enough to provide + the name of the synonym map to delete unconditionally. + + :param name: The Synonym Map to delete + :type name: str or ~search.models.SynonymMap + :keyword match_condition: The match condition to use upon the etag + :type match_condition: ~azure.core.MatchConditions + :return: None + :rtype: None + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_synonym_map_operations.py + :start-after: [START delete_synonym_map] + :end-before: [END delete_synonym_map] + :language: python + :dedent: 4 + :caption: Delete a Synonym Map + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + error_map, access_condition = get_access_conditions( + synonym_map, kwargs.pop("match_condition", MatchConditions.Unconditionally) + ) + kwargs.update(access_condition) + try: + name = synonym_map.name + except AttributeError: + name = synonym_map + self._client.synonym_maps.delete( + synonym_map_name=name, error_map=error_map, **kwargs + ) + + @distributed_trace + def create_synonym_map(self, name, synonyms, **kwargs): + # type: (str, Sequence[str], **Any) -> dict + """Create a new Synonym Map in an Azure Search service + + :param name: The name of the Synonym Map to create + :type name: str + :param synonyms: The list of synonyms in SOLR format + :type synonyms: List[str] + :return: The created Synonym Map + :rtype: dict + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_synonym_map_operations.py + :start-after: [START create_synonym_map] + :end-before: [END create_synonym_map] + :language: python + :dedent: 4 + :caption: Create a Synonym Map + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + solr_format_synonyms = "\n".join(synonyms) + synonym_map = SynonymMap(name=name, synonyms=solr_format_synonyms) + result = self._client.synonym_maps.create(synonym_map, **kwargs) + return listize_synonyms(result.as_dict()) + + @distributed_trace + def create_or_update_synonym_map(self, synonym_map, synonyms=None, **kwargs): + # type: (Union[str, SynonymMap], Optional[Sequence[str]], **Any) -> dict + """Create a new Synonym Map in an Azure Search service, or update an + existing one. + + :param synonym_map: The name of the Synonym Map to create or update + :type synonym_map: str or ~azure.search.documents.SynonymMap + :param synonyms: A list of synonyms in SOLR format + :type synonyms: List[str] + :keyword match_condition: The match condition to use upon the etag + :type match_condition: ~azure.core.MatchConditions + :return: The created or updated Synonym Map + :rtype: dict + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + error_map, access_condition = get_access_conditions( + synonym_map, kwargs.pop("match_condition", MatchConditions.Unconditionally) + ) + kwargs.update(access_condition) + try: + name = synonym_map.name + if synonyms: + synonym_map.synonyms = "\n".join(synonyms) + except AttributeError: + name = synonym_map + solr_format_synonyms = "\n".join(synonyms) + synonym_map = SynonymMap(name=name, synonyms=solr_format_synonyms) + result = self._client.synonym_maps.create_or_update( + synonym_map_name=name, + synonym_map=synonym_map, + error_map=error_map, + **kwargs + ) + return listize_synonyms(result.as_dict()) + + @distributed_trace + def get_service_statistics(self, **kwargs): + # type: (**Any) -> dict + """Get service level statistics for a search service. + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = self._client.get_service_statistics(**kwargs) + return result.as_dict() diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_service_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_service_client.py index 19fa5c3bbdec..50578cfd632e 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_service_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_service_client.py @@ -88,23 +88,6 @@ def get_service_statistics(self, **kwargs): result = self._client.get_service_statistics(**kwargs) return result.as_dict() - def get_indexes_client(self): - # type: () -> SearchIndexesClient - """Return a client to perform operations on Search Indexes. - - :return: The Search Indexes client - :rtype: SearchIndexesClient - """ - return self._indexes_client - - def get_synonym_maps_client(self): - # type: () -> SearchSynonymMapsClient - """Return a client to perform operations on Synonym Maps. - - :return: The Synonym Maps client - :rtype: SearchSynonymMapsClient - """ - return self._synonym_maps_client def get_skillsets_client(self): # type: () -> SearchSkillsetsClient diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_synonym_maps_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_synonym_maps_client.py index 965f173c666a..1981adfe7d6d 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_synonym_maps_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/_synonym_maps_client.py @@ -54,153 +54,3 @@ def close(self): """ return self._client.close() - - @distributed_trace - def get_synonym_maps(self, **kwargs): - # type: (**Any) -> List[Dict[Any, Any]] - """List the Synonym Maps in an Azure Search service. - - :return: List of synonym maps - :rtype: list[dict] - :raises: ~azure.core.exceptions.HttpResponseError - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_synonym_map_operations.py - :start-after: [START get_synonym_maps] - :end-before: [END get_synonym_maps] - :language: python - :dedent: 4 - :caption: List Synonym Maps - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = self._client.synonym_maps.list(**kwargs) - return [listize_synonyms(x) for x in result.as_dict()["synonym_maps"]] - - @distributed_trace - def get_synonym_map(self, name, **kwargs): - # type: (str, **Any) -> dict - """Retrieve a named Synonym Map in an Azure Search service - - :param name: The name of the Synonym Map to get - :type name: str - :return: The retrieved Synonym Map - :rtype: dict - :raises: :class:`~azure.core.exceptions.ResourceNotFoundError` - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_synonym_map_operations.py - :start-after: [START get_synonym_map] - :end-before: [END get_synonym_map] - :language: python - :dedent: 4 - :caption: Get a Synonym Map - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = self._client.synonym_maps.get(name, **kwargs) - return listize_synonyms(result.as_dict()) - - @distributed_trace - def delete_synonym_map(self, synonym_map, **kwargs): - # type: (Union[str, SynonymMap], **Any) -> None - """Delete a named Synonym Map in an Azure Search service. To use access conditions, - the SynonymMap model must be provided instead of the name. It is enough to provide - the name of the synonym map to delete unconditionally. - - :param name: The Synonym Map to delete - :type name: str or ~search.models.SynonymMap - :keyword match_condition: The match condition to use upon the etag - :type match_condition: ~azure.core.MatchConditions - :return: None - :rtype: None - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_synonym_map_operations.py - :start-after: [START delete_synonym_map] - :end-before: [END delete_synonym_map] - :language: python - :dedent: 4 - :caption: Delete a Synonym Map - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - error_map, access_condition = get_access_conditions( - synonym_map, kwargs.pop("match_condition", MatchConditions.Unconditionally) - ) - kwargs.update(access_condition) - try: - name = synonym_map.name - except AttributeError: - name = synonym_map - self._client.synonym_maps.delete( - synonym_map_name=name, error_map=error_map, **kwargs - ) - - @distributed_trace - def create_synonym_map(self, name, synonyms, **kwargs): - # type: (str, Sequence[str], **Any) -> dict - """Create a new Synonym Map in an Azure Search service - - :param name: The name of the Synonym Map to create - :type name: str - :param synonyms: The list of synonyms in SOLR format - :type synonyms: List[str] - :return: The created Synonym Map - :rtype: dict - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_synonym_map_operations.py - :start-after: [START create_synonym_map] - :end-before: [END create_synonym_map] - :language: python - :dedent: 4 - :caption: Create a Synonym Map - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - solr_format_synonyms = "\n".join(synonyms) - synonym_map = SynonymMap(name=name, synonyms=solr_format_synonyms) - result = self._client.synonym_maps.create(synonym_map, **kwargs) - return listize_synonyms(result.as_dict()) - - @distributed_trace - def create_or_update_synonym_map(self, synonym_map, synonyms=None, **kwargs): - # type: (Union[str, SynonymMap], Optional[Sequence[str]], **Any) -> dict - """Create a new Synonym Map in an Azure Search service, or update an - existing one. - - :param synonym_map: The name of the Synonym Map to create or update - :type synonym_map: str or ~azure.search.documents.SynonymMap - :param synonyms: A list of synonyms in SOLR format - :type synonyms: List[str] - :keyword match_condition: The match condition to use upon the etag - :type match_condition: ~azure.core.MatchConditions - :return: The created or updated Synonym Map - :rtype: dict - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - error_map, access_condition = get_access_conditions( - synonym_map, kwargs.pop("match_condition", MatchConditions.Unconditionally) - ) - kwargs.update(access_condition) - try: - name = synonym_map.name - if synonyms: - synonym_map.synonyms = "\n".join(synonyms) - except AttributeError: - name = synonym_map - solr_format_synonyms = "\n".join(synonyms) - synonym_map = SynonymMap(name=name, synonyms=solr_format_synonyms) - result = self._client.synonym_maps.create_or_update( - synonym_map_name=name, - synonym_map=synonym_map, - error_map=error_map, - **kwargs - ) - return listize_synonyms(result.as_dict()) diff --git a/sdk/search/azure-search-documents/tests/test_service_live.py b/sdk/search/azure-search-documents/tests/test_service_live.py index 08638d837af4..c534ecc1d952 100644 --- a/sdk/search/azure-search-documents/tests/test_service_live.py +++ b/sdk/search/azure-search-documents/tests/test_service_live.py @@ -35,6 +35,7 @@ SimpleField, edm ) +from azure.search.documents._service._search_index_client import SearchIndexClient from _test_utils import build_synonym_map_from_dict CWD = dirname(realpath(__file__)) @@ -48,7 +49,7 @@ class SearchClientTest(AzureMgmtTestCase): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer() def test_get_service_statistics(self, api_key, endpoint, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)) + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) result = client.get_service_statistics() assert isinstance(result, dict) assert set(result.keys()) == {"counters", "limits"} @@ -58,7 +59,7 @@ class SearchIndexesClientTest(AzureMgmtTestCase): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer() def test_list_indexes_empty(self, api_key, endpoint, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexes_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) result = client.list_indexes() with pytest.raises(StopIteration): next(result) @@ -66,7 +67,7 @@ def test_list_indexes_empty(self, api_key, endpoint, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_list_indexes(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexes_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) result = client.list_indexes() first = next(result) @@ -78,21 +79,21 @@ def test_list_indexes(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_get_index(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexes_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) result = client.get_index(index_name) assert result.name == index_name @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_get_index_statistics(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexes_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) result = client.get_index_statistics(index_name) assert set(result.keys()) == {'document_count', 'storage_size'} @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_delete_indexes(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexes_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) client.delete_index(index_name) import time if self.is_live: @@ -104,7 +105,7 @@ def test_delete_indexes(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_delete_indexes_if_unchanged(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexes_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) # First create an index name = "hotels" @@ -159,7 +160,7 @@ def test_create_index(self, api_key, endpoint, index_name, **kwargs): fields=fields, scoring_profiles=scoring_profiles, cors_options=cors_options) - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexes_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) result = client.create_index(index) assert result.name == "hotels" assert result.scoring_profiles[0].name == scoring_profile.name @@ -181,7 +182,7 @@ def test_create_or_update_index(self, api_key, endpoint, index_name, **kwargs): fields=fields, scoring_profiles=scoring_profiles, cors_options=cors_options) - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexes_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) result = client.create_or_update_index(index_name=index.name, index=index) assert len(result.scoring_profiles) == 0 assert result.cors_options.allowed_origins == cors_options.allowed_origins @@ -204,7 +205,7 @@ def test_create_or_update_index(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_create_or_update_indexes_if_unchanged(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexes_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) # First create an index name = "hotels" @@ -243,7 +244,7 @@ def test_create_or_update_indexes_if_unchanged(self, api_key, endpoint, index_na @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_analyze_text(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexes_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) analyze_request = AnalyzeRequest(text="One's ", analyzer="standard.lucene") result = client.analyze_text(index_name, analyze_request) assert len(result.tokens) == 2 @@ -252,7 +253,7 @@ class SearchSynonymMapsClientTest(AzureMgmtTestCase): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_create_synonym_map(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_synonym_maps_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) result = client.create_synonym_map("test-syn-map", [ "USA, United States, United States of America", "Washington, Wash. => WA", @@ -268,7 +269,7 @@ def test_create_synonym_map(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_delete_synonym_map(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_synonym_maps_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) result = client.create_synonym_map("test-syn-map", [ "USA, United States, United States of America", "Washington, Wash. => WA", @@ -280,7 +281,7 @@ def test_delete_synonym_map(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_delete_synonym_map_if_unchanged(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_synonym_maps_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) result = client.create_synonym_map("test-syn-map", [ "USA, United States, United States of America", "Washington, Wash. => WA", @@ -300,7 +301,7 @@ def test_delete_synonym_map_if_unchanged(self, api_key, endpoint, index_name, ** @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_get_synonym_map(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_synonym_maps_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) client.create_synonym_map("test-syn-map", [ "USA, United States, United States of America", "Washington, Wash. => WA", @@ -317,7 +318,7 @@ def test_get_synonym_map(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_get_synonym_maps(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_synonym_maps_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) client.create_synonym_map("test-syn-map-1", [ "USA, United States, United States of America", ]) @@ -332,7 +333,7 @@ def test_get_synonym_maps(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_create_or_update_synonym_map(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_synonym_maps_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) client.create_synonym_map("test-syn-map", [ "USA, United States, United States of America", ]) @@ -351,7 +352,7 @@ def test_create_or_update_synonym_map(self, api_key, endpoint, index_name, **kwa @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_create_or_update_synonym_map_if_unchanged(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_synonym_maps_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) result = build_synonym_map_from_dict(client.create_synonym_map("test-syn-map", [ "USA, United States, United States of America", ])) @@ -642,7 +643,7 @@ def _prepare_indexer(self, endpoint, api_key, name="sample-indexer", ds_name="sa "searchable": False }] index = SearchIndex(name=index_name, fields=fields) - ind = client.get_indexes_client().create_index(index) + ind = SearchIndexClient(endpoint, AzureKeyCredential(api_key)).create_index(index) return SearchIndexer(name=name, data_source_name=ds.name, target_index_name=ind.name) @SearchResourceGroupPreparer(random_name_enabled=True) From 2d148dd8ac51d7a96de5f20ad14489c351ba1ce8 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 20 May 2020 19:16:43 -0700 Subject: [PATCH 02/12] indexer, dataset & skillset --- .../documents/_service/_datasources_client.py | 130 ----- .../documents/_service/_indexers_client.py | 195 ------- .../_service/_search_indexer_client.py | 547 ++++++++++++++++++ .../documents/_service/_skillsets_client.py | 163 ------ .../tests/test_service_live.py | 57 +- 5 files changed, 576 insertions(+), 516 deletions(-) create mode 100644 sdk/search/azure-search-documents/azure/search/documents/_service/_search_indexer_client.py diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_datasources_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_datasources_client.py index 0f04fe5407f8..2c82a2d25dd8 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_datasources_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/_datasources_client.py @@ -55,133 +55,3 @@ def close(self): """ return self._client.close() - @distributed_trace - def create_datasource(self, data_source, **kwargs): - # type: (SearchIndexerDataSource, **Any) -> Dict[str, Any] - """Creates a new datasource. - - :param data_source: The definition of the datasource to create. - :type data_source: ~search.models.SearchIndexerDataSource - :return: The created SearchIndexerDataSource - :rtype: dict - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_data_source_operations.py - :start-after: [START create_data_source] - :end-before: [END create_data_source] - :language: python - :dedent: 4 - :caption: Create a Data Source - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = self._client.data_sources.create(data_source, **kwargs) - return result - - @distributed_trace - def create_or_update_datasource(self, data_source, name=None, **kwargs): - # type: (SearchIndexerDataSource, Optional[str], **Any) -> Dict[str, Any] - """Creates a new datasource or updates a datasource if it already exists. - :param name: The name of the datasource to create or update. - :type name: str - :param data_source: The definition of the datasource to create or update. - :type data_source: ~search.models.SearchIndexerDataSource - :keyword match_condition: The match condition to use upon the etag - :type match_condition: ~azure.core.MatchConditions - :return: The created SearchIndexerDataSource - :rtype: dict - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - error_map, access_condition = get_access_conditions( - data_source, kwargs.pop("match_condition", MatchConditions.Unconditionally) - ) - kwargs.update(access_condition) - if not name: - name = data_source.name - result = self._client.data_sources.create_or_update( - data_source_name=name, - data_source=data_source, - error_map=error_map, - **kwargs - ) - return result - - @distributed_trace - def get_datasource(self, name, **kwargs): - # type: (str, **Any) -> Dict[str, Any] - """Retrieves a datasource definition. - - :param name: The name of the datasource to retrieve. - :type name: str - :return: The SearchIndexerDataSource that is fetched. - :rtype: dict - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_data_source_operations.py - :start-after: [START get_data_source] - :end-before: [END get_data_source] - :language: python - :dedent: 4 - :caption: Retrieve a SearchIndexerDataSource - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = self._client.data_sources.get(name, **kwargs) - return result - - @distributed_trace - def get_datasources(self, **kwargs): - # type: (**Any) -> Sequence[SearchIndexerDataSource] - """Lists all datasources available for a search service. - - :return: List of all the data sources. - :rtype: `list[dict]` - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_data_source_operations.py - :start-after: [START list_data_source] - :end-before: [END list_data_source] - :language: python - :dedent: 4 - :caption: List all the SearchIndexerDataSources - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = self._client.data_sources.list(**kwargs) - return result.data_sources - - @distributed_trace - def delete_datasource(self, data_source, **kwargs): - # type: (Union[str, SearchIndexerDataSource], **Any) -> None - """Deletes a datasource. To use access conditions, the Datasource model must be - provided instead of the name. It is enough to provide the name of the datasource - to delete unconditionally - - :param data_source: The datasource to delete. - :type data_source: str or ~search.models.SearchIndexerDataSource - :keyword match_condition: The match condition to use upon the etag - :type match_condition: ~azure.core.MatchConditions - :return: None - :rtype: None - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_data_source_operations.py - :start-after: [START delete_data_source] - :end-before: [END delete_data_source] - :language: python - :dedent: 4 - :caption: Delete a SearchIndexerDataSource - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - error_map, access_condition = get_access_conditions( - data_source, kwargs.pop("match_condition", MatchConditions.Unconditionally) - ) - kwargs.update(access_condition) - try: - name = data_source.name - except AttributeError: - name = data_source - self._client.data_sources.delete( - data_source_name=name, error_map=error_map, **kwargs - ) diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_indexers_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_indexers_client.py index 38d1d81ff7bb..b0d81fda0323 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_indexers_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/_indexers_client.py @@ -54,198 +54,3 @@ def close(self): """ return self._client.close() - - @distributed_trace - def create_indexer(self, indexer, **kwargs): - # type: (SearchIndexer, **Any) -> SearchIndexer - """Creates a new SearchIndexer. - - :param indexer: The definition of the indexer to create. - :type indexer: ~~azure.search.documents.SearchIndexer - :return: The created SearchIndexer - :rtype: ~azure.search.documents.SearchIndexer - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_indexer_operations.py - :start-after: [START create_indexer] - :end-before: [END create_indexer] - :language: python - :dedent: 4 - :caption: Create a SearchIndexer - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = self._client.indexers.create(indexer, **kwargs) - return result - - @distributed_trace - def create_or_update_indexer(self, indexer, name=None, **kwargs): - # type: (SearchIndexer, Optional[str], **Any) -> SearchIndexer - """Creates a new indexer or updates a indexer if it already exists. - - :param name: The name of the indexer to create or update. - :type name: str - :param indexer: The definition of the indexer to create or update. - :type indexer: ~azure.search.documents.SearchIndexer - :return: The created IndexSearchIndexerer - :rtype: ~azure.search.documents.SearchIndexer - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - error_map, access_condition = get_access_conditions( - indexer, kwargs.pop("match_condition", MatchConditions.Unconditionally) - ) - kwargs.update(access_condition) - if not name: - name = indexer.name - result = self._client.indexers.create_or_update( - indexer_name=name, indexer=indexer, error_map=error_map, **kwargs - ) - return result - - @distributed_trace - def get_indexer(self, name, **kwargs): - # type: (str, **Any) -> SearchIndexer - """Retrieves a indexer definition. - - :param name: The name of the indexer to retrieve. - :type name: str - :return: The SearchIndexer that is fetched. - :rtype: ~azure.search.documents.SearchIndexer - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_indexer_operations.py - :start-after: [START get_indexer] - :end-before: [END get_indexer] - :language: python - :dedent: 4 - :caption: Retrieve a SearchIndexer - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = self._client.indexers.get(name, **kwargs) - return result - - @distributed_trace - def get_indexers(self, **kwargs): - # type: (**Any) -> Sequence[SearchIndexer] - """Lists all indexers available for a search service. - - :return: List of all the SearchIndexers. - :rtype: `list[dict]` - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_indexer_operations.py - :start-after: [START list_indexer] - :end-before: [END list_indexer] - :language: python - :dedent: 4 - :caption: List all the SearchIndexers - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = self._client.indexers.list(**kwargs) - return result.indexers - - @distributed_trace - def delete_indexer(self, indexer, **kwargs): - # type: (Union[str, SearchIndexer], **Any) -> None - """Deletes an indexer. To use access conditions, the SearchIndexer model - must be provided instead of the name. It is enough to provide - the name of the indexer to delete unconditionally. - - :param indexer: The indexer to delete. - :type indexer: str or ~azure.search.documents.SearchIndexer - :keyword match_condition: The match condition to use upon the etag - :type match_condition: ~azure.core.MatchConditions - - :return: None - :rtype: None - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_indexer_operations.py - :start-after: [START delete_indexer] - :end-before: [END delete_indexer] - :language: python - :dedent: 4 - :caption: Delete a SearchIndexer - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - error_map, access_condition = get_access_conditions( - indexer, kwargs.pop("match_condition", MatchConditions.Unconditionally) - ) - kwargs.update(access_condition) - try: - name = indexer.name - except AttributeError: - name = indexer - self._client.indexers.delete(name, error_map=error_map, **kwargs) - - @distributed_trace - def run_indexer(self, name, **kwargs): - # type: (str, **Any) -> None - """Run an indexer. - - :param name: The name of the indexer to run. - :type name: str - - :return: None - :rtype: None - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_indexer_operations.py - :start-after: [START run_indexer] - :end-before: [END run_indexer] - :language: python - :dedent: 4 - :caption: Run a SearchIndexer - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - self._client.indexers.run(name, **kwargs) - - @distributed_trace - def reset_indexer(self, name, **kwargs): - # type: (str, **Any) -> None - """Resets the change tracking state associated with an indexer. - - :param name: The name of the indexer to reset. - :type name: str - - :return: None - :rtype: None - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_indexer_operations.py - :start-after: [START reset_indexer] - :end-before: [END reset_indexer] - :language: python - :dedent: 4 - :caption: Reset a SearchIndexer's change tracking state - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - self._client.indexers.reset(name, **kwargs) - - @distributed_trace - def get_indexer_status(self, name, **kwargs): - # type: (str, **Any) -> SearchIndexerStatus - """Get the status of the indexer. - - :param name: The name of the indexer to fetch the status. - :type name: str - - :return: SearchIndexerStatus - :rtype: SearchIndexerStatus - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_indexer_operations.py - :start-after: [START get_indexer_status] - :end-before: [END get_indexer_status] - :language: python - :dedent: 4 - :caption: Get a SearchIndexer's status - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - return self._client.indexers.get_status(name, **kwargs) diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_indexer_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_indexer_client.py new file mode 100644 index 000000000000..98d6d60ff16d --- /dev/null +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_indexer_client.py @@ -0,0 +1,547 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from azure.core import MatchConditions +from azure.core.tracing.decorator import distributed_trace +from azure.core.exceptions import ClientAuthenticationError, ResourceNotFoundError + +from ._generated import SearchServiceClient as _SearchServiceClient +from ._generated.models import SearchIndexerSkillset +from ._utils import get_access_conditions +from .._headers_mixin import HeadersMixin +from .._version import SDK_MONIKER + +if TYPE_CHECKING: + # pylint:disable=unused-import,ungrouped-imports + from ._generated.models import SearchIndexer, SearchIndexerStatus + from typing import Any, Dict, Optional, Sequence + from azure.core.credentials import AzureKeyCredential + + +class SearchIndexerClient(HeadersMixin): + """A client to interact with Azure search service Indexers. + + This class is not normally instantiated directly, instead use + `get_indexers_client()` from a `SearchServiceClient` + + """ + + _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str + + def __init__(self, endpoint, credential, **kwargs): + # type: (str, AzureKeyCredential, **Any) -> None + + self._endpoint = endpoint # type: str + self._credential = credential # type: AzureKeyCredential + self._client = _SearchServiceClient( + endpoint=endpoint, sdk_moniker=SDK_MONIKER, **kwargs + ) # type: _SearchServiceClient + + def __enter__(self): + # type: () -> SearchIndexerClient + self._client.__enter__() # pylint:disable=no-member + return self + + def __exit__(self, *args): + # type: (*Any) -> None + return self._client.__exit__(*args) # pylint:disable=no-member + + def close(self): + # type: () -> None + """Close the :class:`~azure.search.documents.SearchIndexersClient` session. + + """ + return self._client.close() + + @distributed_trace + def create_indexer(self, indexer, **kwargs): + # type: (SearchIndexer, **Any) -> SearchIndexer + """Creates a new SearchIndexer. + + :param indexer: The definition of the indexer to create. + :type indexer: ~~azure.search.documents.SearchIndexer + :return: The created SearchIndexer + :rtype: ~azure.search.documents.SearchIndexer + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_indexer_operations.py + :start-after: [START create_indexer] + :end-before: [END create_indexer] + :language: python + :dedent: 4 + :caption: Create a SearchIndexer + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = self._client.indexers.create(indexer, **kwargs) + return result + + @distributed_trace + def create_or_update_indexer(self, indexer, name=None, **kwargs): + # type: (SearchIndexer, Optional[str], **Any) -> SearchIndexer + """Creates a new indexer or updates a indexer if it already exists. + + :param name: The name of the indexer to create or update. + :type name: str + :param indexer: The definition of the indexer to create or update. + :type indexer: ~azure.search.documents.SearchIndexer + :return: The created IndexSearchIndexerer + :rtype: ~azure.search.documents.SearchIndexer + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + error_map, access_condition = get_access_conditions( + indexer, kwargs.pop("match_condition", MatchConditions.Unconditionally) + ) + kwargs.update(access_condition) + if not name: + name = indexer.name + result = self._client.indexers.create_or_update( + indexer_name=name, indexer=indexer, error_map=error_map, **kwargs + ) + return result + + @distributed_trace + def get_indexer(self, name, **kwargs): + # type: (str, **Any) -> SearchIndexer + """Retrieves a indexer definition. + + :param name: The name of the indexer to retrieve. + :type name: str + :return: The SearchIndexer that is fetched. + :rtype: ~azure.search.documents.SearchIndexer + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_indexer_operations.py + :start-after: [START get_indexer] + :end-before: [END get_indexer] + :language: python + :dedent: 4 + :caption: Retrieve a SearchIndexer + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = self._client.indexers.get(name, **kwargs) + return result + + @distributed_trace + def get_indexers(self, **kwargs): + # type: (**Any) -> Sequence[SearchIndexer] + """Lists all indexers available for a search service. + + :return: List of all the SearchIndexers. + :rtype: `list[dict]` + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_indexer_operations.py + :start-after: [START list_indexer] + :end-before: [END list_indexer] + :language: python + :dedent: 4 + :caption: List all the SearchIndexers + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = self._client.indexers.list(**kwargs) + return result.indexers + + @distributed_trace + def delete_indexer(self, indexer, **kwargs): + # type: (Union[str, SearchIndexer], **Any) -> None + """Deletes an indexer. To use access conditions, the SearchIndexer model + must be provided instead of the name. It is enough to provide + the name of the indexer to delete unconditionally. + + :param indexer: The indexer to delete. + :type indexer: str or ~azure.search.documents.SearchIndexer + :keyword match_condition: The match condition to use upon the etag + :type match_condition: ~azure.core.MatchConditions + + :return: None + :rtype: None + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_indexer_operations.py + :start-after: [START delete_indexer] + :end-before: [END delete_indexer] + :language: python + :dedent: 4 + :caption: Delete a SearchIndexer + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + error_map, access_condition = get_access_conditions( + indexer, kwargs.pop("match_condition", MatchConditions.Unconditionally) + ) + kwargs.update(access_condition) + try: + name = indexer.name + except AttributeError: + name = indexer + self._client.indexers.delete(name, error_map=error_map, **kwargs) + + @distributed_trace + def run_indexer(self, name, **kwargs): + # type: (str, **Any) -> None + """Run an indexer. + + :param name: The name of the indexer to run. + :type name: str + + :return: None + :rtype: None + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_indexer_operations.py + :start-after: [START run_indexer] + :end-before: [END run_indexer] + :language: python + :dedent: 4 + :caption: Run a SearchIndexer + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + self._client.indexers.run(name, **kwargs) + + @distributed_trace + def reset_indexer(self, name, **kwargs): + # type: (str, **Any) -> None + """Resets the change tracking state associated with an indexer. + + :param name: The name of the indexer to reset. + :type name: str + + :return: None + :rtype: None + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_indexer_operations.py + :start-after: [START reset_indexer] + :end-before: [END reset_indexer] + :language: python + :dedent: 4 + :caption: Reset a SearchIndexer's change tracking state + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + self._client.indexers.reset(name, **kwargs) + + @distributed_trace + def get_indexer_status(self, name, **kwargs): + # type: (str, **Any) -> SearchIndexerStatus + """Get the status of the indexer. + + :param name: The name of the indexer to fetch the status. + :type name: str + + :return: SearchIndexerStatus + :rtype: SearchIndexerStatus + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_indexer_operations.py + :start-after: [START get_indexer_status] + :end-before: [END get_indexer_status] + :language: python + :dedent: 4 + :caption: Get a SearchIndexer's status + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + return self._client.indexers.get_status(name, **kwargs) + + @distributed_trace + def create_datasource(self, data_source, **kwargs): + # type: (SearchIndexerDataSource, **Any) -> Dict[str, Any] + """Creates a new datasource. + + :param data_source: The definition of the datasource to create. + :type data_source: ~search.models.SearchIndexerDataSource + :return: The created SearchIndexerDataSource + :rtype: dict + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_data_source_operations.py + :start-after: [START create_data_source] + :end-before: [END create_data_source] + :language: python + :dedent: 4 + :caption: Create a Data Source + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = self._client.data_sources.create(data_source, **kwargs) + return result + + @distributed_trace + def create_or_update_datasource(self, data_source, name=None, **kwargs): + # type: (SearchIndexerDataSource, Optional[str], **Any) -> Dict[str, Any] + """Creates a new datasource or updates a datasource if it already exists. + :param name: The name of the datasource to create or update. + :type name: str + :param data_source: The definition of the datasource to create or update. + :type data_source: ~search.models.SearchIndexerDataSource + :keyword match_condition: The match condition to use upon the etag + :type match_condition: ~azure.core.MatchConditions + :return: The created SearchIndexerDataSource + :rtype: dict + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + error_map, access_condition = get_access_conditions( + data_source, kwargs.pop("match_condition", MatchConditions.Unconditionally) + ) + kwargs.update(access_condition) + if not name: + name = data_source.name + result = self._client.data_sources.create_or_update( + data_source_name=name, + data_source=data_source, + error_map=error_map, + **kwargs + ) + return result + + @distributed_trace + def get_datasource(self, name, **kwargs): + # type: (str, **Any) -> Dict[str, Any] + """Retrieves a datasource definition. + + :param name: The name of the datasource to retrieve. + :type name: str + :return: The SearchIndexerDataSource that is fetched. + :rtype: dict + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_data_source_operations.py + :start-after: [START get_data_source] + :end-before: [END get_data_source] + :language: python + :dedent: 4 + :caption: Retrieve a SearchIndexerDataSource + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = self._client.data_sources.get(name, **kwargs) + return result + + @distributed_trace + def get_datasources(self, **kwargs): + # type: (**Any) -> Sequence[SearchIndexerDataSource] + """Lists all datasources available for a search service. + + :return: List of all the data sources. + :rtype: `list[dict]` + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_data_source_operations.py + :start-after: [START list_data_source] + :end-before: [END list_data_source] + :language: python + :dedent: 4 + :caption: List all the SearchIndexerDataSources + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = self._client.data_sources.list(**kwargs) + return result.data_sources + + @distributed_trace + def delete_datasource(self, data_source, **kwargs): + # type: (Union[str, SearchIndexerDataSource], **Any) -> None + """Deletes a datasource. To use access conditions, the Datasource model must be + provided instead of the name. It is enough to provide the name of the datasource + to delete unconditionally + + :param data_source: The datasource to delete. + :type data_source: str or ~search.models.SearchIndexerDataSource + :keyword match_condition: The match condition to use upon the etag + :type match_condition: ~azure.core.MatchConditions + :return: None + :rtype: None + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_data_source_operations.py + :start-after: [START delete_data_source] + :end-before: [END delete_data_source] + :language: python + :dedent: 4 + :caption: Delete a SearchIndexerDataSource + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + error_map, access_condition = get_access_conditions( + data_source, kwargs.pop("match_condition", MatchConditions.Unconditionally) + ) + kwargs.update(access_condition) + try: + name = data_source.name + except AttributeError: + name = data_source + self._client.data_sources.delete( + data_source_name=name, error_map=error_map, **kwargs + ) + + @distributed_trace + def get_skillsets(self, **kwargs): + # type: (**Any) -> List[SearchIndexerSkillset] + """List the SearchIndexerSkillsets in an Azure Search service. + + :return: List of SearchIndexerSkillsets + :rtype: list[dict] + :raises: ~azure.core.exceptions.HttpResponseError + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_skillset_operations.py + :start-after: [START get_skillsets] + :end-before: [END get_skillsets] + :language: python + :dedent: 4 + :caption: List SearchIndexerSkillsets + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = self._client.skillsets.list(**kwargs) + return result.skillsets + + @distributed_trace + def get_skillset(self, name, **kwargs): + # type: (str, **Any) -> SearchIndexerSkillset + """Retrieve a named SearchIndexerSkillset in an Azure Search service + + :param name: The name of the SearchIndexerSkillset to get + :type name: str + :return: The retrieved SearchIndexerSkillset + :rtype: dict + :raises: :class:`~azure.core.exceptions.ResourceNotFoundError` + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_skillset_operations.py + :start-after: [START get_skillset] + :end-before: [END get_skillset] + :language: python + :dedent: 4 + :caption: Get a SearchIndexerSkillset + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + return self._client.skillsets.get(name, **kwargs) + + @distributed_trace + def delete_skillset(self, skillset, **kwargs): + # type: (Union[str, SearchIndexerSkillset], **Any) -> None + """Delete a named SearchIndexerSkillset in an Azure Search service. To use access conditions, + the SearchIndexerSkillset model must be provided instead of the name. It is enough to provide + the name of the skillset to delete unconditionally + + :param name: The SearchIndexerSkillset to delete + :type name: str or ~search.models.SearchIndexerSkillset + :keyword match_condition: The match condition to use upon the etag + :type match_condition: ~azure.core.MatchConditions + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_skillset_operations.py + :start-after: [START delete_skillset] + :end-before: [END delete_skillset] + :language: python + :dedent: 4 + :caption: Delete a SearchIndexerSkillset + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + error_map, access_condition = get_access_conditions( + skillset, kwargs.pop("match_condition", MatchConditions.Unconditionally) + ) + kwargs.update(access_condition) + try: + name = skillset.name + except AttributeError: + name = skillset + self._client.skillsets.delete(name, error_map=error_map, **kwargs) + + @distributed_trace + def create_skillset(self, name, skills, description, **kwargs): + # type: (str, Sequence[SearchIndexerSkill], str, **Any) -> SearchIndexerSkillset + """Create a new SearchIndexerSkillset in an Azure Search service + + :param name: The name of the SearchIndexerSkillset to create + :type name: str + :param skills: A list of Skill objects to include in the SearchIndexerSkillset + :type skills: List[SearchIndexerSkill]] + :param description: A description for the SearchIndexerSkillset + :type description: Optional[str] + :return: The created SearchIndexerSkillset + :rtype: dict + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_skillset_operations.py + :start-after: [START create_skillset] + :end-before: [END create_skillset] + :language: python + :dedent: 4 + :caption: Create a SearchIndexerSkillset + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + + skillset = SearchIndexerSkillset( + name=name, skills=list(skills), description=description + ) + + return self._client.skillsets.create(skillset, **kwargs) + + @distributed_trace + def create_or_update_skillset(self, name, **kwargs): + # type: (str, **Any) -> SearchIndexerSkillset + """Create a new SearchIndexerSkillset in an Azure Search service, or update an + existing one. The skillset param must be provided to perform the + operation with access conditions. + + :param name: The name of the SearchIndexerSkillset to create or update + :type name: str + :keyword skills: A list of Skill objects to include in the SearchIndexerSkillset + :type skills: List[SearchIndexerSkill] + :keyword description: A description for the SearchIndexerSkillset + :type description: Optional[str] + :keyword skillset: A SearchIndexerSkillset to create or update. + :type skillset: :class:`~azure.search.documents.SearchIndexerSkillset` + :keyword match_condition: The match condition to use upon the etag + :type match_condition: ~azure.core.MatchConditions + :return: The created or updated SearchIndexerSkillset + :rtype: dict + + If a `skillset` is passed in, any optional `skills`, or + `description` parameter values will override it. + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError} + access_condition = None + + if "skillset" in kwargs: + skillset = kwargs.pop("skillset") + error_map, access_condition = get_access_conditions( + skillset, kwargs.pop("match_condition", MatchConditions.Unconditionally) + ) + kwargs.update(access_condition) + skillset = SearchIndexerSkillset.deserialize(skillset.serialize()) + skillset.name = name + for param in ("description", "skills"): + if param in kwargs: + setattr(skillset, param, kwargs.pop(param)) + else: + + skillset = SearchIndexerSkillset( + name=name, + description=kwargs.pop("description", None), + skills=kwargs.pop("skills", None), + ) + + return self._client.skillsets.create_or_update( + skillset_name=name, skillset=skillset, error_map=error_map, **kwargs + ) diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_skillsets_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_skillsets_client.py index c02a78bfe99b..b1ab80342d80 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_skillsets_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/_skillsets_client.py @@ -10,7 +10,6 @@ from azure.core.exceptions import ClientAuthenticationError, ResourceNotFoundError from ._generated import SearchServiceClient as _SearchServiceClient -from ._generated.models import SearchIndexerSkillset from ._utils import get_access_conditions from .._headers_mixin import HeadersMixin from .._version import SDK_MONIKER @@ -57,165 +56,3 @@ def close(self): """ return self._client.close() - @distributed_trace - def get_skillsets(self, **kwargs): - # type: (**Any) -> List[SearchIndexerSkillset] - """List the SearchIndexerSkillsets in an Azure Search service. - - :return: List of SearchIndexerSkillsets - :rtype: list[dict] - :raises: ~azure.core.exceptions.HttpResponseError - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_skillset_operations.py - :start-after: [START get_skillsets] - :end-before: [END get_skillsets] - :language: python - :dedent: 4 - :caption: List SearchIndexerSkillsets - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = self._client.skillsets.list(**kwargs) - return result.skillsets - - @distributed_trace - def get_skillset(self, name, **kwargs): - # type: (str, **Any) -> SearchIndexerSkillset - """Retrieve a named SearchIndexerSkillset in an Azure Search service - - :param name: The name of the SearchIndexerSkillset to get - :type name: str - :return: The retrieved SearchIndexerSkillset - :rtype: dict - :raises: :class:`~azure.core.exceptions.ResourceNotFoundError` - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_skillset_operations.py - :start-after: [START get_skillset] - :end-before: [END get_skillset] - :language: python - :dedent: 4 - :caption: Get a SearchIndexerSkillset - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - return self._client.skillsets.get(name, **kwargs) - - @distributed_trace - def delete_skillset(self, skillset, **kwargs): - # type: (Union[str, SearchIndexerSkillset], **Any) -> None - """Delete a named SearchIndexerSkillset in an Azure Search service. To use access conditions, - the SearchIndexerSkillset model must be provided instead of the name. It is enough to provide - the name of the skillset to delete unconditionally - - :param name: The SearchIndexerSkillset to delete - :type name: str or ~search.models.SearchIndexerSkillset - :keyword match_condition: The match condition to use upon the etag - :type match_condition: ~azure.core.MatchConditions - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_skillset_operations.py - :start-after: [START delete_skillset] - :end-before: [END delete_skillset] - :language: python - :dedent: 4 - :caption: Delete a SearchIndexerSkillset - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - error_map, access_condition = get_access_conditions( - skillset, kwargs.pop("match_condition", MatchConditions.Unconditionally) - ) - kwargs.update(access_condition) - try: - name = skillset.name - except AttributeError: - name = skillset - self._client.skillsets.delete(name, error_map=error_map, **kwargs) - - @distributed_trace - def create_skillset(self, name, skills, description, **kwargs): - # type: (str, Sequence[SearchIndexerSkill], str, **Any) -> SearchIndexerSkillset - """Create a new SearchIndexerSkillset in an Azure Search service - - :param name: The name of the SearchIndexerSkillset to create - :type name: str - :param skills: A list of Skill objects to include in the SearchIndexerSkillset - :type skills: List[SearchIndexerSkill]] - :param description: A description for the SearchIndexerSkillset - :type description: Optional[str] - :return: The created SearchIndexerSkillset - :rtype: dict - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_skillset_operations.py - :start-after: [START create_skillset] - :end-before: [END create_skillset] - :language: python - :dedent: 4 - :caption: Create a SearchIndexerSkillset - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - - skillset = SearchIndexerSkillset( - name=name, skills=list(skills), description=description - ) - - return self._client.skillsets.create(skillset, **kwargs) - - @distributed_trace - def create_or_update_skillset(self, name, **kwargs): - # type: (str, **Any) -> SearchIndexerSkillset - """Create a new SearchIndexerSkillset in an Azure Search service, or update an - existing one. The skillset param must be provided to perform the - operation with access conditions. - - :param name: The name of the SearchIndexerSkillset to create or update - :type name: str - :keyword skills: A list of Skill objects to include in the SearchIndexerSkillset - :type skills: List[SearchIndexerSkill] - :keyword description: A description for the SearchIndexerSkillset - :type description: Optional[str] - :keyword skillset: A SearchIndexerSkillset to create or update. - :type skillset: :class:`~azure.search.documents.SearchIndexerSkillset` - :keyword match_condition: The match condition to use upon the etag - :type match_condition: ~azure.core.MatchConditions - :return: The created or updated SearchIndexerSkillset - :rtype: dict - - If a `skillset` is passed in, any optional `skills`, or - `description` parameter values will override it. - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError} - access_condition = None - - if "skillset" in kwargs: - skillset = kwargs.pop("skillset") - error_map, access_condition = get_access_conditions( - skillset, kwargs.pop("match_condition", MatchConditions.Unconditionally) - ) - kwargs.update(access_condition) - skillset = SearchIndexerSkillset.deserialize(skillset.serialize()) - skillset.name = name - for param in ("description", "skills"): - if param in kwargs: - setattr(skillset, param, kwargs.pop(param)) - else: - - skillset = SearchIndexerSkillset( - name=name, - description=kwargs.pop("description", None), - skills=kwargs.pop("skills", None), - ) - - return self._client.skillsets.create_or_update( - skillset_name=name, skillset=skillset, error_map=error_map, **kwargs - ) diff --git a/sdk/search/azure-search-documents/tests/test_service_live.py b/sdk/search/azure-search-documents/tests/test_service_live.py index c534ecc1d952..f752a53360f3 100644 --- a/sdk/search/azure-search-documents/tests/test_service_live.py +++ b/sdk/search/azure-search-documents/tests/test_service_live.py @@ -36,6 +36,7 @@ edm ) from azure.search.documents._service._search_index_client import SearchIndexClient +from azure.search.documents._service._search_indexer_client import SearchIndexerClient from _test_utils import build_synonym_map_from_dict CWD = dirname(realpath(__file__)) @@ -372,7 +373,7 @@ class SearchSkillsetClientTest(AzureMgmtTestCase): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_create_skillset(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_skillsets_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) s = EntityRecognitionSkill(inputs=[InputFieldMappingEntry(name="text", source="/document/content")], outputs=[OutputFieldMappingEntry(name="organizations", target_name="organizations")]) @@ -390,7 +391,7 @@ def test_create_skillset(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_delete_skillset(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_skillsets_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) s = EntityRecognitionSkill(inputs=[InputFieldMappingEntry(name="text", source="/document/content")], outputs=[OutputFieldMappingEntry(name="organizations", target_name="organizations")]) @@ -403,7 +404,7 @@ def test_delete_skillset(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_delete_skillset_if_unchanged(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_skillsets_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) s = EntityRecognitionSkill(inputs=[InputFieldMappingEntry(name="text", source="/document/content")], outputs=[OutputFieldMappingEntry(name="organizations", target_name="organizations")]) @@ -419,7 +420,7 @@ def test_delete_skillset_if_unchanged(self, api_key, endpoint, index_name, **kwa @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_get_skillset(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_skillsets_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) s = EntityRecognitionSkill(inputs=[InputFieldMappingEntry(name="text", source="/document/content")], outputs=[OutputFieldMappingEntry(name="organizations", target_name="organizations")]) @@ -437,7 +438,7 @@ def test_get_skillset(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_get_skillsets(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_skillsets_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) s = EntityRecognitionSkill(inputs=[InputFieldMappingEntry(name="text", source="/document/content")], outputs=[OutputFieldMappingEntry(name="organizations", target_name="organizations")]) @@ -451,7 +452,7 @@ def test_get_skillsets(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_create_or_update_skillset(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_skillsets_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) s = EntityRecognitionSkill(inputs=[InputFieldMappingEntry(name="text", source="/document/content")], outputs=[OutputFieldMappingEntry(name="organizations", target_name="organizations")]) @@ -467,7 +468,7 @@ def test_create_or_update_skillset(self, api_key, endpoint, index_name, **kwargs @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_create_or_update_skillset_inplace(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_skillsets_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) s = EntityRecognitionSkill(inputs=[InputFieldMappingEntry(name="text", source="/document/content")], outputs=[OutputFieldMappingEntry(name="organizations", target_name="organizations")]) @@ -483,7 +484,7 @@ def test_create_or_update_skillset_inplace(self, api_key, endpoint, index_name, @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_create_or_update_skillset_if_unchanged(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_skillsets_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) s = EntityRecognitionSkill(inputs=[InputFieldMappingEntry(name="text", source="/document/content")], outputs=[OutputFieldMappingEntry(name="organizations", target_name="organizations")]) @@ -513,7 +514,7 @@ def _create_datasource(self, name="sample-datasource"): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_create_datasource(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_datasources_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) data_source = self._create_datasource() result = client.create_datasource(data_source) assert result.name == "sample-datasource" @@ -522,7 +523,7 @@ def test_create_datasource(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_delete_datasource(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_datasources_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) data_source = self._create_datasource() result = client.create_datasource(data_source) assert len(client.get_datasources()) == 1 @@ -532,7 +533,7 @@ def test_delete_datasource(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_get_datasource(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_datasources_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) data_source = self._create_datasource() created = client.create_datasource(data_source) result = client.get_datasource("sample-datasource") @@ -541,7 +542,7 @@ def test_get_datasource(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_list_datasource(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_datasources_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) data_source1 = self._create_datasource() data_source2 = self._create_datasource(name="another-sample") created1 = client.create_datasource(data_source1) @@ -553,7 +554,7 @@ def test_list_datasource(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_create_or_update_datasource(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_datasources_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) data_source = self._create_datasource() created = client.create_datasource(data_source) assert len(client.get_datasources()) == 1 @@ -567,7 +568,7 @@ def test_create_or_update_datasource(self, api_key, endpoint, index_name, **kwar @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_create_or_update_datasource_if_unchanged(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_datasources_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) data_source = self._create_datasource() created = client.create_datasource(data_source) etag = created.e_tag @@ -585,7 +586,7 @@ def test_create_or_update_datasource_if_unchanged(self, api_key, endpoint, index @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_delete_datasource_if_unchanged(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_datasources_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) data_source = self._create_datasource() created = client.create_datasource(data_source) etag = created.e_tag @@ -603,7 +604,7 @@ def test_delete_datasource_if_unchanged(self, api_key, endpoint, index_name, **k @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_delete_datasource_string_if_unchanged(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_datasources_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) data_source = self._create_datasource() created = client.create_datasource(data_source) etag = created.e_tag @@ -631,8 +632,8 @@ def _prepare_indexer(self, endpoint, api_key, name="sample-indexer", ds_name="sa credentials=credentials, container=container ) - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)) - ds = client.get_datasources_client().create_datasource(data_source) + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) + ds = client.create_datasource(data_source) index_name = id_name fields = [ @@ -649,7 +650,7 @@ def _prepare_indexer(self, endpoint, api_key, name="sample-indexer", ds_name="sa @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_create_indexer(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexers_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) indexer = self._prepare_indexer(endpoint, api_key) result = client.create_indexer(indexer) assert result.name == "sample-indexer" @@ -659,7 +660,7 @@ def test_create_indexer(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_delete_indexer(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexers_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) indexer = self._prepare_indexer(endpoint, api_key) result = client.create_indexer(indexer) assert len(client.get_indexers()) == 1 @@ -669,7 +670,7 @@ def test_delete_indexer(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_reset_indexer(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexers_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) indexer = self._prepare_indexer(endpoint, api_key) result = client.create_indexer(indexer) assert len(client.get_indexers()) == 1 @@ -679,7 +680,7 @@ def test_reset_indexer(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_run_indexer(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexers_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) indexer = self._prepare_indexer(endpoint, api_key) result = client.create_indexer(indexer) assert len(client.get_indexers()) == 1 @@ -690,7 +691,7 @@ def test_run_indexer(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_get_indexer(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexers_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) indexer = self._prepare_indexer(endpoint, api_key) created = client.create_indexer(indexer) result = client.get_indexer("sample-indexer") @@ -699,7 +700,7 @@ def test_get_indexer(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_list_indexer(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexers_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) indexer1 = self._prepare_indexer(endpoint, api_key) indexer2 = self._prepare_indexer(endpoint, api_key, name="another-indexer", ds_name="another-datasource", id_name="another-index") created1 = client.create_indexer(indexer1) @@ -711,7 +712,7 @@ def test_list_indexer(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_create_or_update_indexer(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexers_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) indexer = self._prepare_indexer(endpoint, api_key) created = client.create_indexer(indexer) assert len(client.get_indexers()) == 1 @@ -725,7 +726,7 @@ def test_create_or_update_indexer(self, api_key, endpoint, index_name, **kwargs) @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_get_indexer_status(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexers_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) indexer = self._prepare_indexer(endpoint, api_key) result = client.create_indexer(indexer) status = client.get_indexer_status("sample-indexer") @@ -734,7 +735,7 @@ def test_get_indexer_status(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_create_or_update_indexer_if_unchanged(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexers_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) indexer = self._prepare_indexer(endpoint, api_key) created = client.create_indexer(indexer) etag = created.e_tag @@ -750,7 +751,7 @@ def test_create_or_update_indexer_if_unchanged(self, api_key, endpoint, index_na @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) def test_delete_indexer_if_unchanged(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexers_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) indexer = self._prepare_indexer(endpoint, api_key) result = client.create_indexer(indexer) etag = result.e_tag From 69c9d9ff6d76c3bb2a22ba7c5184485e17f1296e Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 20 May 2020 19:34:58 -0700 Subject: [PATCH 03/12] async changes --- .../_service/aio/_datasources_client.py | 126 ---- .../_service/aio/_indexers_client.py | 195 ------- .../documents/_service/aio/_indexes_client.py | 199 ------- .../_service/aio/_search_index_client.py | 422 ++++++++++++++ .../_service/aio/_search_indexer_client.py | 541 ++++++++++++++++++ .../_service/aio/_skillsets_client.py | 163 ------ .../_service/aio/_synonym_maps_client.py | 150 ----- .../async_tests/test_service_live_async.py | 91 +-- 8 files changed, 1009 insertions(+), 878 deletions(-) create mode 100644 sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_index_client.py create mode 100644 sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_indexer_client.py diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_datasources_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_datasources_client.py index 25b6ccf36c40..b30973a2d89d 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_datasources_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_datasources_client.py @@ -55,129 +55,3 @@ async def close(self): """ return await self._client.close() - @distributed_trace_async - async def create_datasource(self, data_source, **kwargs): - # type: (SearchIndexerDataSource, **Any) -> Dict[str, Any] - """Creates a new datasource. - :param data_source: The definition of the datasource to create. - :type data_source: ~search.models.SearchIndexerDataSource - :return: The created SearchIndexerDataSource - :rtype: dict - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_data_source_operations_async.py - :start-after: [START create_data_source_async] - :end-before: [END create_data_source_async] - :language: python - :dedent: 4 - :caption: Create a SearchIndexerDataSource - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = await self._client.data_sources.create(data_source, **kwargs) - return result - - @distributed_trace_async - async def create_or_update_datasource(self, data_source, name=None, **kwargs): - # type: (SearchIndexerDataSource, Optional[str], **Any) -> Dict[str, Any] - """Creates a new datasource or updates a datasource if it already exists. - :param name: The name of the datasource to create or update. - :type name: str - :param data_source: The definition of the datasource to create or update. - :type data_source: ~search.models.SearchIndexerDataSource - :keyword match_condition: The match condition to use upon the etag - :type match_condition: ~azure.core.MatchConditions - :return: The created SearchIndexerDataSource - :rtype: dict - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - error_map, access_condition = get_access_conditions( - data_source, kwargs.pop("match_condition", MatchConditions.Unconditionally) - ) - kwargs.update(access_condition) - if not name: - name = data_source.name - result = await self._client.data_sources.create_or_update( - data_source_name=name, - data_source=data_source, - error_map=error_map, - **kwargs - ) - return result - - @distributed_trace_async - async def delete_datasource(self, data_source, **kwargs): - # type: (Union[str, SearchIndexerDataSource], **Any) -> None - """Deletes a datasource. To use access conditions, the Datasource model must be - provided instead of the name. It is enough to provide the name of the datasource - to delete unconditionally - - :param data_source: The datasource to delete. - :type data_source: str or ~search.models.SearchIndexerDataSource - :keyword match_condition: The match condition to use upon the etag - :type match_condition: ~azure.core.MatchConditions - :return: None - :rtype: None - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_data_source_operations_async.py - :start-after: [START delete_data_source_async] - :end-before: [END delete_data_source_async] - :language: python - :dedent: 4 - :caption: Delete a SearchIndexerDataSource - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - error_map, access_condition = get_access_conditions( - data_source, kwargs.pop("match_condition", MatchConditions.Unconditionally) - ) - kwargs.update(access_condition) - try: - name = data_source.name - except AttributeError: - name = data_source - await self._client.data_sources.delete( - data_source_name=name, error_map=error_map, **kwargs - ) - - @distributed_trace_async - async def get_datasource(self, name, **kwargs): - # type: (str, **Any) -> Dict[str, Any] - """Retrieves a datasource definition. - - :param name: The name of the datasource to retrieve. - :type name: str - :return: The SearchIndexerDataSource that is fetched. - - .. literalinclude:: ../samples/async_samples/sample_data_source_operations_async.py - :start-after: [START get_data_source_async] - :end-before: [END get_data_source_async] - :language: python - :dedent: 4 - :caption: Retrieve a SearchIndexerDataSource - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = await self._client.data_sources.get(name, **kwargs) - return result - - @distributed_trace_async - async def get_datasources(self, **kwargs): - # type: (**Any) -> Sequence[SearchIndexerDataSource] - """Lists all datasources available for a search service. - - :return: List of all the data sources. - :rtype: `list[dict]` - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_data_source_operations_async.py - :start-after: [START list_data_source_async] - :end-before: [END list_data_source_async] - :language: python - :dedent: 4 - :caption: List all SearchIndexerDataSources - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = await self._client.data_sources.list(**kwargs) - return result.data_sources diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_indexers_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_indexers_client.py index cba6743bffcf..c6a1a0f3e7dd 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_indexers_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_indexers_client.py @@ -54,198 +54,3 @@ async def close(self): """ return await self._client.close() - - @distributed_trace_async - async def create_indexer(self, indexer, **kwargs): - # type: (SearchIndexer, **Any) -> SearchIndexer - """Creates a new SearchIndexer. - - :param indexer: The definition of the indexer to create. - :type indexer: ~azure.search.documents.SearchIndexer - :return: The created SearchIndexer - :rtype: dict - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_indexer_operations_async.py - :start-after: [START create_indexer_async] - :end-before: [END create_indexer_async] - :language: python - :dedent: 4 - :caption: Create a SearchIndexer - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = await self._client.indexers.create(indexer, **kwargs) - return result - - @distributed_trace_async - async def create_or_update_indexer(self, indexer, name=None, **kwargs): - # type: (SearchIndexer, Optional[str], **Any) -> SearchIndexer - """Creates a new indexer or updates a indexer if it already exists. - - :param name: The name of the indexer to create or update. - :type name: str - :param indexer: The definition of the indexer to create or update. - :type indexer: ~azure.search.documents.SearchIndexer - :return: The created SearchIndexer - :rtype: dict - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - error_map, access_condition = get_access_conditions( - indexer, kwargs.pop("match_condition", MatchConditions.Unconditionally) - ) - kwargs.update(access_condition) - if not name: - name = indexer.name - result = await self._client.indexers.create_or_update( - indexer_name=name, indexer=indexer, error_map=error_map, **kwargs - ) - return result - - @distributed_trace_async - async def get_indexer(self, name, **kwargs): - # type: (str, **Any) -> SearchIndexer - """Retrieves a indexer definition. - - :param name: The name of the indexer to retrieve. - :type name: str - :return: The SearchIndexer that is fetched. - :rtype: dict - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_indexer_operations_async.py - :start-after: [START get_indexer_async] - :end-before: [END get_indexer_async] - :language: python - :dedent: 4 - :caption: Retrieve a SearchIndexer - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = await self._client.indexers.get(name, **kwargs) - return result - - @distributed_trace_async - async def get_indexers(self, **kwargs): - # type: (**Any) -> Sequence[SearchIndexer] - """Lists all indexers available for a search service. - - :return: List of all the SearchIndexers. - :rtype: `list[dict]` - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_indexer_operations_async.py - :start-after: [START list_indexer_async] - :end-before: [END list_indexer_async] - :language: python - :dedent: 4 - :caption: List all the SearchIndexers - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = await self._client.indexers.list(**kwargs) - return result.indexers - - @distributed_trace_async - async def delete_indexer(self, indexer, **kwargs): - # type: (Union[str, SearchIndexer], **Any) -> None - """Deletes an indexer. To use access conditions, the SearchIndexer model - must be provided instead of the name. It is enough to provide - the name of the indexer to delete unconditionally. - - :param name: The name of the indexer to delete. - :type name: str - :keyword match_condition: The match condition to use upon the etag - :type match_condition: ~azure.core.MatchConditions - - :return: None - :rtype: None - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_indexer_operations_async.py - :start-after: [START delete_indexer_async] - :end-before: [END delete_indexer_async] - :language: python - :dedent: 4 - :caption: Delete a SearchIndexer - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - error_map, access_condition = get_access_conditions( - indexer, kwargs.pop("match_condition", MatchConditions.Unconditionally) - ) - kwargs.update(access_condition) - try: - name = indexer.name - except AttributeError: - name = indexer - await self._client.indexers.delete(name, error_map=error_map, **kwargs) - - @distributed_trace_async - async def run_indexer(self, name, **kwargs): - # type: (str, **Any) -> None - """Run an indexer. - - :param name: The name of the indexer to run. - :type name: str - - :return: None - :rtype: None - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_indexer_operations_async.py - :start-after: [START run_indexer_async] - :end-before: [END run_indexer_async] - :language: python - :dedent: 4 - :caption: Run a SearchIndexer - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - await self._client.indexers.run(name, **kwargs) - - @distributed_trace_async - async def reset_indexer(self, name, **kwargs): - # type: (str, **Any) -> None - """Resets the change tracking state associated with an indexer. - - :param name: The name of the indexer to reset. - :type name: str - - :return: None - :rtype: None - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_indexer_operations_async.py - :start-after: [START reset_indexer_async] - :end-before: [END reset_indexer_async] - :language: python - :dedent: 4 - :caption: Reset a SearchIndexer's change tracking state - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - await self._client.indexers.reset(name, **kwargs) - - @distributed_trace_async - async def get_indexer_status(self, name, **kwargs): - # type: (str, **Any) -> SearchIndexerStatus - """Get the status of the indexer. - - :param name: The name of the indexer to fetch the status. - :type name: str - - :return: SearchIndexerStatus - :rtype: SearchIndexerStatus - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_indexer_operations_async.py - :start-after: [START get_indexer_status_async] - :end-before: [END get_indexer_status_async] - :language: python - :dedent: 4 - :caption: Get a SearchIndexer's status - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - return await self._client.indexers.get_status(name, **kwargs) diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_indexes_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_indexes_client.py index 19cdd6bc2daf..8c0e5ab71ab2 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_indexes_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_indexes_client.py @@ -58,202 +58,3 @@ async def close(self): """ return await self._client.close() - - @distributed_trace_async - async def list_indexes(self, **kwargs): - # type: (**Any) -> AsyncItemPaged[SearchIndex] - """List the indexes in an Azure Search service. - - :return: List of indexes - :rtype: list[~azure.search.documents.SearchIndex] - :raises: ~azure.core.exceptions.HttpResponseError - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - - async def get_next(_token): - return await self._client.indexes.list(**kwargs) - - async def extract_data(response): - return None, [listize_flags_for_index(x) for x in response.indexes] - - return AsyncItemPaged(get_next=get_next, extract_data=extract_data) - - @distributed_trace_async - async def get_index(self, index_name, **kwargs): - # type: (str, **Any) -> SearchIndex - """ - - :param index_name: The name of the index to retrieve. - :type index_name: str - :return: SearchIndex object - :rtype: ~azure.search.documents.SearchIndex - :raises: ~azure.core.exceptions.HttpResponseError - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_index_crud_operations_async.py - :start-after: [START get_index_async] - :end-before: [END get_index_async] - :language: python - :dedent: 4 - :caption: Get an index. - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = await self._client.indexes.get(index_name, **kwargs) - return listize_flags_for_index(result) - - @distributed_trace_async - async def get_index_statistics(self, index_name, **kwargs): - # type: (str, **Any) -> dict - """Returns statistics for the given index, including a document count - and storage usage. - - :param index_name: The name of the index to retrieve. - :type index_name: str - :return: Statistics for the given index, including a document count and storage usage. - :rtype: ~azure.search.documents.GetIndexStatisticsResult - :raises: ~azure.core.exceptions.HttpResponseError - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = await self._client.indexes.get_statistics(index_name, **kwargs) - return result.as_dict() - - @distributed_trace_async - async def delete_index(self, index, **kwargs): - # type: (Union[str, SearchIndex], **Any) -> None - """Deletes a search index and all the documents it contains. The model must be - provided instead of the name to use the access conditions - - :param index: The index to retrieve. - :type index: str or ~search.models.SearchIndex - :keyword match_condition: The match condition to use upon the etag - :type match_condition: ~azure.core.MatchConditions - :raises: ~azure.core.exceptions.HttpResponseError - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_index_crud_operations_async.py - :start-after: [START delete_index_async] - :end-before: [END delete_index_async] - :language: python - :dedent: 4 - :caption: Delete an index. - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - error_map, access_condition = get_access_conditions( - index, kwargs.pop("match_condition", MatchConditions.Unconditionally) - ) - kwargs.update(access_condition) - try: - index_name = index.name - except AttributeError: - index_name = index - await self._client.indexes.delete( - index_name=index_name, error_map=error_map, **kwargs - ) - - @distributed_trace_async - async def create_index(self, index, **kwargs): - # type: (SearchIndex, **Any) -> SearchIndex - """Creates a new search index. - - :param index: The index object. - :type index: ~azure.search.documents.SearchIndex - :return: The index created - :rtype: ~azure.search.documents.SearchIndex - :raises: ~azure.core.exceptions.HttpResponseError - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_index_crud_operations_async.py - :start-after: [START create_index_async] - :end-before: [END create_index_async] - :language: python - :dedent: 4 - :caption: Creating a new index. - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - patched_index = delistize_flags_for_index(index) - result = await self._client.indexes.create(patched_index, **kwargs) - return result - - @distributed_trace_async - async def create_or_update_index( - self, index_name, index, allow_index_downtime=None, **kwargs - ): - # type: (str, SearchIndex, bool, MatchConditions, **Any) -> SearchIndex - """Creates a new search index or updates an index if it already exists. - - :param index_name: The name of the index. - :type index_name: str - :param index: The index object. - :type index: ~azure.search.documents.SearchIndex - :param allow_index_downtime: Allows new analyzers, tokenizers, token filters, or char filters - to be added to an index by taking the index offline for at least a few seconds. This - temporarily causes indexing and query requests to fail. Performance and write availability of - the index can be impaired for several minutes after the index is updated, or longer for very - large indexes. - :type allow_index_downtime: bool - :keyword match_condition: The match condition to use upon the etag - :type match_condition: ~azure.core.MatchConditions - :return: The index created or updated - :rtype: :class:`~azure.search.documents.SearchIndex` - :raises: :class:`~azure.core.exceptions.ResourceNotFoundError`, \ - :class:`~azure.core.exceptions.ResourceModifiedError`, \ - :class:`~azure.core.exceptions.ResourceNotModifiedError`, \ - :class:`~azure.core.exceptions.ResourceNotFoundError`, \ - :class:`~azure.core.exceptions.ResourceExistsError` - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_index_crud_operations_async.py - :start-after: [START update_index_async] - :end-before: [END update_index_async] - :language: python - :dedent: 4 - :caption: Update an index. - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - error_map, access_condition = get_access_conditions( - index, kwargs.pop("match_condition", MatchConditions.Unconditionally) - ) - kwargs.update(access_condition) - patched_index = delistize_flags_for_index(index) - result = await self._client.indexes.create_or_update( - index_name=index_name, - index=patched_index, - allow_index_downtime=allow_index_downtime, - error_map=error_map, - **kwargs - ) - return result - - @distributed_trace_async - async def analyze_text(self, index_name, analyze_request, **kwargs): - # type: (str, AnalyzeRequest, **Any) -> AnalyzeResult - """Shows how an analyzer breaks text into tokens. - - :param index_name: The name of the index for which to test an analyzer. - :type index_name: str - :param analyze_request: The text and analyzer or analysis components to test. - :type analyze_request: ~azure.search.documents.AnalyzeRequest - :return: AnalyzeResult - :rtype: ~azure.search.documents.AnalyzeResult - :raises: ~azure.core.exceptions.HttpResponseError - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_analyze_text_async.py - :start-after: [START simple_analyze_text_async] - :end-before: [END simple_analyze_text_async] - :language: python - :dedent: 4 - :caption: Analyze text - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = await self._client.indexes.analyze( - index_name=index_name, request=analyze_request, **kwargs - ) - return result diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_index_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_index_client.py new file mode 100644 index 000000000000..3a85114fbaaf --- /dev/null +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_index_client.py @@ -0,0 +1,422 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from azure.core import MatchConditions +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.core.async_paging import AsyncItemPaged +from .._generated.aio import SearchServiceClient as _SearchServiceClient +from .._generated.models import SynonymMap +from .._utils import ( + delistize_flags_for_index, + listize_flags_for_index, + listize_synonyms, + get_access_conditions, +) +from ..._headers_mixin import HeadersMixin +from ..._version import SDK_MONIKER + +if TYPE_CHECKING: + # pylint:disable=unused-import,ungrouped-imports + from .._generated.models import AnalyzeRequest, AnalyzeResult, SearchIndex + from typing import Any, Dict, List, Union + from azure.core.credentials import AzureKeyCredential + + +class SearchIndexClient(HeadersMixin): + """A client to interact with Azure search service Indexes. + + This class is not normally instantiated directly, instead use + `get_skillsets_client()` from a `SearchServiceClient` + + """ + + _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str + + def __init__(self, endpoint, credential, **kwargs): + # type: (str, AzureKeyCredential, **Any) -> None + + self._endpoint = endpoint # type: str + self._credential = credential # type: AzureKeyCredential + self._client = _SearchServiceClient( + endpoint=endpoint, sdk_moniker=SDK_MONIKER, **kwargs + ) # type: _SearchServiceClient + + async def __aenter__(self): + # type: () -> SearchIndexesClient + await self._client.__aenter__() # pylint:disable=no-member + return self + + async def __aexit__(self, *args): + # type: (*Any) -> None + return await self._client.__aexit__(*args) # pylint:disable=no-member + + async def close(self): + # type: () -> None + """Close the :class:`~azure.search.documents.SearchIndexesClient` session. + + """ + return await self._client.close() + + @distributed_trace_async + async def list_indexes(self, **kwargs): + # type: (**Any) -> AsyncItemPaged[SearchIndex] + """List the indexes in an Azure Search service. + + :return: List of indexes + :rtype: list[~azure.search.documents.SearchIndex] + :raises: ~azure.core.exceptions.HttpResponseError + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + + async def get_next(_token): + return await self._client.indexes.list(**kwargs) + + async def extract_data(response): + return None, [listize_flags_for_index(x) for x in response.indexes] + + return AsyncItemPaged(get_next=get_next, extract_data=extract_data) + + @distributed_trace_async + async def get_index(self, index_name, **kwargs): + # type: (str, **Any) -> SearchIndex + """ + + :param index_name: The name of the index to retrieve. + :type index_name: str + :return: SearchIndex object + :rtype: ~azure.search.documents.SearchIndex + :raises: ~azure.core.exceptions.HttpResponseError + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_index_crud_operations_async.py + :start-after: [START get_index_async] + :end-before: [END get_index_async] + :language: python + :dedent: 4 + :caption: Get an index. + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = await self._client.indexes.get(index_name, **kwargs) + return listize_flags_for_index(result) + + @distributed_trace_async + async def get_index_statistics(self, index_name, **kwargs): + # type: (str, **Any) -> dict + """Returns statistics for the given index, including a document count + and storage usage. + + :param index_name: The name of the index to retrieve. + :type index_name: str + :return: Statistics for the given index, including a document count and storage usage. + :rtype: ~azure.search.documents.GetIndexStatisticsResult + :raises: ~azure.core.exceptions.HttpResponseError + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = await self._client.indexes.get_statistics(index_name, **kwargs) + return result.as_dict() + + @distributed_trace_async + async def delete_index(self, index, **kwargs): + # type: (Union[str, SearchIndex], **Any) -> None + """Deletes a search index and all the documents it contains. The model must be + provided instead of the name to use the access conditions + + :param index: The index to retrieve. + :type index: str or ~search.models.SearchIndex + :keyword match_condition: The match condition to use upon the etag + :type match_condition: ~azure.core.MatchConditions + :raises: ~azure.core.exceptions.HttpResponseError + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_index_crud_operations_async.py + :start-after: [START delete_index_async] + :end-before: [END delete_index_async] + :language: python + :dedent: 4 + :caption: Delete an index. + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + error_map, access_condition = get_access_conditions( + index, kwargs.pop("match_condition", MatchConditions.Unconditionally) + ) + kwargs.update(access_condition) + try: + index_name = index.name + except AttributeError: + index_name = index + await self._client.indexes.delete( + index_name=index_name, error_map=error_map, **kwargs + ) + + @distributed_trace_async + async def create_index(self, index, **kwargs): + # type: (SearchIndex, **Any) -> SearchIndex + """Creates a new search index. + + :param index: The index object. + :type index: ~azure.search.documents.SearchIndex + :return: The index created + :rtype: ~azure.search.documents.SearchIndex + :raises: ~azure.core.exceptions.HttpResponseError + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_index_crud_operations_async.py + :start-after: [START create_index_async] + :end-before: [END create_index_async] + :language: python + :dedent: 4 + :caption: Creating a new index. + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + patched_index = delistize_flags_for_index(index) + result = await self._client.indexes.create(patched_index, **kwargs) + return result + + @distributed_trace_async + async def create_or_update_index( + self, index_name, index, allow_index_downtime=None, **kwargs + ): + # type: (str, SearchIndex, bool, MatchConditions, **Any) -> SearchIndex + """Creates a new search index or updates an index if it already exists. + + :param index_name: The name of the index. + :type index_name: str + :param index: The index object. + :type index: ~azure.search.documents.SearchIndex + :param allow_index_downtime: Allows new analyzers, tokenizers, token filters, or char filters + to be added to an index by taking the index offline for at least a few seconds. This + temporarily causes indexing and query requests to fail. Performance and write availability of + the index can be impaired for several minutes after the index is updated, or longer for very + large indexes. + :type allow_index_downtime: bool + :keyword match_condition: The match condition to use upon the etag + :type match_condition: ~azure.core.MatchConditions + :return: The index created or updated + :rtype: :class:`~azure.search.documents.SearchIndex` + :raises: :class:`~azure.core.exceptions.ResourceNotFoundError`, \ + :class:`~azure.core.exceptions.ResourceModifiedError`, \ + :class:`~azure.core.exceptions.ResourceNotModifiedError`, \ + :class:`~azure.core.exceptions.ResourceNotFoundError`, \ + :class:`~azure.core.exceptions.ResourceExistsError` + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_index_crud_operations_async.py + :start-after: [START update_index_async] + :end-before: [END update_index_async] + :language: python + :dedent: 4 + :caption: Update an index. + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + error_map, access_condition = get_access_conditions( + index, kwargs.pop("match_condition", MatchConditions.Unconditionally) + ) + kwargs.update(access_condition) + patched_index = delistize_flags_for_index(index) + result = await self._client.indexes.create_or_update( + index_name=index_name, + index=patched_index, + allow_index_downtime=allow_index_downtime, + error_map=error_map, + **kwargs + ) + return result + + @distributed_trace_async + async def analyze_text(self, index_name, analyze_request, **kwargs): + # type: (str, AnalyzeRequest, **Any) -> AnalyzeResult + """Shows how an analyzer breaks text into tokens. + + :param index_name: The name of the index for which to test an analyzer. + :type index_name: str + :param analyze_request: The text and analyzer or analysis components to test. + :type analyze_request: ~azure.search.documents.AnalyzeRequest + :return: AnalyzeResult + :rtype: ~azure.search.documents.AnalyzeResult + :raises: ~azure.core.exceptions.HttpResponseError + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_analyze_text_async.py + :start-after: [START simple_analyze_text_async] + :end-before: [END simple_analyze_text_async] + :language: python + :dedent: 4 + :caption: Analyze text + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = await self._client.indexes.analyze( + index_name=index_name, request=analyze_request, **kwargs + ) + return result + + @distributed_trace_async + async def get_synonym_maps(self, **kwargs): + # type: (**Any) -> List[Dict[Any, Any]] + """List the Synonym Maps in an Azure Search service. + + :return: List of synonym maps + :rtype: list[dict] + :raises: ~azure.core.exceptions.HttpResponseError + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_synonym_map_operations_async.py + :start-after: [START get_synonym_maps_async] + :end-before: [END get_synonym_maps_async] + :language: python + :dedent: 4 + :caption: List Synonym Maps + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = await self._client.synonym_maps.list(**kwargs) + return [listize_synonyms(x) for x in result.as_dict()["synonym_maps"]] + + @distributed_trace_async + async def get_synonym_map(self, name, **kwargs): + # type: (str, **Any) -> dict + """Retrieve a named Synonym Map in an Azure Search service + + :param name: The name of the Synonym Map to get + :type name: str + :return: The retrieved Synonym Map + :rtype: dict + :raises: :class:`~azure.core.exceptions.ResourceNotFoundError` + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_synonym_map_operations_async.py + :start-after: [START get_synonym_map_async] + :end-before: [END get_synonym_map_async] + :language: python + :dedent: 4 + :caption: Get a Synonym Map + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = await self._client.synonym_maps.get(name, **kwargs) + return listize_synonyms(result.as_dict()) + + @distributed_trace_async + async def delete_synonym_map(self, synonym_map, **kwargs): + # type: (Union[str, SynonymMap], **Any) -> None + """Delete a named Synonym Map in an Azure Search service. To use access conditions, + the SynonymMap model must be provided instead of the name. It is enough to provide + the name of the synonym map to delete unconditionally. + + :param name: The Synonym Map to delete + :type name: str or ~search.models.SynonymMap + :keyword match_condition: The match condition to use upon the etag + :type match_condition: ~azure.core.MatchConditions + :return: None + :rtype: None + + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_synonym_map_operations_async.py + :start-after: [START delete_synonym_map_async] + :end-before: [END delete_synonym_map_async] + :language: python + :dedent: 4 + :caption: Delete a Synonym Map + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + error_map, access_condition = get_access_conditions( + synonym_map, kwargs.pop("match_condition", MatchConditions.Unconditionally) + ) + kwargs.update(access_condition) + try: + name = synonym_map.name + except AttributeError: + name = synonym_map + await self._client.synonym_maps.delete( + synonym_map_name=name, error_map=error_map, **kwargs + ) + + @distributed_trace_async + async def create_synonym_map(self, name, synonyms, **kwargs): + # type: (str, Sequence[str], **Any) -> dict + """Create a new Synonym Map in an Azure Search service + + :param name: The name of the Synonym Map to create + :type name: str + :param synonyms: A list of synonyms in SOLR format + :type synonyms: List[str] + :return: The created Synonym Map + :rtype: dict + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_synonym_map_operations_async.py + :start-after: [START create_synonym_map_async] + :end-before: [END create_synonym_map_async] + :language: python + :dedent: 4 + :caption: Create a Synonym Map + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + solr_format_synonyms = "\n".join(synonyms) + synonym_map = SynonymMap(name=name, synonyms=solr_format_synonyms) + result = await self._client.synonym_maps.create(synonym_map, **kwargs) + return listize_synonyms(result.as_dict()) + + @distributed_trace_async + async def create_or_update_synonym_map(self, synonym_map, synonyms=None, **kwargs): + # type: (Union[str, SynonymMap], Optional[Sequence[str]], **Any) -> dict + """Create a new Synonym Map in an Azure Search service, or update an + existing one. + + :param synonym_map: The name of the Synonym Map to create or update + :type synonym_map: str or ~azure.search.documents.SynonymMap + :param synonyms: A list of synonyms in SOLR format + :type synonyms: List[str] + :keyword match_condition: The match condition to use upon the etag + :type match_condition: ~azure.core.MatchConditions + :return: The created or updated Synonym Map + :rtype: dict + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + error_map, access_condition = get_access_conditions( + synonym_map, kwargs.pop("match_condition", MatchConditions.Unconditionally) + ) + kwargs.update(access_condition) + try: + name = synonym_map.name + if synonyms: + synonym_map.synonyms = "\n".join(synonyms) + except AttributeError: + name = synonym_map + solr_format_synonyms = "\n".join(synonyms) + synonym_map = SynonymMap(name=name, synonyms=solr_format_synonyms) + result = await self._client.synonym_maps.create_or_update( + synonym_map_name=name, + synonym_map=synonym_map, + error_map=error_map, + **kwargs + ) + return listize_synonyms(result.as_dict()) + + @distributed_trace_async + async def get_service_statistics(self, **kwargs): + # type: (**Any) -> dict + """Get service level statistics for a search service. + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = await self._client.get_service_statistics(**kwargs) + return result.as_dict() diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_indexer_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_indexer_client.py new file mode 100644 index 000000000000..8008a0ce77bf --- /dev/null +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_indexer_client.py @@ -0,0 +1,541 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from azure.core import MatchConditions +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.core.exceptions import ClientAuthenticationError, ResourceNotFoundError + +from .._generated.aio import SearchServiceClient as _SearchServiceClient +from .._generated.models import SearchIndexerSkillset +from .._utils import get_access_conditions +from ..._headers_mixin import HeadersMixin +from ..._version import SDK_MONIKER + +if TYPE_CHECKING: + # pylint:disable=unused-import,ungrouped-imports + from .._generated.models import SearchIndexer, SearchIndexerStatus + from typing import Any, Dict, Optional, Sequence + from azure.core.credentials import AzureKeyCredential + + +class SearchIndexerClient(HeadersMixin): + """A client to interact with Azure search service Indexers. + + """ + + _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str + + def __init__(self, endpoint, credential, **kwargs): + # type: (str, AzureKeyCredential, **Any) -> None + + self._endpoint = endpoint # type: str + self._credential = credential # type: AzureKeyCredential + self._client = _SearchServiceClient( + endpoint=endpoint, sdk_moniker=SDK_MONIKER, **kwargs + ) # type: _SearchServiceClient + + async def __aenter__(self): + # type: () -> SearchIndexersClient + await self._client.__aenter__() # pylint:disable=no-member + return self + + async def __aexit__(self, *args): + # type: (*Any) -> None + return await self._client.__aexit__(*args) # pylint:disable=no-member + + async def close(self): + # type: () -> None + """Close the :class:`~azure.search.documents.aio.SearchIndexersClient` session. + + """ + return await self._client.close() + + @distributed_trace_async + async def create_indexer(self, indexer, **kwargs): + # type: (SearchIndexer, **Any) -> SearchIndexer + """Creates a new SearchIndexer. + + :param indexer: The definition of the indexer to create. + :type indexer: ~azure.search.documents.SearchIndexer + :return: The created SearchIndexer + :rtype: dict + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_indexer_operations_async.py + :start-after: [START create_indexer_async] + :end-before: [END create_indexer_async] + :language: python + :dedent: 4 + :caption: Create a SearchIndexer + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = await self._client.indexers.create(indexer, **kwargs) + return result + + @distributed_trace_async + async def create_or_update_indexer(self, indexer, name=None, **kwargs): + # type: (SearchIndexer, Optional[str], **Any) -> SearchIndexer + """Creates a new indexer or updates a indexer if it already exists. + + :param name: The name of the indexer to create or update. + :type name: str + :param indexer: The definition of the indexer to create or update. + :type indexer: ~azure.search.documents.SearchIndexer + :return: The created SearchIndexer + :rtype: dict + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + error_map, access_condition = get_access_conditions( + indexer, kwargs.pop("match_condition", MatchConditions.Unconditionally) + ) + kwargs.update(access_condition) + if not name: + name = indexer.name + result = await self._client.indexers.create_or_update( + indexer_name=name, indexer=indexer, error_map=error_map, **kwargs + ) + return result + + @distributed_trace_async + async def get_indexer(self, name, **kwargs): + # type: (str, **Any) -> SearchIndexer + """Retrieves a indexer definition. + + :param name: The name of the indexer to retrieve. + :type name: str + :return: The SearchIndexer that is fetched. + :rtype: dict + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_indexer_operations_async.py + :start-after: [START get_indexer_async] + :end-before: [END get_indexer_async] + :language: python + :dedent: 4 + :caption: Retrieve a SearchIndexer + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = await self._client.indexers.get(name, **kwargs) + return result + + @distributed_trace_async + async def get_indexers(self, **kwargs): + # type: (**Any) -> Sequence[SearchIndexer] + """Lists all indexers available for a search service. + + :return: List of all the SearchIndexers. + :rtype: `list[dict]` + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_indexer_operations_async.py + :start-after: [START list_indexer_async] + :end-before: [END list_indexer_async] + :language: python + :dedent: 4 + :caption: List all the SearchIndexers + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = await self._client.indexers.list(**kwargs) + return result.indexers + + @distributed_trace_async + async def delete_indexer(self, indexer, **kwargs): + # type: (Union[str, SearchIndexer], **Any) -> None + """Deletes an indexer. To use access conditions, the SearchIndexer model + must be provided instead of the name. It is enough to provide + the name of the indexer to delete unconditionally. + + :param name: The name of the indexer to delete. + :type name: str + :keyword match_condition: The match condition to use upon the etag + :type match_condition: ~azure.core.MatchConditions + + :return: None + :rtype: None + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_indexer_operations_async.py + :start-after: [START delete_indexer_async] + :end-before: [END delete_indexer_async] + :language: python + :dedent: 4 + :caption: Delete a SearchIndexer + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + error_map, access_condition = get_access_conditions( + indexer, kwargs.pop("match_condition", MatchConditions.Unconditionally) + ) + kwargs.update(access_condition) + try: + name = indexer.name + except AttributeError: + name = indexer + await self._client.indexers.delete(name, error_map=error_map, **kwargs) + + @distributed_trace_async + async def run_indexer(self, name, **kwargs): + # type: (str, **Any) -> None + """Run an indexer. + + :param name: The name of the indexer to run. + :type name: str + + :return: None + :rtype: None + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_indexer_operations_async.py + :start-after: [START run_indexer_async] + :end-before: [END run_indexer_async] + :language: python + :dedent: 4 + :caption: Run a SearchIndexer + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + await self._client.indexers.run(name, **kwargs) + + @distributed_trace_async + async def reset_indexer(self, name, **kwargs): + # type: (str, **Any) -> None + """Resets the change tracking state associated with an indexer. + + :param name: The name of the indexer to reset. + :type name: str + + :return: None + :rtype: None + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_indexer_operations_async.py + :start-after: [START reset_indexer_async] + :end-before: [END reset_indexer_async] + :language: python + :dedent: 4 + :caption: Reset a SearchIndexer's change tracking state + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + await self._client.indexers.reset(name, **kwargs) + + @distributed_trace_async + async def get_indexer_status(self, name, **kwargs): + # type: (str, **Any) -> SearchIndexerStatus + """Get the status of the indexer. + + :param name: The name of the indexer to fetch the status. + :type name: str + + :return: SearchIndexerStatus + :rtype: SearchIndexerStatus + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_indexer_operations_async.py + :start-after: [START get_indexer_status_async] + :end-before: [END get_indexer_status_async] + :language: python + :dedent: 4 + :caption: Get a SearchIndexer's status + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + return await self._client.indexers.get_status(name, **kwargs) + + @distributed_trace_async + async def create_datasource(self, data_source, **kwargs): + # type: (SearchIndexerDataSource, **Any) -> Dict[str, Any] + """Creates a new datasource. + :param data_source: The definition of the datasource to create. + :type data_source: ~search.models.SearchIndexerDataSource + :return: The created SearchIndexerDataSource + :rtype: dict + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_data_source_operations_async.py + :start-after: [START create_data_source_async] + :end-before: [END create_data_source_async] + :language: python + :dedent: 4 + :caption: Create a SearchIndexerDataSource + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = await self._client.data_sources.create(data_source, **kwargs) + return result + + @distributed_trace_async + async def create_or_update_datasource(self, data_source, name=None, **kwargs): + # type: (SearchIndexerDataSource, Optional[str], **Any) -> Dict[str, Any] + """Creates a new datasource or updates a datasource if it already exists. + :param name: The name of the datasource to create or update. + :type name: str + :param data_source: The definition of the datasource to create or update. + :type data_source: ~search.models.SearchIndexerDataSource + :keyword match_condition: The match condition to use upon the etag + :type match_condition: ~azure.core.MatchConditions + :return: The created SearchIndexerDataSource + :rtype: dict + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + error_map, access_condition = get_access_conditions( + data_source, kwargs.pop("match_condition", MatchConditions.Unconditionally) + ) + kwargs.update(access_condition) + if not name: + name = data_source.name + result = await self._client.data_sources.create_or_update( + data_source_name=name, + data_source=data_source, + error_map=error_map, + **kwargs + ) + return result + + @distributed_trace_async + async def delete_datasource(self, data_source, **kwargs): + # type: (Union[str, SearchIndexerDataSource], **Any) -> None + """Deletes a datasource. To use access conditions, the Datasource model must be + provided instead of the name. It is enough to provide the name of the datasource + to delete unconditionally + + :param data_source: The datasource to delete. + :type data_source: str or ~search.models.SearchIndexerDataSource + :keyword match_condition: The match condition to use upon the etag + :type match_condition: ~azure.core.MatchConditions + :return: None + :rtype: None + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_data_source_operations_async.py + :start-after: [START delete_data_source_async] + :end-before: [END delete_data_source_async] + :language: python + :dedent: 4 + :caption: Delete a SearchIndexerDataSource + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + error_map, access_condition = get_access_conditions( + data_source, kwargs.pop("match_condition", MatchConditions.Unconditionally) + ) + kwargs.update(access_condition) + try: + name = data_source.name + except AttributeError: + name = data_source + await self._client.data_sources.delete( + data_source_name=name, error_map=error_map, **kwargs + ) + + @distributed_trace_async + async def get_datasource(self, name, **kwargs): + # type: (str, **Any) -> Dict[str, Any] + """Retrieves a datasource definition. + + :param name: The name of the datasource to retrieve. + :type name: str + :return: The SearchIndexerDataSource that is fetched. + + .. literalinclude:: ../samples/async_samples/sample_data_source_operations_async.py + :start-after: [START get_data_source_async] + :end-before: [END get_data_source_async] + :language: python + :dedent: 4 + :caption: Retrieve a SearchIndexerDataSource + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = await self._client.data_sources.get(name, **kwargs) + return result + + @distributed_trace_async + async def get_datasources(self, **kwargs): + # type: (**Any) -> Sequence[SearchIndexerDataSource] + """Lists all datasources available for a search service. + + :return: List of all the data sources. + :rtype: `list[dict]` + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_data_source_operations_async.py + :start-after: [START list_data_source_async] + :end-before: [END list_data_source_async] + :language: python + :dedent: 4 + :caption: List all SearchIndexerDataSources + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = await self._client.data_sources.list(**kwargs) + return result.data_sources + + @distributed_trace_async + async def get_skillsets(self, **kwargs): + # type: (**Any) -> List[SearchIndexerSkillset] + """List the SearchIndexerSkillsets in an Azure Search service. + + :return: List of SearchIndexerSkillsets + :rtype: list[dict] + :raises: ~azure.core.exceptions.HttpResponseError + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_skillset_operations_async.py + :start-after: [START get_skillsets] + :end-before: [END get_skillsets] + :language: python + :dedent: 4 + :caption: List SearchIndexerSkillsets + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = await self._client.skillsets.list(**kwargs) + return result.skillsets + + @distributed_trace_async + async def get_skillset(self, name, **kwargs): + # type: (str, **Any) -> SearchIndexerSkillset + """Retrieve a named SearchIndexerSkillset in an Azure Search service + + :param name: The name of the SearchIndexerSkillset to get + :type name: str + :return: The retrieved SearchIndexerSkillset + :rtype: dict + :raises: :class:`~azure.core.exceptions.ResourceNotFoundError` + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_skillset_operations_async.py + :start-after: [START get_skillset] + :end-before: [END get_skillset] + :language: python + :dedent: 4 + :caption: Get a SearchIndexerSkillset + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + return await self._client.skillsets.get(name, **kwargs) + + @distributed_trace_async + async def delete_skillset(self, skillset, **kwargs): + # type: (Union[str, SearchIndexerSkillset], **Any) -> None + """Delete a named SearchIndexerSkillset in an Azure Search service. To use access conditions, + the SearchIndexerSkillset model must be provided instead of the name. It is enough to provide + the name of the skillset to delete unconditionally + + :param name: The SearchIndexerSkillset to delete + :type name: str or ~search.models.SearchIndexerSkillset + :keyword match_condition: The match condition to use upon the etag + :type match_condition: ~azure.core.MatchConditions + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_skillset_operations_async.py + :start-after: [START delete_skillset] + :end-before: [END delete_skillset] + :language: python + :dedent: 4 + :caption: Delete a SearchIndexerSkillset + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + error_map, access_condition = get_access_conditions( + skillset, kwargs.pop("match_condition", MatchConditions.Unconditionally) + ) + kwargs.update(access_condition) + try: + name = skillset.name + except AttributeError: + name = skillset + await self._client.skillsets.delete(name, error_map=error_map, **kwargs) + + @distributed_trace_async + async def create_skillset(self, name, skills, description, **kwargs): + # type: (str, Sequence[SearchIndexerSkill], str, **Any) -> SearchIndexerSkillset + """Create a new SearchIndexerSkillset in an Azure Search service + + :param name: The name of the SearchIndexerSkillset to create + :type name: str + :param skills: A list of Skill objects to include in the SearchIndexerSkillset + :type skills: List[SearchIndexerSkill]] + :param description: A description for the SearchIndexerSkillset + :type description: Optional[str] + :return: The created SearchIndexerSkillset + :rtype: dict + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_skillset_operations_async.py + :start-after: [START create_skillset] + :end-before: [END create_skillset] + :language: python + :dedent: 4 + :caption: Create a SearchIndexerSkillset + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + + skillset = SearchIndexerSkillset( + name=name, skills=list(skills), description=description + ) + + return await self._client.skillsets.create(skillset, **kwargs) + + @distributed_trace_async + async def create_or_update_skillset(self, name, **kwargs): + # type: (str, **Any) -> SearchIndexerSkillset + """Create a new SearchIndexerSkillset in an Azure Search service, or update an + existing one. The skillset param must be provided to perform the + operation with access conditions. + + :param name: The name of the SearchIndexerSkillset to create or update + :type name: str + :keyword skills: A list of Skill objects to include in the SearchIndexerSkillset + :type skills: List[SearchIndexerSkill] + :keyword description: A description for the SearchIndexerSkillset + :type description: Optional[str] + :keyword skillset: A SearchIndexerSkillset to create or update. + :type skillset: :class:`~azure.search.documents.SearchIndexerSkillset` + :keyword match_condition: The match condition to use upon the etag + :type match_condition: ~azure.core.MatchConditions + :return: The created or updated SearchIndexerSkillset + :rtype: dict + + If a `skillset` is passed in, any optional `skills`, or + `description` parameter values will override it. + + + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError} + access_condition = None + + if "skillset" in kwargs: + skillset = kwargs.pop("skillset") + error_map, access_condition = get_access_conditions( + skillset, kwargs.pop("match_condition", MatchConditions.Unconditionally) + ) + kwargs.update(access_condition) + skillset = SearchIndexerSkillset.deserialize(skillset.serialize()) + skillset.name = name + for param in ("description", "skills"): + if param in kwargs: + setattr(skillset, param, kwargs.pop(param)) + else: + + skillset = SearchIndexerSkillset( + name=name, + description=kwargs.pop("description", None), + skills=kwargs.pop("skills", None), + ) + + return await self._client.skillsets.create_or_update( + skillset_name=name, skillset=skillset, error_map=error_map, **kwargs + ) diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_skillsets_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_skillsets_client.py index a53f74508589..5f72362c410e 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_skillsets_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_skillsets_client.py @@ -57,166 +57,3 @@ async def close(self): """ return await self._client.close() - @distributed_trace_async - async def get_skillsets(self, **kwargs): - # type: (**Any) -> List[SearchIndexerSkillset] - """List the SearchIndexerSkillsets in an Azure Search service. - - :return: List of SearchIndexerSkillsets - :rtype: list[dict] - :raises: ~azure.core.exceptions.HttpResponseError - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_skillset_operations_async.py - :start-after: [START get_skillsets] - :end-before: [END get_skillsets] - :language: python - :dedent: 4 - :caption: List SearchIndexerSkillsets - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = await self._client.skillsets.list(**kwargs) - return result.skillsets - - @distributed_trace_async - async def get_skillset(self, name, **kwargs): - # type: (str, **Any) -> SearchIndexerSkillset - """Retrieve a named SearchIndexerSkillset in an Azure Search service - - :param name: The name of the SearchIndexerSkillset to get - :type name: str - :return: The retrieved SearchIndexerSkillset - :rtype: dict - :raises: :class:`~azure.core.exceptions.ResourceNotFoundError` - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_skillset_operations_async.py - :start-after: [START get_skillset] - :end-before: [END get_skillset] - :language: python - :dedent: 4 - :caption: Get a SearchIndexerSkillset - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - return await self._client.skillsets.get(name, **kwargs) - - @distributed_trace_async - async def delete_skillset(self, skillset, **kwargs): - # type: (Union[str, SearchIndexerSkillset], **Any) -> None - """Delete a named SearchIndexerSkillset in an Azure Search service. To use access conditions, - the SearchIndexerSkillset model must be provided instead of the name. It is enough to provide - the name of the skillset to delete unconditionally - - :param name: The SearchIndexerSkillset to delete - :type name: str or ~search.models.SearchIndexerSkillset - :keyword match_condition: The match condition to use upon the etag - :type match_condition: ~azure.core.MatchConditions - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_skillset_operations_async.py - :start-after: [START delete_skillset] - :end-before: [END delete_skillset] - :language: python - :dedent: 4 - :caption: Delete a SearchIndexerSkillset - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - error_map, access_condition = get_access_conditions( - skillset, kwargs.pop("match_condition", MatchConditions.Unconditionally) - ) - kwargs.update(access_condition) - try: - name = skillset.name - except AttributeError: - name = skillset - await self._client.skillsets.delete(name, error_map=error_map, **kwargs) - - @distributed_trace_async - async def create_skillset(self, name, skills, description, **kwargs): - # type: (str, Sequence[SearchIndexerSkill], str, **Any) -> SearchIndexerSkillset - """Create a new SearchIndexerSkillset in an Azure Search service - - :param name: The name of the SearchIndexerSkillset to create - :type name: str - :param skills: A list of Skill objects to include in the SearchIndexerSkillset - :type skills: List[SearchIndexerSkill]] - :param description: A description for the SearchIndexerSkillset - :type description: Optional[str] - :return: The created SearchIndexerSkillset - :rtype: dict - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_skillset_operations_async.py - :start-after: [START create_skillset] - :end-before: [END create_skillset] - :language: python - :dedent: 4 - :caption: Create a SearchIndexerSkillset - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - - skillset = SearchIndexerSkillset( - name=name, skills=list(skills), description=description - ) - - return await self._client.skillsets.create(skillset, **kwargs) - - @distributed_trace_async - async def create_or_update_skillset(self, name, **kwargs): - # type: (str, **Any) -> SearchIndexerSkillset - """Create a new SearchIndexerSkillset in an Azure Search service, or update an - existing one. The skillset param must be provided to perform the - operation with access conditions. - - :param name: The name of the SearchIndexerSkillset to create or update - :type name: str - :keyword skills: A list of Skill objects to include in the SearchIndexerSkillset - :type skills: List[SearchIndexerSkill] - :keyword description: A description for the SearchIndexerSkillset - :type description: Optional[str] - :keyword skillset: A SearchIndexerSkillset to create or update. - :type skillset: :class:`~azure.search.documents.SearchIndexerSkillset` - :keyword match_condition: The match condition to use upon the etag - :type match_condition: ~azure.core.MatchConditions - :return: The created or updated SearchIndexerSkillset - :rtype: dict - - If a `skillset` is passed in, any optional `skills`, or - `description` parameter values will override it. - - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError} - access_condition = None - - if "skillset" in kwargs: - skillset = kwargs.pop("skillset") - error_map, access_condition = get_access_conditions( - skillset, kwargs.pop("match_condition", MatchConditions.Unconditionally) - ) - kwargs.update(access_condition) - skillset = SearchIndexerSkillset.deserialize(skillset.serialize()) - skillset.name = name - for param in ("description", "skills"): - if param in kwargs: - setattr(skillset, param, kwargs.pop(param)) - else: - - skillset = SearchIndexerSkillset( - name=name, - description=kwargs.pop("description", None), - skills=kwargs.pop("skills", None), - ) - - return await self._client.skillsets.create_or_update( - skillset_name=name, skillset=skillset, error_map=error_map, **kwargs - ) diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_synonym_maps_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_synonym_maps_client.py index a3d6f88dead0..e67a268b18bb 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_synonym_maps_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_synonym_maps_client.py @@ -55,153 +55,3 @@ async def close(self): """ return await self._client.close() - @distributed_trace_async - async def get_synonym_maps(self, **kwargs): - # type: (**Any) -> List[Dict[Any, Any]] - """List the Synonym Maps in an Azure Search service. - - :return: List of synonym maps - :rtype: list[dict] - :raises: ~azure.core.exceptions.HttpResponseError - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_synonym_map_operations_async.py - :start-after: [START get_synonym_maps_async] - :end-before: [END get_synonym_maps_async] - :language: python - :dedent: 4 - :caption: List Synonym Maps - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = await self._client.synonym_maps.list(**kwargs) - return [listize_synonyms(x) for x in result.as_dict()["synonym_maps"]] - - @distributed_trace_async - async def get_synonym_map(self, name, **kwargs): - # type: (str, **Any) -> dict - """Retrieve a named Synonym Map in an Azure Search service - - :param name: The name of the Synonym Map to get - :type name: str - :return: The retrieved Synonym Map - :rtype: dict - :raises: :class:`~azure.core.exceptions.ResourceNotFoundError` - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_synonym_map_operations_async.py - :start-after: [START get_synonym_map_async] - :end-before: [END get_synonym_map_async] - :language: python - :dedent: 4 - :caption: Get a Synonym Map - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = await self._client.synonym_maps.get(name, **kwargs) - return listize_synonyms(result.as_dict()) - - @distributed_trace_async - async def delete_synonym_map(self, synonym_map, **kwargs): - # type: (Union[str, SynonymMap], **Any) -> None - """Delete a named Synonym Map in an Azure Search service. To use access conditions, - the SynonymMap model must be provided instead of the name. It is enough to provide - the name of the synonym map to delete unconditionally. - - :param name: The Synonym Map to delete - :type name: str or ~search.models.SynonymMap - :keyword match_condition: The match condition to use upon the etag - :type match_condition: ~azure.core.MatchConditions - :return: None - :rtype: None - - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_synonym_map_operations_async.py - :start-after: [START delete_synonym_map_async] - :end-before: [END delete_synonym_map_async] - :language: python - :dedent: 4 - :caption: Delete a Synonym Map - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - error_map, access_condition = get_access_conditions( - synonym_map, kwargs.pop("match_condition", MatchConditions.Unconditionally) - ) - kwargs.update(access_condition) - try: - name = synonym_map.name - except AttributeError: - name = synonym_map - await self._client.synonym_maps.delete( - synonym_map_name=name, error_map=error_map, **kwargs - ) - - @distributed_trace_async - async def create_synonym_map(self, name, synonyms, **kwargs): - # type: (str, Sequence[str], **Any) -> dict - """Create a new Synonym Map in an Azure Search service - - :param name: The name of the Synonym Map to create - :type name: str - :param synonyms: A list of synonyms in SOLR format - :type synonyms: List[str] - :return: The created Synonym Map - :rtype: dict - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_synonym_map_operations_async.py - :start-after: [START create_synonym_map_async] - :end-before: [END create_synonym_map_async] - :language: python - :dedent: 4 - :caption: Create a Synonym Map - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - solr_format_synonyms = "\n".join(synonyms) - synonym_map = SynonymMap(name=name, synonyms=solr_format_synonyms) - result = await self._client.synonym_maps.create(synonym_map, **kwargs) - return listize_synonyms(result.as_dict()) - - @distributed_trace_async - async def create_or_update_synonym_map(self, synonym_map, synonyms=None, **kwargs): - # type: (Union[str, SynonymMap], Optional[Sequence[str]], **Any) -> dict - """Create a new Synonym Map in an Azure Search service, or update an - existing one. - - :param synonym_map: The name of the Synonym Map to create or update - :type synonym_map: str or ~azure.search.documents.SynonymMap - :param synonyms: A list of synonyms in SOLR format - :type synonyms: List[str] - :keyword match_condition: The match condition to use upon the etag - :type match_condition: ~azure.core.MatchConditions - :return: The created or updated Synonym Map - :rtype: dict - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - error_map, access_condition = get_access_conditions( - synonym_map, kwargs.pop("match_condition", MatchConditions.Unconditionally) - ) - kwargs.update(access_condition) - try: - name = synonym_map.name - if synonyms: - synonym_map.synonyms = "\n".join(synonyms) - except AttributeError: - name = synonym_map - solr_format_synonyms = "\n".join(synonyms) - synonym_map = SynonymMap(name=name, synonyms=solr_format_synonyms) - result = await self._client.synonym_maps.create_or_update( - synonym_map_name=name, - synonym_map=synonym_map, - error_map=error_map, - **kwargs - ) - return listize_synonyms(result.as_dict()) diff --git a/sdk/search/azure-search-documents/tests/async_tests/test_service_live_async.py b/sdk/search/azure-search-documents/tests/async_tests/test_service_live_async.py index 60994ffe248f..0ee80d5e4112 100644 --- a/sdk/search/azure-search-documents/tests/async_tests/test_service_live_async.py +++ b/sdk/search/azure-search-documents/tests/async_tests/test_service_live_async.py @@ -39,6 +39,8 @@ edm ) from azure.search.documents.aio import SearchServiceClient +from azure.search.documents._service.aio._search_index_client import SearchIndexClient +from azure.search.documents._service.aio._search_indexer_client import SearchIndexerClient from _test_utils import build_synonym_map_from_dict CWD = dirname(realpath(__file__)) @@ -64,7 +66,7 @@ class SearchClientTest(AzureMgmtTestCase): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer() async def test_get_service_statistics(self, api_key, endpoint, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)) + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) result = await client.get_service_statistics() assert isinstance(result, dict) assert set(result.keys()) == {"counters", "limits"} @@ -74,7 +76,7 @@ class SearchIndexesClientTest(AzureMgmtTestCase): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer() async def test_list_indexes_empty(self, api_key, endpoint, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexes_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) result = await client.list_indexes() with pytest.raises(StopAsyncIteration): @@ -83,7 +85,7 @@ async def test_list_indexes_empty(self, api_key, endpoint, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_list_indexes(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexes_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) result = await client.list_indexes() first = await result.__anext__() @@ -95,21 +97,21 @@ async def test_list_indexes(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_get_index(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexes_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) result = await client.get_index(index_name) assert result.name == index_name @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_get_index_statistics(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexes_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) result = await client.get_index_statistics(index_name) assert set(result.keys()) == {'document_count', 'storage_size'} @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_delete_indexes(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexes_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) await client.delete_index(index_name) import time if self.is_live: @@ -121,7 +123,7 @@ async def test_delete_indexes(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_delete_indexes_if_unchanged(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexes_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) # First create an index name = "hotels" @@ -177,7 +179,7 @@ async def test_create_index(self, api_key, endpoint, index_name, **kwargs): fields=fields, scoring_profiles=scoring_profiles, cors_options=cors_options) - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexes_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) result = await client.create_index(index) assert result.name == "hotels" assert result.scoring_profiles[0].name == scoring_profile.name @@ -200,7 +202,7 @@ async def test_create_or_update_index(self, api_key, endpoint, index_name, **kwa fields=fields, scoring_profiles=scoring_profiles, cors_options=cors_options) - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexes_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) result = await client.create_or_update_index(index_name=index.name, index=index) assert len(result.scoring_profiles) == 0 assert result.cors_options.allowed_origins == cors_options.allowed_origins @@ -223,7 +225,7 @@ async def test_create_or_update_index(self, api_key, endpoint, index_name, **kwa @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_create_or_update_indexes_if_unchanged(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexes_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) # First create an index name = "hotels" @@ -262,7 +264,7 @@ async def test_create_or_update_indexes_if_unchanged(self, api_key, endpoint, in @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_analyze_text(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexes_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) analyze_request = AnalyzeRequest(text="One's ", analyzer="standard.lucene") result = await client.analyze_text(index_name, analyze_request) assert len(result.tokens) == 2 @@ -271,7 +273,7 @@ class SearchSynonymMapsClientTest(AzureMgmtTestCase): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_create_synonym_map(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_synonym_maps_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) result = await client.create_synonym_map("test-syn-map", [ "USA, United States, United States of America", "Washington, Wash. => WA", @@ -287,7 +289,7 @@ async def test_create_synonym_map(self, api_key, endpoint, index_name, **kwargs) @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_delete_synonym_map(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_synonym_maps_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) result = await client.create_synonym_map("test-syn-map", [ "USA, United States, United States of America", "Washington, Wash. => WA", @@ -299,7 +301,7 @@ async def test_delete_synonym_map(self, api_key, endpoint, index_name, **kwargs) @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_delete_synonym_map_if_unchanged(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_synonym_maps_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) result = await client.create_synonym_map("test-syn-map", [ "USA, United States, United States of America", "Washington, Wash. => WA", @@ -319,7 +321,7 @@ async def test_delete_synonym_map_if_unchanged(self, api_key, endpoint, index_na @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_get_synonym_map(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_synonym_maps_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) await client.create_synonym_map("test-syn-map", [ "USA, United States, United States of America", "Washington, Wash. => WA", @@ -336,7 +338,7 @@ async def test_get_synonym_map(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_get_synonym_maps(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_synonym_maps_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) await client.create_synonym_map("test-syn-map-1", [ "USA, United States, United States of America", ]) @@ -351,7 +353,7 @@ async def test_get_synonym_maps(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_create_or_update_synonym_map(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_synonym_maps_client() + client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) await client.create_synonym_map("test-syn-map", [ "USA, United States, United States of America", ]) @@ -372,7 +374,7 @@ class SearchSkillsetClientTest(AzureMgmtTestCase): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_create_skillset(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_skillsets_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) s = EntityRecognitionSkill(inputs=[InputFieldMappingEntry(name="text", source="/document/content")], outputs=[OutputFieldMappingEntry(name="organizations", target_name="organizations")]) @@ -390,7 +392,7 @@ async def test_create_skillset(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_delete_skillset(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_skillsets_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) s = EntityRecognitionSkill(inputs=[InputFieldMappingEntry(name="text", source="/document/content")], outputs=[OutputFieldMappingEntry(name="organizations", target_name="organizations")]) @@ -405,7 +407,7 @@ async def test_delete_skillset(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_delete_skillset_if_unchanged(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_skillsets_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) s = EntityRecognitionSkill(inputs=[InputFieldMappingEntry(name="text", source="/document/content")], outputs=[OutputFieldMappingEntry(name="organizations", target_name="organizations")]) @@ -421,7 +423,7 @@ async def test_delete_skillset_if_unchanged(self, api_key, endpoint, index_name, @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_get_skillset(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_skillsets_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) s = EntityRecognitionSkill(inputs=[InputFieldMappingEntry(name="text", source="/document/content")], outputs=[OutputFieldMappingEntry(name="organizations", target_name="organizations")]) @@ -439,7 +441,7 @@ async def test_get_skillset(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_get_skillsets(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_skillsets_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) s = EntityRecognitionSkill(inputs=[InputFieldMappingEntry(name="text", source="/document/content")], outputs=[OutputFieldMappingEntry(name="organizations", target_name="organizations")]) @@ -453,7 +455,7 @@ async def test_get_skillsets(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_create_or_update_skillset(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_skillsets_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) s = EntityRecognitionSkill(inputs=[InputFieldMappingEntry(name="text", source="/document/content")], outputs=[OutputFieldMappingEntry(name="organizations", target_name="organizations")]) @@ -469,7 +471,7 @@ async def test_create_or_update_skillset(self, api_key, endpoint, index_name, ** @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_create_or_update_skillset_inplace(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_skillsets_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) s = EntityRecognitionSkill(inputs=[InputFieldMappingEntry(name="text", source="/document/content")], outputs=[OutputFieldMappingEntry(name="organizations", target_name="organizations")]) @@ -485,7 +487,7 @@ async def test_create_or_update_skillset_inplace(self, api_key, endpoint, index_ @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_create_or_update_skillset_if_unchanged(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_skillsets_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) s = EntityRecognitionSkill(inputs=[InputFieldMappingEntry(name="text", source="/document/content")], outputs=[OutputFieldMappingEntry(name="organizations", target_name="organizations")]) @@ -516,7 +518,7 @@ def _create_datasource(self, name="sample-datasource"): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_create_datasource_async(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_datasources_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) data_source = self._create_datasource() result = await client.create_datasource(data_source) assert result.name == "sample-datasource" @@ -525,7 +527,7 @@ async def test_create_datasource_async(self, api_key, endpoint, index_name, **kw @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_delete_datasource_async(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_datasources_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) data_source = self._create_datasource() result = await client.create_datasource(data_source) assert len(await client.get_datasources()) == 1 @@ -535,7 +537,7 @@ async def test_delete_datasource_async(self, api_key, endpoint, index_name, **kw @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_get_datasource_async(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_datasources_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) data_source = self._create_datasource() created = await client.create_datasource(data_source) result = await client.get_datasource("sample-datasource") @@ -544,7 +546,7 @@ async def test_get_datasource_async(self, api_key, endpoint, index_name, **kwarg @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_list_datasource_async(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_datasources_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) data_source1 = self._create_datasource() data_source2 = self._create_datasource(name="another-sample") created1 = await client.create_datasource(data_source1) @@ -556,7 +558,7 @@ async def test_list_datasource_async(self, api_key, endpoint, index_name, **kwar @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_create_or_update_datasource_async(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_datasources_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) data_source = self._create_datasource() created = await client.create_datasource(data_source) assert len(await client.get_datasources()) == 1 @@ -570,7 +572,7 @@ async def test_create_or_update_datasource_async(self, api_key, endpoint, index_ @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_create_or_update_datasource_if_unchanged(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_datasources_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) data_source = self._create_datasource() created = await client.create_datasource(data_source) etag = created.e_tag @@ -589,7 +591,7 @@ async def test_create_or_update_datasource_if_unchanged(self, api_key, endpoint, @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_delete_datasource_if_unchanged(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_datasources_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) data_source = self._create_datasource() created = await client.create_datasource(data_source) etag = created.e_tag @@ -617,8 +619,7 @@ async def _prepare_indexer(self, endpoint, api_key, name="sample-indexer", ds_na credentials=credentials, container=container ) - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)) - ds_client = client.get_datasources_client() + ds_client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) ds = await ds_client.create_datasource(data_source) index_name = id_name @@ -630,14 +631,14 @@ async def _prepare_indexer(self, endpoint, api_key, name="sample-indexer", ds_na "searchable": False }] index = SearchIndex(name=index_name, fields=fields) - ind_client = client.get_indexes_client() + ind_client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) ind = await ind_client.create_index(index) return SearchIndexer(name=name, data_source_name=ds.name, target_index_name=ind.name) @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_create_indexer(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexers_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) indexer = await self._prepare_indexer(endpoint, api_key) result = await client.create_indexer(indexer) assert result.name == "sample-indexer" @@ -647,7 +648,7 @@ async def test_create_indexer(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_delete_indexer(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexers_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) indexer = await self._prepare_indexer(endpoint, api_key) result = await client.create_indexer(indexer) assert len(await client.get_indexers()) == 1 @@ -657,7 +658,7 @@ async def test_delete_indexer(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_get_indexer(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexers_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) indexer = await self._prepare_indexer(endpoint, api_key) created = await client.create_indexer(indexer) result = await client.get_indexer("sample-indexer") @@ -666,7 +667,7 @@ async def test_get_indexer(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_list_indexer(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexers_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) indexer1 = await self._prepare_indexer(endpoint, api_key) indexer2 = await self._prepare_indexer(endpoint, api_key, name="another-indexer", ds_name="another-datasource", id_name="another-index") created1 = await client.create_indexer(indexer1) @@ -678,7 +679,7 @@ async def test_list_indexer(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_create_or_update_indexer(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexers_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) indexer = await self._prepare_indexer(endpoint, api_key) created = await client.create_indexer(indexer) assert len(await client.get_indexers()) == 1 @@ -692,7 +693,7 @@ async def test_create_or_update_indexer(self, api_key, endpoint, index_name, **k @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_reset_indexer(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexers_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) indexer = await self._prepare_indexer(endpoint, api_key) result = await client.create_indexer(indexer) assert len(await client.get_indexers()) == 1 @@ -702,7 +703,7 @@ async def test_reset_indexer(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_run_indexer(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexers_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) indexer = await self._prepare_indexer(endpoint, api_key) result = await client.create_indexer(indexer) assert len(await client.get_indexers()) == 1 @@ -713,7 +714,7 @@ async def test_run_indexer(self, api_key, endpoint, index_name, **kwargs): @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_get_indexer_status(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexers_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) indexer = await self._prepare_indexer(endpoint, api_key) result = await client.create_indexer(indexer) status = await client.get_indexer_status("sample-indexer") @@ -722,7 +723,7 @@ async def test_get_indexer_status(self, api_key, endpoint, index_name, **kwargs) @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_create_or_update_indexer_if_unchanged(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexers_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) indexer = await self._prepare_indexer(endpoint, api_key) created = await client.create_indexer(indexer) etag = created.e_tag @@ -738,7 +739,7 @@ async def test_create_or_update_indexer_if_unchanged(self, api_key, endpoint, in @SearchResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) async def test_delete_indexer_if_unchanged(self, api_key, endpoint, index_name, **kwargs): - client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)).get_indexers_client() + client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) indexer = await self._prepare_indexer(endpoint, api_key) result = await client.create_indexer(indexer) etag = result.e_tag From 06746c16c7d5417b83b081b0247cc7baf744f766 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 20 May 2020 19:53:14 -0700 Subject: [PATCH 04/12] update init --- .../azure/search/documents/__init__.py | 18 +-- .../search/documents/_service/__init__.py | 3 +- .../documents/_service/_datasources_client.py | 57 -------- .../documents/_service/_indexers_client.py | 56 -------- .../documents/_service/_indexes_client.py | 61 -------- .../_service/_search_index_client.py | 3 +- .../_service/_search_indexer_client.py | 4 +- .../_service/_search_service_client.py | 117 --------------- .../_service/_search_service_client_base.py | 36 ----- .../documents/_service/_skillsets_client.py | 58 -------- .../_service/_synonym_maps_client.py | 56 -------- .../azure/search/documents/_service/_utils.py | 2 +- .../search/documents/_service/aio/__init__.py | 17 +-- .../_service/aio/_datasources_client.py | 57 -------- .../_service/aio/_indexers_client.py | 56 -------- .../documents/_service/aio/_indexes_client.py | 60 -------- .../_service/aio/_search_index_client.py | 3 +- .../_service/aio/_search_indexer_client.py | 4 +- .../aio/_search_service_client_async.py | 134 ------------------ .../_service/aio/_skillsets_client.py | 59 -------- .../_service/aio/_synonym_maps_client.py | 57 -------- .../azure/search/documents/aio.py | 16 +-- .../async_tests/test_service_live_async.py | 5 +- .../tests/test_search_service_client.py | 66 ++++++--- .../tests/test_service_live.py | 5 +- 25 files changed, 76 insertions(+), 934 deletions(-) delete mode 100644 sdk/search/azure-search-documents/azure/search/documents/_service/_datasources_client.py delete mode 100644 sdk/search/azure-search-documents/azure/search/documents/_service/_indexers_client.py delete mode 100644 sdk/search/azure-search-documents/azure/search/documents/_service/_indexes_client.py delete mode 100644 sdk/search/azure-search-documents/azure/search/documents/_service/_search_service_client.py delete mode 100644 sdk/search/azure-search-documents/azure/search/documents/_service/_search_service_client_base.py delete mode 100644 sdk/search/azure-search-documents/azure/search/documents/_service/_skillsets_client.py delete mode 100644 sdk/search/azure-search-documents/azure/search/documents/_service/_synonym_maps_client.py delete mode 100644 sdk/search/azure-search-documents/azure/search/documents/_service/aio/_datasources_client.py delete mode 100644 sdk/search/azure-search-documents/azure/search/documents/_service/aio/_indexers_client.py delete mode 100644 sdk/search/azure-search-documents/azure/search/documents/_service/aio/_indexes_client.py delete mode 100644 sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_service_client_async.py delete mode 100644 sdk/search/azure-search-documents/azure/search/documents/_service/aio/_skillsets_client.py delete mode 100644 sdk/search/azure-search-documents/azure/search/documents/_service/aio/_synonym_maps_client.py diff --git a/sdk/search/azure-search-documents/azure/search/documents/__init__.py b/sdk/search/azure-search-documents/azure/search/documents/__init__.py index 7632f0b5daa7..a640ced8b894 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/__init__.py +++ b/sdk/search/azure-search-documents/azure/search/documents/__init__.py @@ -39,7 +39,8 @@ ComplexField, SearchableField, SimpleField, - SearchServiceClient, + SearchIndexClient, + SearchIndexerClient, edm, ) from ._service._generated.models import ( @@ -129,11 +130,8 @@ WordDelimiterTokenFilter, ) from ._service._models import PatternAnalyzer, PatternTokenizer -from ._service._datasources_client import SearchDataSourcesClient -from ._service._indexers_client import SearchIndexersClient -from ._service._indexes_client import SearchIndexesClient -from ._service._skillsets_client import SearchSkillsetsClient -from ._service._synonym_maps_client import SearchSynonymMapsClient +from ._service._search_indexer_client import SearchIndexerClient +from ._service._search_index_client import SearchIndexClient from ._version import VERSION __version__ = VERSION @@ -202,7 +200,6 @@ "RegexFlags", "ScoringFunction", "ScoringProfile", - "SearchDataSourcesClient", "SearchClient", "SearchField", "SearchIndex", @@ -210,14 +207,11 @@ "SearchIndexerDataContainer", "SearchIndexerDataSource", "SearchIndexerSkillset", - "SearchIndexersClient", - "SearchIndexesClient", + "SearchIndexerClient", + "SearchIndexClient", "SearchItemPaged", "SearchQuery", "SearchResourceEncryptionKey", - "SearchServiceClient", - "SearchSkillsetsClient", - "SearchSynonymMapsClient", "SearchableField", "SentimentSkill", "ShaperSkill", diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/__init__.py b/sdk/search/azure-search-documents/azure/search/documents/_service/__init__.py index 0e79615eac2c..11b14c02fb89 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/__init__.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/__init__.py @@ -7,6 +7,7 @@ SearchableField, SimpleField, ) -from ._search_service_client import SearchServiceClient # pylint: disable=unused-import +from ._search_index_client import SearchIndexClient # pylint: disable=unused-import +from ._search_indexer_client import SearchIndexerClient # pylint: disable=unused-import from . import edm # pylint: disable=unused-import diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_datasources_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_datasources_client.py deleted file mode 100644 index 2c82a2d25dd8..000000000000 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_datasources_client.py +++ /dev/null @@ -1,57 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -from typing import TYPE_CHECKING - -from azure.core import MatchConditions -from azure.core.tracing.decorator import distributed_trace - -from ._generated import SearchServiceClient as _SearchServiceClient -from ._utils import get_access_conditions -from .._headers_mixin import HeadersMixin -from .._version import SDK_MONIKER - -if TYPE_CHECKING: - # pylint:disable=unused-import,ungrouped-imports - from ._generated.models import SearchIndexerDataSource - from typing import Any, Dict, Optional, Sequence, Union - from azure.core.credentials import AzureKeyCredential - - -class SearchDataSourcesClient(HeadersMixin): - """A client to interact with Azure search service Data Sources. - - This class is not normally instantiated directly, instead use - `get_datasources_client()` from a `SearchServiceClient` - - """ - - _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str - - def __init__(self, endpoint, credential, **kwargs): - # type: (str, AzureKeyCredential, **Any) -> None - - self._endpoint = endpoint # type: str - self._credential = credential # type: AzureKeyCredential - self._client = _SearchServiceClient( - endpoint=endpoint, sdk_moniker=SDK_MONIKER, **kwargs - ) # type: _SearchServiceClient - - def __enter__(self): - # type: () -> SearchDataSourcesClient - self._client.__enter__() # pylint:disable=no-member - return self - - def __exit__(self, *args): - # type: (*Any) -> None - return self._client.__exit__(*args) # pylint:disable=no-member - - def close(self): - # type: () -> None - """Close the :class:`~azure.search.documents.SearchDataSourcesClient` session. - - """ - return self._client.close() - diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_indexers_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_indexers_client.py deleted file mode 100644 index b0d81fda0323..000000000000 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_indexers_client.py +++ /dev/null @@ -1,56 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -from typing import TYPE_CHECKING - -from azure.core import MatchConditions -from azure.core.tracing.decorator import distributed_trace - -from ._generated import SearchServiceClient as _SearchServiceClient -from ._utils import get_access_conditions -from .._headers_mixin import HeadersMixin -from .._version import SDK_MONIKER - -if TYPE_CHECKING: - # pylint:disable=unused-import,ungrouped-imports - from ._generated.models import SearchIndexer, SearchIndexerStatus - from typing import Any, Dict, Optional, Sequence - from azure.core.credentials import AzureKeyCredential - - -class SearchIndexersClient(HeadersMixin): - """A client to interact with Azure search service Indexers. - - This class is not normally instantiated directly, instead use - `get_indexers_client()` from a `SearchServiceClient` - - """ - - _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str - - def __init__(self, endpoint, credential, **kwargs): - # type: (str, AzureKeyCredential, **Any) -> None - - self._endpoint = endpoint # type: str - self._credential = credential # type: AzureKeyCredential - self._client = _SearchServiceClient( - endpoint=endpoint, sdk_moniker=SDK_MONIKER, **kwargs - ) # type: _SearchServiceClient - - def __enter__(self): - # type: () -> SearchIndexersClient - self._client.__enter__() # pylint:disable=no-member - return self - - def __exit__(self, *args): - # type: (*Any) -> None - return self._client.__exit__(*args) # pylint:disable=no-member - - def close(self): - # type: () -> None - """Close the :class:`~azure.search.documents.SearchIndexersClient` session. - - """ - return self._client.close() diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_indexes_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_indexes_client.py deleted file mode 100644 index be259290bf21..000000000000 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_indexes_client.py +++ /dev/null @@ -1,61 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -from typing import TYPE_CHECKING - -from azure.core import MatchConditions -from azure.core.tracing.decorator import distributed_trace -from azure.core.paging import ItemPaged - -from ._generated import SearchServiceClient as _SearchServiceClient -from ._utils import ( - delistize_flags_for_index, - listize_flags_for_index, - get_access_conditions, -) -from .._headers_mixin import HeadersMixin -from .._version import SDK_MONIKER - -if TYPE_CHECKING: - # pylint:disable=unused-import,ungrouped-imports - from ._generated.models import AnalyzeRequest, AnalyzeResult, SearchIndex - from typing import Any, Dict, List, Union - from azure.core.credentials import AzureKeyCredential - - -class SearchIndexesClient(HeadersMixin): - """A client to interact with Azure search service Indexes. - - This class is not normally instantiated directly, instead use - `get_skillsets_client()` from a `SearchServiceClient` - - """ - - _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str - - def __init__(self, endpoint, credential, **kwargs): - # type: (str, AzureKeyCredential, **Any) -> None - - self._endpoint = endpoint # type: str - self._credential = credential # type: AzureKeyCredential - self._client = _SearchServiceClient( - endpoint=endpoint, sdk_moniker=SDK_MONIKER, **kwargs - ) # type: _SearchServiceClient - - def __enter__(self): - # type: () -> SearchIndexesClient - self._client.__enter__() # pylint:disable=no-member - return self - - def __exit__(self, *args): - # type: (*Any) -> None - return self._client.__exit__(*args) # pylint:disable=no-member - - def close(self): - # type: () -> None - """Close the :class:`~azure.search.documents.SearchIndexesClient` session. - - """ - return self._client.close() diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py index d9dcbc3b04b1..fd3fa5bc3b8c 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py @@ -16,6 +16,7 @@ listize_flags_for_index, listize_synonyms, get_access_conditions, + normalize_endpoint, ) from .._headers_mixin import HeadersMixin from .._version import SDK_MONIKER @@ -36,7 +37,7 @@ class SearchIndexClient(HeadersMixin): def __init__(self, endpoint, credential, **kwargs): # type: (str, AzureKeyCredential, **Any) -> None - self._endpoint = endpoint # type: str + self._endpoint = normalize_endpoint(endpoint) # type: str self._credential = credential # type: AzureKeyCredential self._client = _SearchServiceClient( endpoint=endpoint, sdk_moniker=SDK_MONIKER, **kwargs diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_indexer_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_indexer_client.py index 98d6d60ff16d..2e75c9e9b2bc 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_indexer_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_indexer_client.py @@ -11,7 +11,7 @@ from ._generated import SearchServiceClient as _SearchServiceClient from ._generated.models import SearchIndexerSkillset -from ._utils import get_access_conditions +from ._utils import get_access_conditions, normalize_endpoint from .._headers_mixin import HeadersMixin from .._version import SDK_MONIKER @@ -35,7 +35,7 @@ class SearchIndexerClient(HeadersMixin): def __init__(self, endpoint, credential, **kwargs): # type: (str, AzureKeyCredential, **Any) -> None - self._endpoint = endpoint # type: str + self._endpoint = normalize_endpoint(endpoint) # type: str self._credential = credential # type: AzureKeyCredential self._client = _SearchServiceClient( endpoint=endpoint, sdk_moniker=SDK_MONIKER, **kwargs diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_service_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_service_client.py deleted file mode 100644 index 50578cfd632e..000000000000 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_service_client.py +++ /dev/null @@ -1,117 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -from typing import TYPE_CHECKING - -from azure.core.tracing.decorator import distributed_trace - -from ._search_service_client_base import SearchServiceClientBase -from ._generated import SearchServiceClient as _SearchServiceClient -from .._version import SDK_MONIKER -from ._datasources_client import SearchDataSourcesClient -from ._indexes_client import SearchIndexesClient -from ._indexers_client import SearchIndexersClient -from ._skillsets_client import SearchSkillsetsClient -from ._synonym_maps_client import SearchSynonymMapsClient - -if TYPE_CHECKING: - # pylint:disable=unused-import,ungrouped-imports - from typing import Any, Dict, List, Optional, Sequence - from azure.core.credentials import AzureKeyCredential - - -class SearchServiceClient(SearchServiceClientBase): # pylint: disable=too-many-public-methods - """A client to interact with an existing Azure search service. - - :param endpoint: The URL endpoint of an Azure search service - :type endpoint: str - :param credential: A credential to authorize search client requests - :type credential: ~azure.core.credentials.AzureKeyCredential - - .. admonition:: Example: - - .. literalinclude:: ../samples/sample_authentication.py - :start-after: [START create_search_service_client_with_key] - :end-before: [END create_search_service_client_with_key] - :language: python - :dedent: 4 - :caption: Creating the SearchServiceClient with an API key. - """ - - _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str - - def __init__(self, endpoint, credential, **kwargs): - # type: (str, AzureKeyCredential, **Any) -> None - super(SearchServiceClient, self).__init__(endpoint, credential, **kwargs) - self._client = _SearchServiceClient( - endpoint=endpoint, sdk_moniker=SDK_MONIKER, **kwargs - ) # type: _SearchServiceClient - self._indexes_client = SearchIndexesClient(endpoint, credential, **kwargs) - - self._synonym_maps_client = SearchSynonymMapsClient( - endpoint, credential, **kwargs - ) - - self._skillsets_client = SearchSkillsetsClient(endpoint, credential, **kwargs) - - self._datasources_client = SearchDataSourcesClient( - endpoint, credential, **kwargs - ) - - self._indexers_client = SearchIndexersClient(endpoint, credential, **kwargs) - - def __enter__(self): - # type: () -> SearchServiceClient - self._client.__enter__() # pylint:disable=no-member - return self - - def __exit__(self, *args): - # type: (*Any) -> None - return self._client.__exit__(*args) # pylint:disable=no-member - - def close(self): - # type: () -> None - """Close the :class:`~azure.search.documents.SearchServiceClient` session. - - """ - return self._client.close() - - @distributed_trace - def get_service_statistics(self, **kwargs): - # type: (**Any) -> dict - """Get service level statistics for a search service. - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = self._client.get_service_statistics(**kwargs) - return result.as_dict() - - - def get_skillsets_client(self): - # type: () -> SearchSkillsetsClient - """Return a client to perform operations on Skillsets. - - :return: The Skillsets client - :rtype: SearchSkillsetClient - """ - return self._skillsets_client - - def get_datasources_client(self): - # type: () -> SearchDataSourcesClient - """Return a client to perform operations on Data Sources. - - :return: The Data Sources client - :rtype: SearchDataSourcesClient - """ - return self._datasources_client - - def get_indexers_client(self): - # type: () -> SearchIndexersClient - """Return a client to perform operations on Data Sources. - - :return: The Data Sources client - :rtype: SearchDataSourcesClient - """ - return self._indexers_client diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_service_client_base.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_service_client_base.py deleted file mode 100644 index cccac76a15d4..000000000000 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_service_client_base.py +++ /dev/null @@ -1,36 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -from typing import TYPE_CHECKING - -from .._headers_mixin import HeadersMixin -from ._utils import _normalize_endpoint - -if TYPE_CHECKING: - # pylint:disable=unused-import,ungrouped-imports - from typing import Any, Dict, List, Optional, Sequence - from azure.core.credentials import AzureKeyCredential - - -class SearchServiceClientBase(HeadersMixin): # pylint: disable=too-many-public-methods - """A client to interact with an existing Azure search service. - - :param endpoint: The URL endpoint of an Azure search service - :type endpoint: str - :param credential: A credential to authorize search client requests - :type credential: ~azure.core.credentials import AzureKeyCredential - """ - - _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str - - def __init__(self, endpoint, credential): - # type: (str, AzureKeyCredential) -> None - - self._endpoint = _normalize_endpoint(endpoint) # type: str - self._credential = credential # type: AzureKeyCredential - - def __repr__(self): - # type: () -> str - return "".format(repr(self._endpoint))[:1024] diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_skillsets_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_skillsets_client.py deleted file mode 100644 index b1ab80342d80..000000000000 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_skillsets_client.py +++ /dev/null @@ -1,58 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -from typing import TYPE_CHECKING - -from azure.core import MatchConditions -from azure.core.tracing.decorator import distributed_trace -from azure.core.exceptions import ClientAuthenticationError, ResourceNotFoundError - -from ._generated import SearchServiceClient as _SearchServiceClient -from ._utils import get_access_conditions -from .._headers_mixin import HeadersMixin -from .._version import SDK_MONIKER - -if TYPE_CHECKING: - # pylint:disable=unused-import,ungrouped-imports - from ._generated.models import SearchIndexerSkill - from typing import Any, List, Sequence, Union - from azure.core.credentials import AzureKeyCredential - - -class SearchSkillsetsClient(HeadersMixin): - """A client to interact with Azure search service Skillsets. - - This class is not normally instantiated directly, instead use - `get_skillsets_client()` from a `SearchServiceClient` - - """ - - _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str - - def __init__(self, endpoint, credential, **kwargs): - # type: (str, AzureKeyCredential, **Any) -> None - - self._endpoint = endpoint # type: str - self._credential = credential # type: AzureKeyCredential - self._client = _SearchServiceClient( - endpoint=endpoint, sdk_moniker=SDK_MONIKER, **kwargs - ) # type: _SearchServiceClient - - def __enter__(self): - # type: () -> SearchSkillsetsClient - self._client.__enter__() # pylint:disable=no-member - return self - - def __exit__(self, *args): - # type: (*Any) -> None - return self._client.__exit__(*args) # pylint:disable=no-member - - def close(self): - # type: () -> None - """Close the :class:`~azure.search.documents.SearchSkillsetsClient` session. - - """ - return self._client.close() - diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_synonym_maps_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_synonym_maps_client.py deleted file mode 100644 index 1981adfe7d6d..000000000000 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_synonym_maps_client.py +++ /dev/null @@ -1,56 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -from typing import TYPE_CHECKING - -from azure.core import MatchConditions -from azure.core.tracing.decorator import distributed_trace - -from ._generated import SearchServiceClient as _SearchServiceClient -from ._generated.models import SynonymMap -from ._utils import listize_synonyms, get_access_conditions -from .._headers_mixin import HeadersMixin -from .._version import SDK_MONIKER - -if TYPE_CHECKING: - # pylint:disable=unused-import,ungrouped-imports - from typing import Any, Dict, List, Sequence, Union, Optional - from azure.core.credentials import AzureKeyCredential - - -class SearchSynonymMapsClient(HeadersMixin): - """A client to interact with Azure search service Synonym Maps. - - This class is not normally instantiated directly, instead use - `get_synonym_maps_client()` from a `SearchServiceClient` - - """ - - _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str - - def __init__(self, endpoint, credential, **kwargs): - # type: (str, AzureKeyCredential, **Any) -> None - - self._endpoint = endpoint # type: str - self._credential = credential # type: AzureKeyCredential - self._client = _SearchServiceClient( - endpoint=endpoint, sdk_moniker=SDK_MONIKER, **kwargs - ) # type: _SearchServiceClient - - def __enter__(self): - # type: () -> SearchSynonymMapsClient - self._client.__enter__() # pylint:disable=no-member - return self - - def __exit__(self, *args): - # type: (*Any) -> None - return self._client.__exit__(*args) # pylint:disable=no-member - - def close(self): - # type: () -> None - """Close the :class:`~azure.search.documents.SearchSynonymMapsClient` session. - - """ - return self._client.close() diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_utils.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_utils.py index b19457bf6c9e..e6cf1a808932 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_utils.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/_utils.py @@ -184,7 +184,7 @@ def get_access_conditions(model, match_condition=MatchConditions.Unconditionally except AttributeError: raise ValueError("Unable to get e_tag from the model") -def _normalize_endpoint(endpoint): +def normalize_endpoint(endpoint): try: if not endpoint.lower().startswith('http'): endpoint = "https://" + endpoint diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/__init__.py b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/__init__.py index 28c06ccbb2bb..49c60a65974d 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/__init__.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/__init__.py @@ -2,19 +2,10 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # ------------------------------------ -from ._search_service_client_async import SearchServiceClient - -from ._datasources_client import SearchDataSourcesClient -from ._indexers_client import SearchIndexersClient -from ._indexes_client import SearchIndexesClient -from ._skillsets_client import SearchSkillsetsClient -from ._synonym_maps_client import SearchSynonymMapsClient +from ._search_indexer_client import SearchIndexerClient +from ._search_index_client import SearchIndexClient __all__ = ( - "SearchServiceClient", - "SearchDataSourcesClient", - "SearchIndexersClient", - "SearchIndexesClient", - "SearchSkillsetsClient", - "SearchSynonymMapsClient", + "SearchIndexerClient", + "SearchIndexClient", ) diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_datasources_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_datasources_client.py deleted file mode 100644 index b30973a2d89d..000000000000 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_datasources_client.py +++ /dev/null @@ -1,57 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -from typing import TYPE_CHECKING - -from azure.core import MatchConditions -from azure.core.tracing.decorator_async import distributed_trace_async - -from .._generated.aio import SearchServiceClient as _SearchServiceClient -from .._utils import get_access_conditions -from ..._headers_mixin import HeadersMixin -from ..._version import SDK_MONIKER - -if TYPE_CHECKING: - # pylint:disable=unused-import,ungrouped-imports - from .._generated.models import SearchIndexerDataSource - from typing import Any, Dict, Optional, Sequence, Union - from azure.core.credentials import AzureKeyCredential - - -class SearchDataSourcesClient(HeadersMixin): - """A client to interact with Azure search service Data Sources. - - This class is not normally instantiated directly, instead use - `get_datasources_client()` from a `SearchServiceClient` - - """ - - _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str - - def __init__(self, endpoint, credential, **kwargs): - # type: (str, AzureKeyCredential, **Any) -> None - - self._endpoint = endpoint # type: str - self._credential = credential # type: AzureKeyCredential - self._client = _SearchServiceClient( - endpoint=endpoint, sdk_moniker=SDK_MONIKER, **kwargs - ) # type: _SearchServiceClient - - async def __aenter__(self): - # type: () -> SearchDataSourcesClient - await self._client.__aenter__() # pylint:disable=no-member - return self - - async def __aexit__(self, *args): - # type: (*Any) -> None - return await self._client.__aexit__(*args) # pylint:disable=no-member - - async def close(self): - # type: () -> None - """Close the :class:`~azure.search.documents.aio.SearchDataSourcesClient` session. - - """ - return await self._client.close() - diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_indexers_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_indexers_client.py deleted file mode 100644 index c6a1a0f3e7dd..000000000000 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_indexers_client.py +++ /dev/null @@ -1,56 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -from typing import TYPE_CHECKING - -from azure.core import MatchConditions -from azure.core.tracing.decorator_async import distributed_trace_async - -from .._generated.aio import SearchServiceClient as _SearchServiceClient -from .._utils import get_access_conditions -from ..._headers_mixin import HeadersMixin -from ..._version import SDK_MONIKER - -if TYPE_CHECKING: - # pylint:disable=unused-import,ungrouped-imports - from .._generated.models import SearchIndexer, SearchIndexerStatus - from typing import Any, Dict, Optional, Sequence - from azure.core.credentials import AzureKeyCredential - - -class SearchIndexersClient(HeadersMixin): - """A client to interact with Azure search service Indexers. - - This class is not normally instantiated directly, instead use - `get_indexers_client()` from a `SearchServiceClient` - - """ - - _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str - - def __init__(self, endpoint, credential, **kwargs): - # type: (str, AzureKeyCredential, **Any) -> None - - self._endpoint = endpoint # type: str - self._credential = credential # type: AzureKeyCredential - self._client = _SearchServiceClient( - endpoint=endpoint, sdk_moniker=SDK_MONIKER, **kwargs - ) # type: _SearchServiceClient - - async def __aenter__(self): - # type: () -> SearchIndexersClient - await self._client.__aenter__() # pylint:disable=no-member - return self - - async def __aexit__(self, *args): - # type: (*Any) -> None - return await self._client.__aexit__(*args) # pylint:disable=no-member - - async def close(self): - # type: () -> None - """Close the :class:`~azure.search.documents.aio.SearchIndexersClient` session. - - """ - return await self._client.close() diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_indexes_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_indexes_client.py deleted file mode 100644 index 8c0e5ab71ab2..000000000000 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_indexes_client.py +++ /dev/null @@ -1,60 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -from typing import TYPE_CHECKING - -from azure.core import MatchConditions -from azure.core.tracing.decorator_async import distributed_trace_async -from azure.core.async_paging import AsyncItemPaged -from .._generated.aio import SearchServiceClient as _SearchServiceClient -from .._utils import ( - delistize_flags_for_index, - listize_flags_for_index, - get_access_conditions, -) -from ..._headers_mixin import HeadersMixin -from ..._version import SDK_MONIKER - -if TYPE_CHECKING: - # pylint:disable=unused-import,ungrouped-imports - from .._generated.models import AnalyzeRequest, AnalyzeResult, SearchIndex - from typing import Any, Dict, List, Union - from azure.core.credentials import AzureKeyCredential - - -class SearchIndexesClient(HeadersMixin): - """A client to interact with Azure search service Indexes. - - This class is not normally instantiated directly, instead use - `get_skillsets_client()` from a `SearchServiceClient` - - """ - - _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str - - def __init__(self, endpoint, credential, **kwargs): - # type: (str, AzureKeyCredential, **Any) -> None - - self._endpoint = endpoint # type: str - self._credential = credential # type: AzureKeyCredential - self._client = _SearchServiceClient( - endpoint=endpoint, sdk_moniker=SDK_MONIKER, **kwargs - ) # type: _SearchServiceClient - - async def __aenter__(self): - # type: () -> SearchIndexesClient - await self._client.__aenter__() # pylint:disable=no-member - return self - - async def __aexit__(self, *args): - # type: (*Any) -> None - return await self._client.__aexit__(*args) # pylint:disable=no-member - - async def close(self): - # type: () -> None - """Close the :class:`~azure.search.documents.SearchIndexesClient` session. - - """ - return await self._client.close() diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_index_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_index_client.py index 3a85114fbaaf..a00aa1a82c14 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_index_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_index_client.py @@ -15,6 +15,7 @@ listize_flags_for_index, listize_synonyms, get_access_conditions, + normalize_endpoint, ) from ..._headers_mixin import HeadersMixin from ..._version import SDK_MONIKER @@ -39,7 +40,7 @@ class SearchIndexClient(HeadersMixin): def __init__(self, endpoint, credential, **kwargs): # type: (str, AzureKeyCredential, **Any) -> None - self._endpoint = endpoint # type: str + self._endpoint = normalize_endpoint(endpoint) # type: str self._credential = credential # type: AzureKeyCredential self._client = _SearchServiceClient( endpoint=endpoint, sdk_moniker=SDK_MONIKER, **kwargs diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_indexer_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_indexer_client.py index 8008a0ce77bf..49109cac771d 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_indexer_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_indexer_client.py @@ -11,7 +11,7 @@ from .._generated.aio import SearchServiceClient as _SearchServiceClient from .._generated.models import SearchIndexerSkillset -from .._utils import get_access_conditions +from .._utils import get_access_conditions, normalize_endpoint from ..._headers_mixin import HeadersMixin from ..._version import SDK_MONIKER @@ -32,7 +32,7 @@ class SearchIndexerClient(HeadersMixin): def __init__(self, endpoint, credential, **kwargs): # type: (str, AzureKeyCredential, **Any) -> None - self._endpoint = endpoint # type: str + self._endpoint = normalize_endpoint(endpoint) # type: str self._credential = credential # type: AzureKeyCredential self._client = _SearchServiceClient( endpoint=endpoint, sdk_moniker=SDK_MONIKER, **kwargs diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_service_client_async.py b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_service_client_async.py deleted file mode 100644 index 82db403cbfca..000000000000 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_service_client_async.py +++ /dev/null @@ -1,134 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -from typing import TYPE_CHECKING - -from azure.core.tracing.decorator_async import distributed_trace_async - -from .._generated.aio import SearchServiceClient as _SearchServiceClient -from .._search_service_client_base import SearchServiceClientBase -from ..._version import SDK_MONIKER -from ._datasources_client import SearchDataSourcesClient -from ._indexes_client import SearchIndexesClient -from ._indexers_client import SearchIndexersClient -from ._skillsets_client import SearchSkillsetsClient -from ._synonym_maps_client import SearchSynonymMapsClient - -if TYPE_CHECKING: - # pylint:disable=unused-import,ungrouped-imports - from typing import Any, Dict, List, Optional, Sequence - from azure.core.credentials import AzureKeyCredential - - -class SearchServiceClient(SearchServiceClientBase): # pylint: disable=too-many-public-methods - """A client to interact with an existing Azure search service. - - :param endpoint: The URL endpoint of an Azure search service - :type endpoint: str - :param credential: A credential to authorize search client requests - :type credential: ~azure.core.credentials import AzureKeyCredential - - .. admonition:: Example: - - .. literalinclude:: ../samples/async_samples/sample_authentication_async.py - :start-after: [START create_search_service_with_key_async] - :end-before: [END create_search_service_with_key_async] - :language: python - :dedent: 4 - :caption: Creating the SearchServiceClient with an API key. - """ - - _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str - - def __init__(self, endpoint, credential, **kwargs): - # type: (str, AzureKeyCredential, **Any) -> None - - super().__init__(endpoint, credential, **kwargs) - self._client = _SearchServiceClient( - endpoint=endpoint, sdk_moniker=SDK_MONIKER, **kwargs - ) # type: _SearchServiceClient - - self._indexes_client = SearchIndexesClient(endpoint, credential, **kwargs) - - self._synonym_maps_client = SearchSynonymMapsClient( - endpoint, credential, **kwargs - ) - - self._skillsets_client = SearchSkillsetsClient(endpoint, credential, **kwargs) - - self._datasources_client = SearchDataSourcesClient( - endpoint, credential, **kwargs - ) - - self._indexers_client = SearchIndexersClient(endpoint, credential, **kwargs) - - async def __aenter__(self): - # type: () -> SearchServiceClient - await self._client.__aenter__() # pylint:disable=no-member - return self - - async def __aexit__(self, *args): - # type: (*Any) -> None - return await self._client.__aexit__(*args) # pylint:disable=no-member - - async def close(self): - # type: () -> None - """Close the :class:`~azure.search.documents.aio.SearchServiceClient` session. - - """ - return await self._client.close() - - @distributed_trace_async - async def get_service_statistics(self, **kwargs): - # type: (**Any) -> dict - """Get service level statistics for a search service. - - """ - kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) - result = await self._client.get_service_statistics(**kwargs) - return result.as_dict() - - def get_indexes_client(self): - # type: () -> SearchIndexesClient - """Return a client to perform operations on Search Indexes. - - :return: The Search Indexes client - :rtype: SearchIndexesClient - """ - return self._indexes_client - - def get_synonym_maps_client(self): - # type: () -> SearchSynonymMapsClient - """Return a client to perform operations on Synonym Maps. - - :return: The Synonym Maps client - :rtype: SearchSynonymMapsClient - """ - return self._synonym_maps_client - - def get_skillsets_client(self) -> SearchSkillsetsClient: - """Return a client to perform operations on Skillsets. - - :return: The Skillsets client - :rtype: SearchSkillsetsClient - """ - return self._skillsets_client - - def get_datasources_client(self) -> SearchDataSourcesClient: - """Return a client to perform operations on Data Sources. - - :return: The Data Sources client - :rtype: SearchDataSourcesClient - """ - return self._datasources_client - - def get_indexers_client(self): - # type: () -> SearchIndexersClient - """Return a client to perform operations on Data Sources. - - :return: The Data Sources client - :rtype: SearchDataSourcesClient - """ - return self._indexers_client diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_skillsets_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_skillsets_client.py deleted file mode 100644 index 5f72362c410e..000000000000 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_skillsets_client.py +++ /dev/null @@ -1,59 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -from typing import TYPE_CHECKING - -from azure.core import MatchConditions -from azure.core.exceptions import ClientAuthenticationError, ResourceNotFoundError -from azure.core.tracing.decorator_async import distributed_trace_async - -from .._generated.aio import SearchServiceClient as _SearchServiceClient -from .._generated.models import SearchIndexerSkillset -from .._utils import get_access_conditions -from ..._headers_mixin import HeadersMixin -from ..._version import SDK_MONIKER - -if TYPE_CHECKING: - # pylint:disable=unused-import,ungrouped-imports - from .._generated.models import SearchIndexerSkill - from typing import Any, List, Sequence, Union - from azure.core.credentials import AzureKeyCredential - - -class SearchSkillsetsClient(HeadersMixin): - """A client to interact with Azure search service Skillsets. - - This class is not normally instantiated directly, instead use - `get_skillsets_client()` from a `SearchServiceClient` - - """ - - _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str - - def __init__(self, endpoint, credential, **kwargs): - # type: (str, AzureKeyCredential, **Any) -> None - - self._endpoint = endpoint # type: str - self._credential = credential # type: AzureKeyCredential - self._client = _SearchServiceClient( - endpoint=endpoint, sdk_moniker=SDK_MONIKER, **kwargs - ) # type: _SearchServiceClient - - async def __aenter__(self): - # type: () -> SearchSkillsetsClient - await self._client.__aenter__() # pylint:disable=no-member - return self - - async def __aexit__(self, *args): - # type: (*Any) -> None - return await self._client.__aexit__(*args) # pylint:disable=no-member - - async def close(self): - # type: () -> None - """Close the :class:`~azure.search.documents.aio.SearchSkillsetsClient` session. - - """ - return await self._client.close() - diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_synonym_maps_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_synonym_maps_client.py deleted file mode 100644 index e67a268b18bb..000000000000 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_synonym_maps_client.py +++ /dev/null @@ -1,57 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -from typing import TYPE_CHECKING - -from azure.core import MatchConditions -from azure.core.tracing.decorator_async import distributed_trace_async - -from .._generated.aio import SearchServiceClient as _SearchServiceClient -from .._generated.models import SynonymMap -from .._utils import listize_synonyms, get_access_conditions -from ..._headers_mixin import HeadersMixin -from ..._version import SDK_MONIKER - -if TYPE_CHECKING: - # pylint:disable=unused-import,ungrouped-imports - from typing import Any, Dict, List, Sequence, Union, Optional - from azure.core.credentials import AzureKeyCredential - - -class SearchSynonymMapsClient(HeadersMixin): - """A client to interact with Azure search service Synonym Maps. - - This class is not normally instantiated directly, instead use - `get_synonym_maps_client()` from a `SearchServiceClient` - - """ - - _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str - - def __init__(self, endpoint, credential, **kwargs): - # type: (str, AzureKeyCredential, **Any) -> None - - self._endpoint = endpoint # type: str - self._credential = credential # type: AzureKeyCredential - self._client = _SearchServiceClient( - endpoint=endpoint, sdk_moniker=SDK_MONIKER, **kwargs - ) # type: _SearchServiceClient - - async def __aenter__(self): - # type: () -> SearchSynonymMapsClient - await self._client.__aenter__() # pylint:disable=no-member - return self - - async def __aexit__(self, *args): - # type: (*Any) -> None - return await self._client.__aexit__(*args) # pylint:disable=no-member - - async def close(self): - # type: () -> None - """Close the :class:`~azure.search.documents.aio.SearchSynonymMapsClient` session. - - """ - return await self._client.close() - diff --git a/sdk/search/azure-search-documents/azure/search/documents/aio.py b/sdk/search/azure-search-documents/azure/search/documents/aio.py index 565c6e7cf240..19c037e557f0 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/aio.py +++ b/sdk/search/azure-search-documents/azure/search/documents/aio.py @@ -26,21 +26,13 @@ from ._index.aio import AsyncSearchItemPaged, SearchClient from ._service.aio import ( - SearchServiceClient, - SearchDataSourcesClient, - SearchIndexersClient, - SearchIndexesClient, - SearchSkillsetsClient, - SearchSynonymMapsClient, + SearchIndexClient, + SearchIndexerClient, ) __all__ = ( "AsyncSearchItemPaged", "SearchClient", - "SearchServiceClient", - "SearchDataSourcesClient", - "SearchIndexersClient", - "SearchIndexesClient", - "SearchSkillsetsClient", - "SearchSynonymMapsClient", + "SearchIndexClient", + "SearchIndexerClient", ) diff --git a/sdk/search/azure-search-documents/tests/async_tests/test_service_live_async.py b/sdk/search/azure-search-documents/tests/async_tests/test_service_live_async.py index 0ee80d5e4112..91fc208abe08 100644 --- a/sdk/search/azure-search-documents/tests/async_tests/test_service_live_async.py +++ b/sdk/search/azure-search-documents/tests/async_tests/test_service_live_async.py @@ -27,7 +27,6 @@ SearchIndex, InputFieldMappingEntry, OutputFieldMappingEntry, - SearchServiceClient, ScoringProfile, SearchIndexerSkillset, DataSourceCredentials, @@ -38,9 +37,7 @@ SimpleField, edm ) -from azure.search.documents.aio import SearchServiceClient -from azure.search.documents._service.aio._search_index_client import SearchIndexClient -from azure.search.documents._service.aio._search_indexer_client import SearchIndexerClient +from azure.search.documents.aio import SearchIndexClient, SearchIndexerClient from _test_utils import build_synonym_map_from_dict CWD = dirname(realpath(__file__)) diff --git a/sdk/search/azure-search-documents/tests/test_search_service_client.py b/sdk/search/azure-search-documents/tests/test_search_service_client.py index 167d46936cd9..50c18db1391f 100644 --- a/sdk/search/azure-search-documents/tests/test_search_service_client.py +++ b/sdk/search/azure-search-documents/tests/test_search_service_client.py @@ -11,22 +11,22 @@ import mock from azure.core.credentials import AzureKeyCredential -from azure.search.documents import SearchServiceClient +from azure.search.documents import SearchIndexClient, SearchIndexerClient CREDENTIAL = AzureKeyCredential(key="test_api_key") -class TestSearchServiceClient(object): - def test_init(self): - client = SearchServiceClient("endpoint", CREDENTIAL) +class TestSearchIndexClient(object): + def test_index_init(self): + client = SearchIndexClient("endpoint", CREDENTIAL) assert client._headers == { "api-key": "test_api_key", "Accept": "application/json;odata.metadata=minimal", } - def test_credential_roll(self): + def test_index_credential_roll(self): credential = AzureKeyCredential(key="old_api_key") - client = SearchServiceClient("endpoint", credential) + client = SearchIndexClient("endpoint", credential) assert client._headers == { "api-key": "old_api_key", "Accept": "application/json;odata.metadata=minimal", @@ -37,32 +37,62 @@ def test_credential_roll(self): "Accept": "application/json;odata.metadata=minimal", } - def test_repr(self): - client = SearchServiceClient("endpoint", CREDENTIAL) - assert repr(client) == "".format( - repr("https://endpoint") - ) - @mock.patch( "azure.search.documents._service._generated._search_service_client.SearchServiceClient.get_service_statistics" ) def test_get_service_statistics(self, mock_get_stats): - client = SearchServiceClient("endpoint", CREDENTIAL) + client = SearchIndexClient("endpoint", CREDENTIAL) client.get_service_statistics() assert mock_get_stats.called assert mock_get_stats.call_args[0] == () assert mock_get_stats.call_args[1] == {"headers": client._headers} - def test_endpoint_https(self): + def test_index_endpoint_https(self): + credential = AzureKeyCredential(key="old_api_key") + client = SearchIndexClient("endpoint", credential) + assert client._endpoint.startswith('https') + + client = SearchIndexClient("https://endpoint", credential) + assert client._endpoint.startswith('https') + + with pytest.raises(ValueError): + client = SearchIndexClient("http://endpoint", credential) + + with pytest.raises(ValueError): + client = SearchIndexClient(12345, credential) + + +class TestSearchIndexerClient(object): + def test_indexer_init(self): + client = SearchIndexerClient("endpoint", CREDENTIAL) + assert client._headers == { + "api-key": "test_api_key", + "Accept": "application/json;odata.metadata=minimal", + } + + def test_indexer_credential_roll(self): + credential = AzureKeyCredential(key="old_api_key") + client = SearchIndexerClient("endpoint", credential) + assert client._headers == { + "api-key": "old_api_key", + "Accept": "application/json;odata.metadata=minimal", + } + credential.update("new_api_key") + assert client._headers == { + "api-key": "new_api_key", + "Accept": "application/json;odata.metadata=minimal", + } + + def test_indexer_endpoint_https(self): credential = AzureKeyCredential(key="old_api_key") - client = SearchServiceClient("endpoint", credential) + client = SearchIndexerClient("endpoint", credential) assert client._endpoint.startswith('https') - client = SearchServiceClient("https://endpoint", credential) + client = SearchIndexerClient("https://endpoint", credential) assert client._endpoint.startswith('https') with pytest.raises(ValueError): - client = SearchServiceClient("http://endpoint", credential) + client = SearchIndexerClient("http://endpoint", credential) with pytest.raises(ValueError): - client = SearchServiceClient(12345, credential) + client = SearchIndexerClient(12345, credential) diff --git a/sdk/search/azure-search-documents/tests/test_service_live.py b/sdk/search/azure-search-documents/tests/test_service_live.py index f752a53360f3..b1978514615c 100644 --- a/sdk/search/azure-search-documents/tests/test_service_live.py +++ b/sdk/search/azure-search-documents/tests/test_service_live.py @@ -24,7 +24,8 @@ SearchIndex, InputFieldMappingEntry, OutputFieldMappingEntry, - SearchServiceClient, + SearchIndexClient, + SearchIndexerClient, ScoringProfile, SearchIndexerSkillset, DataSourceCredentials, @@ -35,8 +36,6 @@ SimpleField, edm ) -from azure.search.documents._service._search_index_client import SearchIndexClient -from azure.search.documents._service._search_indexer_client import SearchIndexerClient from _test_utils import build_synonym_map_from_dict CWD = dirname(realpath(__file__)) From 4fa1dcf55f7af7d75323ac274306ce6fd0cfc814 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 20 May 2020 19:58:41 -0700 Subject: [PATCH 05/12] update changelog --- sdk/search/azure-search-documents/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sdk/search/azure-search-documents/CHANGELOG.md b/sdk/search/azure-search-documents/CHANGELOG.md index 23071b1d6a54..82060da8852d 100644 --- a/sdk/search/azure-search-documents/CHANGELOG.md +++ b/sdk/search/azure-search-documents/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 1.0.0b4 (Unreleased) + +**Breaking Changes** + +- Reorganized `SearchServiceClient` into `SearchIndexClient` & `SearchIndexerClient` #11572 + ## 1.0.0b3 (2020-05-04) **Features** From 02b9600d1a0eefb11e0ff8fab7332d44f210b691 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 20 May 2020 20:00:08 -0700 Subject: [PATCH 06/12] update --- sdk/search/azure-search-documents/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/search/azure-search-documents/CHANGELOG.md b/sdk/search/azure-search-documents/CHANGELOG.md index 82060da8852d..abad78cf4b14 100644 --- a/sdk/search/azure-search-documents/CHANGELOG.md +++ b/sdk/search/azure-search-documents/CHANGELOG.md @@ -4,7 +4,7 @@ **Breaking Changes** -- Reorganized `SearchServiceClient` into `SearchIndexClient` & `SearchIndexerClient` #11572 +- Reorganized `SearchServiceClient` into `SearchIndexClient` & `SearchIndexerClient` #11507 ## 1.0.0b3 (2020-05-04) From 7d067c233783573b078b66650249104434c277f0 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 20 May 2020 20:22:42 -0700 Subject: [PATCH 07/12] get_search_client --- .../_service/_search_index_client.py | 13 +++ .../_service/aio/_search_index_client.py | 11 ++ .../test_search_service_client_async.py | 107 ++++++++++++++++++ .../tests/test_search_service_client.py | 8 +- 4 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 sdk/search/azure-search-documents/tests/async_tests/test_search_service_client_async.py diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py index fd3fa5bc3b8c..454ff267e9b9 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py @@ -20,6 +20,7 @@ ) from .._headers_mixin import HeadersMixin from .._version import SDK_MONIKER +from .. import SearchClient if TYPE_CHECKING: # pylint:disable=unused-import,ungrouped-imports @@ -59,6 +60,18 @@ def close(self): """ return self._client.close() + @distributed_trace + def get_search_client(self, index_name, **kwargs): + # type: (str, dict) -> SearchClient + """Return a client to perform operations on Search + + :param index_name: The name of the Search Index + :type index_name: str + :rtype: ~azure.search.documents.SearchClient + + """ + return SearchClient(self._endpoint, index_name, self._credential, **kwargs) + @distributed_trace def list_indexes(self, **kwargs): # type: (**Any) -> ItemPaged[SearchIndex] diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_index_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_index_client.py index a00aa1a82c14..1498bdf4bd6c 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_index_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_index_client.py @@ -10,6 +10,7 @@ from azure.core.async_paging import AsyncItemPaged from .._generated.aio import SearchServiceClient as _SearchServiceClient from .._generated.models import SynonymMap +from ...aio import SearchClient from .._utils import ( delistize_flags_for_index, listize_flags_for_index, @@ -62,6 +63,16 @@ async def close(self): """ return await self._client.close() + def get_search_client(self, index_name, **kwargs): + # type: (str, dict) -> SearchClient + """Return a client to perform operations on Search. + + :param index_name: The name of the Search Index + :type index_name: str + :rtype: ~azure.search.documents.aio.SearchClient + """ + return SearchClient(self._endpoint, index_name, self._credential, **kwargs) + @distributed_trace_async async def list_indexes(self, **kwargs): # type: (**Any) -> AsyncItemPaged[SearchIndex] diff --git a/sdk/search/azure-search-documents/tests/async_tests/test_search_service_client_async.py b/sdk/search/azure-search-documents/tests/async_tests/test_search_service_client_async.py new file mode 100644 index 000000000000..10fd55b3bb20 --- /dev/null +++ b/sdk/search/azure-search-documents/tests/async_tests/test_search_service_client_async.py @@ -0,0 +1,107 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ +import asyncio +import functools +import pytest + +try: + from unittest import mock +except ImportError: + import mock +from azure_devtools.scenario_tests.utilities import trim_kwargs_from_test_function +from azure.core.credentials import AzureKeyCredential +from azure.search.documents.aio import SearchClient, SearchIndexClient, SearchIndexerClient + +CREDENTIAL = AzureKeyCredential(key="test_api_key") + +def await_prepared_test(test_fn): + """Synchronous wrapper for async test methods. Used to avoid making changes + upstream to AbstractPreparer (which doesn't await the functions it wraps) + """ + + @functools.wraps(test_fn) + def run(test_class_instance, *args, **kwargs): + trim_kwargs_from_test_function(test_fn, kwargs) + loop = asyncio.get_event_loop() + return loop.run_until_complete(test_fn(test_class_instance, **kwargs)) + + return run + +class TestSearchIndexClient(object): + def test_index_init(self): + client = SearchIndexClient("endpoint", CREDENTIAL) + assert client._headers == { + "api-key": "test_api_key", + "Accept": "application/json;odata.metadata=minimal", + } + + def test_index_credential_roll(self): + credential = AzureKeyCredential(key="old_api_key") + client = SearchIndexClient("endpoint", credential) + assert client._headers == { + "api-key": "old_api_key", + "Accept": "application/json;odata.metadata=minimal", + } + credential.update("new_api_key") + assert client._headers == { + "api-key": "new_api_key", + "Accept": "application/json;odata.metadata=minimal", + } + + def test_get_search_client(self): + credential = AzureKeyCredential(key="old_api_key") + client = SearchIndexClient("endpoint", credential) + search_client = client.get_search_client('index') + assert isinstance(search_client, SearchClient) + + def test_index_endpoint_https(self): + credential = AzureKeyCredential(key="old_api_key") + client = SearchIndexClient("endpoint", credential) + assert client._endpoint.startswith('https') + + client = SearchIndexClient("https://endpoint", credential) + assert client._endpoint.startswith('https') + + with pytest.raises(ValueError): + client = SearchIndexClient("http://endpoint", credential) + + with pytest.raises(ValueError): + client = SearchIndexClient(12345, credential) + + +class TestSearchIndexerClient(object): + def test_indexer_init(self): + client = SearchIndexerClient("endpoint", CREDENTIAL) + assert client._headers == { + "api-key": "test_api_key", + "Accept": "application/json;odata.metadata=minimal", + } + + def test_indexer_credential_roll(self): + credential = AzureKeyCredential(key="old_api_key") + client = SearchIndexerClient("endpoint", credential) + assert client._headers == { + "api-key": "old_api_key", + "Accept": "application/json;odata.metadata=minimal", + } + credential.update("new_api_key") + assert client._headers == { + "api-key": "new_api_key", + "Accept": "application/json;odata.metadata=minimal", + } + + def test_indexer_endpoint_https(self): + credential = AzureKeyCredential(key="old_api_key") + client = SearchIndexerClient("endpoint", credential) + assert client._endpoint.startswith('https') + + client = SearchIndexerClient("https://endpoint", credential) + assert client._endpoint.startswith('https') + + with pytest.raises(ValueError): + client = SearchIndexerClient("http://endpoint", credential) + + with pytest.raises(ValueError): + client = SearchIndexerClient(12345, credential) diff --git a/sdk/search/azure-search-documents/tests/test_search_service_client.py b/sdk/search/azure-search-documents/tests/test_search_service_client.py index 50c18db1391f..b32b0d98d754 100644 --- a/sdk/search/azure-search-documents/tests/test_search_service_client.py +++ b/sdk/search/azure-search-documents/tests/test_search_service_client.py @@ -11,7 +11,7 @@ import mock from azure.core.credentials import AzureKeyCredential -from azure.search.documents import SearchIndexClient, SearchIndexerClient +from azure.search.documents import SearchClient, SearchIndexClient, SearchIndexerClient CREDENTIAL = AzureKeyCredential(key="test_api_key") @@ -37,6 +37,12 @@ def test_index_credential_roll(self): "Accept": "application/json;odata.metadata=minimal", } + def test_get_search_client(self): + credential = AzureKeyCredential(key="old_api_key") + client = SearchIndexClient("endpoint", credential) + search_client = client.get_search_client('index') + assert isinstance(search_client, SearchClient) + @mock.patch( "azure.search.documents._service._generated._search_service_client.SearchServiceClient.get_service_statistics" ) From b94c5311ac787b745aee8008c448d2753f36f58a Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 20 May 2020 20:23:11 -0700 Subject: [PATCH 08/12] update version --- .../azure-search-documents/azure/search/documents/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/search/azure-search-documents/azure/search/documents/_version.py b/sdk/search/azure-search-documents/azure/search/documents/_version.py index e9adc155cfcf..10e578c87b24 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_version.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_version.py @@ -3,6 +3,6 @@ # Licensed under the MIT License. # ------------------------------------ -VERSION = "1.0.0b3" # type: str +VERSION = "1.0.0b4" # type: str SDK_MONIKER = "search-documents/{}".format(VERSION) # type: str From 2f72ebf6cdef7c58b49d71333255c5f7edea8d5b Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 20 May 2020 20:38:39 -0700 Subject: [PATCH 09/12] pylint --- .../azure-search-documents/azure/search/documents/__init__.py | 2 -- .../azure/search/documents/_service/_search_index_client.py | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/sdk/search/azure-search-documents/azure/search/documents/__init__.py b/sdk/search/azure-search-documents/azure/search/documents/__init__.py index a640ced8b894..309814cf85f2 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/__init__.py +++ b/sdk/search/azure-search-documents/azure/search/documents/__init__.py @@ -130,8 +130,6 @@ WordDelimiterTokenFilter, ) from ._service._models import PatternAnalyzer, PatternTokenizer -from ._service._search_indexer_client import SearchIndexerClient -from ._service._search_index_client import SearchIndexClient from ._version import VERSION __version__ = VERSION diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py index 454ff267e9b9..7cc62599032a 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py @@ -30,9 +30,9 @@ class SearchIndexClient(HeadersMixin): """A client to interact with Azure search service index. - - """ + """ + _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str def __init__(self, endpoint, credential, **kwargs): From 3d80080c26e3029559755a747928ced1fd31c01e Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 20 May 2020 20:51:46 -0700 Subject: [PATCH 10/12] update --- .../azure/search/documents/_service/_search_index_client.py | 4 ++-- .../azure/search/documents/_service/_search_indexer_client.py | 2 +- .../search/documents/_service/aio/_search_index_client.py | 2 +- .../search/documents/_service/aio/_search_indexer_client.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py index 7cc62599032a..65ae7e65dc5c 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py @@ -32,7 +32,7 @@ class SearchIndexClient(HeadersMixin): """A client to interact with Azure search service index. """ - + _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str def __init__(self, endpoint, credential, **kwargs): @@ -55,7 +55,7 @@ def __exit__(self, *args): def close(self): # type: () -> None - """Close the :class:`~azure.search.documents.SearchSynonymMapsClient` session. + """Close the :class:`~azure.search.documents.SearchIndexClient` session. """ return self._client.close() diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_indexer_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_indexer_client.py index 2e75c9e9b2bc..e528a6d6413b 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_indexer_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_indexer_client.py @@ -52,7 +52,7 @@ def __exit__(self, *args): def close(self): # type: () -> None - """Close the :class:`~azure.search.documents.SearchIndexersClient` session. + """Close the :class:`~azure.search.documents.SearchIndexerClient` session. """ return self._client.close() diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_index_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_index_client.py index 1498bdf4bd6c..e44334f9c03c 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_index_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_index_client.py @@ -58,7 +58,7 @@ async def __aexit__(self, *args): async def close(self): # type: () -> None - """Close the :class:`~azure.search.documents.SearchIndexesClient` session. + """Close the :class:`~azure.search.documents.aio.SearchIndexClient` session. """ return await self._client.close() diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_indexer_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_indexer_client.py index 49109cac771d..4f844c27ba2c 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_indexer_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_indexer_client.py @@ -49,7 +49,7 @@ async def __aexit__(self, *args): async def close(self): # type: () -> None - """Close the :class:`~azure.search.documents.aio.SearchIndexersClient` session. + """Close the :class:`~azure.search.documents.aio.SearchIndexerClient` session. """ return await self._client.close() From bc34f2fb781b6f829466601f923855af50f11768 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 20 May 2020 21:34:23 -0700 Subject: [PATCH 11/12] update --- .../azure/search/documents/_service/_search_index_client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py index 65ae7e65dc5c..edd6388c2a37 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py @@ -32,7 +32,6 @@ class SearchIndexClient(HeadersMixin): """A client to interact with Azure search service index. """ - _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str def __init__(self, endpoint, credential, **kwargs): From a896838ee19887e3b7c1124a7ad7848a328b329e Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Thu, 21 May 2020 09:51:04 -0700 Subject: [PATCH 12/12] don't need trace for get_search_client --- .../azure/search/documents/_service/_search_index_client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py index edd6388c2a37..4317559fb208 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py @@ -59,7 +59,6 @@ def close(self): """ return self._client.close() - @distributed_trace def get_search_client(self, index_name, **kwargs): # type: (str, dict) -> SearchClient """Return a client to perform operations on Search