diff --git a/sdk/search/azure-search-documents/CHANGELOG.md b/sdk/search/azure-search-documents/CHANGELOG.md index 23071b1d6a54..abad78cf4b14 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` #11507 + ## 1.0.0b3 (2020-05-04) **Features** 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..309814cf85f2 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,6 @@ 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 ._version import VERSION __version__ = VERSION @@ -202,7 +198,6 @@ "RegexFlags", "ScoringFunction", "ScoringProfile", - "SearchDataSourcesClient", "SearchClient", "SearchField", "SearchIndex", @@ -210,14 +205,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 0f04fe5407f8..000000000000 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_datasources_client.py +++ /dev/null @@ -1,187 +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() - - @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 deleted file mode 100644 index 38d1d81ff7bb..000000000000 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_indexers_client.py +++ /dev/null @@ -1,251 +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() - - @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/_indexes_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py similarity index 58% rename from sdk/search/azure-search-documents/azure/search/documents/_service/_indexes_client.py rename to sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py index bd65a30a3b87..4317559fb208 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_indexes_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_index_client.py @@ -10,42 +10,41 @@ 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, + normalize_endpoint, ) from .._headers_mixin import HeadersMixin from .._version import SDK_MONIKER +from .. import SearchClient if TYPE_CHECKING: # pylint:disable=unused-import,ungrouped-imports - from ._generated.models import AnalyzeRequest, AnalyzeResult, SearchIndex - from typing import Any, Dict, List, Union + from typing import Any, Dict, List, Sequence, Union, Optional 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` +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._endpoint = normalize_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 + # type: () -> SearchIndexClient self._client.__enter__() # pylint:disable=no-member return self @@ -55,11 +54,22 @@ def __exit__(self, *args): def close(self): # type: () -> None - """Close the :class:`~azure.search.documents.SearchIndexesClient` session. + """Close the :class:`~azure.search.documents.SearchIndexClient` session. """ return 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.SearchClient + + """ + return SearchClient(self._endpoint, index_name, self._credential, **kwargs) + @distributed_trace def list_indexes(self, **kwargs): # type: (**Any) -> ItemPaged[SearchIndex] @@ -258,3 +268,163 @@ def analyze_text(self, index_name, analyze_request, **kwargs): 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_indexer_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_indexer_client.py new file mode 100644 index 000000000000..e528a6d6413b --- /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, normalize_endpoint +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 = normalize_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.SearchIndexerClient` 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/_search_service_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_service_client.py deleted file mode 100644 index 19fa5c3bbdec..000000000000 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_service_client.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 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_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 - """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 c02a78bfe99b..000000000000 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_skillsets_client.py +++ /dev/null @@ -1,221 +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 ._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 - - 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() - - @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/_synonym_maps_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_synonym_maps_client.py deleted file mode 100644 index 965f173c666a..000000000000 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_synonym_maps_client.py +++ /dev/null @@ -1,206 +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() - - @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/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 25b6ccf36c40..000000000000 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_datasources_client.py +++ /dev/null @@ -1,183 +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() - - @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 deleted file mode 100644 index cba6743bffcf..000000000000 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_indexers_client.py +++ /dev/null @@ -1,251 +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() - - @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/_search_index_client.py similarity index 59% rename from sdk/search/azure-search-documents/azure/search/documents/_service/aio/_indexes_client.py rename to sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_index_client.py index 19cdd6bc2daf..e44334f9c03c 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/_search_index_client.py @@ -9,10 +9,14 @@ 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 ...aio import SearchClient from .._utils import ( delistize_flags_for_index, listize_flags_for_index, + listize_synonyms, get_access_conditions, + normalize_endpoint, ) from ..._headers_mixin import HeadersMixin from ..._version import SDK_MONIKER @@ -24,7 +28,7 @@ from azure.core.credentials import AzureKeyCredential -class SearchIndexesClient(HeadersMixin): +class SearchIndexClient(HeadersMixin): """A client to interact with Azure search service Indexes. This class is not normally instantiated directly, instead use @@ -37,7 +41,7 @@ class SearchIndexesClient(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 @@ -54,11 +58,21 @@ 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() + 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] @@ -257,3 +271,164 @@ async def analyze_text(self, index_name, analyze_request, **kwargs): 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..4f844c27ba2c --- /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, normalize_endpoint +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 = normalize_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.SearchIndexerClient` 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/_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 a53f74508589..000000000000 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_skillsets_client.py +++ /dev/null @@ -1,222 +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() - - @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 deleted file mode 100644 index a3d6f88dead0..000000000000 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_synonym_maps_client.py +++ /dev/null @@ -1,207 +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() - - @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/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 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_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/async_tests/test_service_live_async.py b/sdk/search/azure-search-documents/tests/async_tests/test_service_live_async.py index 60994ffe248f..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,7 +37,7 @@ SimpleField, edm ) -from azure.search.documents.aio import SearchServiceClient +from azure.search.documents.aio import SearchIndexClient, SearchIndexerClient from _test_utils import build_synonym_map_from_dict CWD = dirname(realpath(__file__)) @@ -64,7 +63,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 +73,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 +82,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 +94,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 +120,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 +176,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 +199,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 +222,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 +261,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 +270,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 +286,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 +298,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 +318,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 +335,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 +350,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 +371,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 +389,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 +404,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 +420,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 +438,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 +452,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 +468,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 +484,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 +515,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 +524,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 +534,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 +543,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 +555,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 +569,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 +588,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 +616,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 +628,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 +645,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 +655,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 +664,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 +676,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 +690,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 +700,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 +711,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 +720,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 +736,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 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..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,22 +11,22 @@ import mock from azure.core.credentials import AzureKeyCredential -from azure.search.documents import SearchServiceClient +from azure.search.documents import SearchClient, 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,68 @@ 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") - ) + 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" ) 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 08638d837af4..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, @@ -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", ])) @@ -371,7 +372,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")]) @@ -389,7 +390,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")]) @@ -402,7 +403,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")]) @@ -418,7 +419,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")]) @@ -436,7 +437,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")]) @@ -450,7 +451,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")]) @@ -466,7 +467,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")]) @@ -482,7 +483,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")]) @@ -512,7 +513,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" @@ -521,7 +522,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 @@ -531,7 +532,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") @@ -540,7 +541,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) @@ -552,7 +553,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 @@ -566,7 +567,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 @@ -584,7 +585,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 @@ -602,7 +603,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 @@ -630,8 +631,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 = [ @@ -642,13 +643,13 @@ 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) @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" @@ -658,7 +659,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 @@ -668,7 +669,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 @@ -678,7 +679,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 @@ -689,7 +690,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") @@ -698,7 +699,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) @@ -710,7 +711,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 @@ -724,7 +725,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") @@ -733,7 +734,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 @@ -749,7 +750,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