-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Implementation for indexers operations #11144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
57e0ddd
169b711
a2a6117
cc1c538
e843164
60fa67c
0426a35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,244 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # 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 ._generated import SearchServiceClient as _SearchServiceClient | ||
| from .._headers_mixin import HeadersMixin | ||
| from .._version import SDK_MONIKER | ||
|
|
||
| if TYPE_CHECKING: | ||
| # pylint:disable=unused-import,ungrouped-imports | ||
| from ._generated.models import Indexer, IndexerExecutionInfo | ||
| 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: (Indexer, **Any) -> Indexer | ||
| """Creates a new Indexers. | ||
|
|
||
| :param indexer: The definition of the indexer to create. | ||
| :type indexer: ~~azure.search.documents.Indexer | ||
| :return: The created Indexer | ||
| :rtype: ~azure.search.documents.Indexer | ||
|
|
||
| .. admonition:: Example: | ||
|
|
||
| .. literalinclude:: ../samples/sample_indexer_operations.py | ||
| :start-after: [START create_indexer] | ||
| :end-before: [END create_indexer] | ||
| :language: python | ||
| :dedent: 4 | ||
| :caption: Create an Indexer | ||
| """ | ||
| 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: (Indexer, Optional[str], **Any) -> Indexer | ||
| """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.Indexer | ||
| :return: The created Indexer | ||
| :rtype: ~azure.search.documents.Indexer | ||
| """ | ||
| # TODO: access_condition | ||
| kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) | ||
|
|
||
| if not name: | ||
| name = indexer.name | ||
| result = self._client.indexers.create_or_update(name, indexer, **kwargs) | ||
| return result | ||
|
|
||
| @distributed_trace | ||
| def get_indexer(self, name, **kwargs): | ||
| # type: (str, **Any) -> Indexer | ||
| """Retrieves a indexer definition. | ||
|
|
||
| :param name: The name of the indexer to retrieve. | ||
| :type name: str | ||
| :return: The Indexer that is fetched. | ||
| :rtype: ~azure.search.documents.Indexer | ||
|
|
||
| .. admonition:: Example: | ||
|
|
||
| .. literalinclude:: ../samples/sample_indexer_operations.py | ||
| :start-after: [START get_indexer] | ||
| :end-before: [END get_indexer] | ||
| :language: python | ||
| :dedent: 4 | ||
| :caption: Retrieve an Indexer | ||
| """ | ||
| 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[Indexer] | ||
| """Lists all indexers available for a search service. | ||
|
|
||
| :return: List of all the Indexers. | ||
| :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 Indexers | ||
| """ | ||
| 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): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we ask user to give entire indexer? Name is good enough. Not correct?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And you have ':param name: The name of the indexer to delete.' :)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indexers is |
||
| # type: (Union[str, Indexer], **Any) -> None | ||
| """Deletes an indexer. To use access conditions, the Indexer 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.Indexer | ||
| :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 an Indexer | ||
| """ | ||
| kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) | ||
| access_condition = None | ||
| try: | ||
| name = indexer.name | ||
| # TODO: update the placeholder | ||
| access_condition = None | ||
| except AttributeError: | ||
| name = indexer | ||
| self._client.indexers.delete(name, access_condition=access_condition, **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 an Indexer | ||
| """ | ||
| 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 an Indexer'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) -> IndexerExecutionInfo | ||
| """Get the status of the indexer. | ||
|
|
||
| :param name: The name of the indexer to fetch the status. | ||
| :type name: str | ||
|
|
||
| :return: IndexerExecutionInfo | ||
| :rtype: IndexerExecutionInfo | ||
|
|
||
| .. 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 an Indexer's status | ||
| """ | ||
| kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) | ||
| return self._client.indexers.get_status(name, **kwargs) | ||
Uh oh!
There was an error while loading. Please reload this page.