From a746d2c071135a5fde58bceac400f4d12841111e Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Mon, 22 Jun 2020 16:37:16 -0700 Subject: [PATCH 1/7] update --- sdk/search/azure-search-documents/README.md | 22 ++- .../azure/search/documents/_api_versions.py | 16 +++ .../documents/_internal/_search_client.py | 131 ++++++++++++++++++ .../_internal/aio/_search_client_async.py | 131 ++++++++++++++++++ .../indexes/_internal/_search_index_client.py | 9 ++ .../_internal/_search_indexer_client.py | 9 ++ .../_internal/aio/_search_index_client.py | 10 +- .../_internal/aio/_search_indexer_client.py | 9 ++ 8 files changed, 334 insertions(+), 3 deletions(-) create mode 100644 sdk/search/azure-search-documents/azure/search/documents/_api_versions.py diff --git a/sdk/search/azure-search-documents/README.md b/sdk/search/azure-search-documents/README.md index 8509a796c546..bfb9a21a7d7b 100644 --- a/sdk/search/azure-search-documents/README.md +++ b/sdk/search/azure-search-documents/README.md @@ -133,7 +133,7 @@ client = SearchClient(endpoint=endpoint, credential=credential) # Let's get the top 5 jobs related to Microsoft -results = client.search(search_text="Microsoft", include_total_result_count=5) +results = client.search(search_text="Microsoft", top=5) for result in results: # Print out the title and job description @@ -325,6 +325,26 @@ print("Upload of new document succeeded: {}".format(result[0].succeeded)) ``` +### Async APIs +This library includes a complete async API supported on Python 3.5+. To use it, you must +first install an async transport, such as [aiohttp](https://pypi.org/project/aiohttp/). +See +[azure-core documentation](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/core/azure-core/README.md#transport) +for more information. + + +```py +from azure.search.documents.aio import SearchClient + +client = SearchClient( + endpoint, index_name, AzureKeyCredential(api_key) + ) + +async with client: + results = await client.search(search_text="hotel") +... + + ## Troubleshooting ### General diff --git a/sdk/search/azure-search-documents/azure/search/documents/_api_versions.py b/sdk/search/azure-search-documents/azure/search/documents/_api_versions.py new file mode 100644 index 000000000000..b9f90073729d --- /dev/null +++ b/sdk/search/azure-search-documents/azure/search/documents/_api_versions.py @@ -0,0 +1,16 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ + +_SUPPORTED_API_VERSIONS = [ + "2019-05-06-Preview", +] + +def get_api_version(kwargs, default): + # type: (Dict[str, Any]) -> str + api_version = kwargs.pop('api_version', None) + if api_version and api_version not in _SUPPORTED_API_VERSIONS: + versions = '\n'.join(_SUPPORTED_API_VERSIONS) + raise ValueError("Unsupported API version '{}'. Please select from:\n{}".format(api_version, versions)) + return api_version or default diff --git a/sdk/search/azure-search-documents/azure/search/documents/_internal/_search_client.py b/sdk/search/azure-search-documents/azure/search/documents/_internal/_search_client.py index 45694e8b6d00..dff4d2a01152 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_internal/_search_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_internal/_search_client.py @@ -8,6 +8,7 @@ import six from azure.core.tracing.decorator import distributed_trace +from .._api_versions import get_api_version from ._generated import SearchIndexClient from ._generated.models import IndexBatch, IndexingResult from ._index_documents_batch import IndexDocumentsBatch @@ -59,6 +60,8 @@ class SearchClient(HeadersMixin): :type index_name: str :param credential: A credential to authorize search client requests :type credential: ~azure.core.credentials.AzureKeyCredential + :keyword str api_version: + The Search API version to use for requests. Default value is "2019-05-06-Preview". .. admonition:: Example: @@ -75,6 +78,7 @@ class SearchClient(HeadersMixin): def __init__(self, endpoint, index_name, credential, **kwargs): # type: (str, str, AzureKeyCredential, **Any) -> None + get_api_version(kwargs, "2019-05-06-Preview") self._endpoint = endpoint # type: str self._index_name = index_name # type: str self._credential = credential # type: AzureKeyCredential @@ -138,6 +142,68 @@ def search(self, search_text, **kwargs): :param str search_text: A full-text search query expression; Use "*" or omit this parameter to match all documents. + :keyword include_total_result_count: A value that specifies whether to fetch the total count of + results. Default is false. Setting this value to true may have a performance impact. Note that + the count returned is an approximation. + :type include_total_result_count: bool + :keyword facets: The list of facet expressions to apply to the search query. Each facet + expression contains a field name, optionally followed by a comma-separated list of name:value + pairs. + :type facets: list[str] + :keyword filter: The OData $filter expression to apply to the search query. + :type filter: str + :keyword highlight_fields: The list of field names to use for hit highlights. Only searchable + fields can be used for hit highlighting. + :type highlight_fields: list[str] + :keyword highlight_post_tag: A string tag that is appended to hit highlights. Must be set with + highlightPreTag. Default is </em>. + :type highlight_post_tag: str + :keyword highlight_pre_tag: A string tag that is prepended to hit highlights. Must be set with + highlightPostTag. Default is <em>. + :type highlight_pre_tag: str + :keyword minimum_coverage: A number between 0 and 100 indicating the percentage of the index that + must be covered by a search query in order for the query to be reported as a success. This + parameter can be useful for ensuring search availability even for services with only one + replica. The default is 100. + :type minimum_coverage: float + :keyword order_by: The list of OData $orderby expressions by which to sort the results. Each + expression can be either a field name or a call to either the geo.distance() or the + search.score() functions. Each expression can be followed by asc to indicate ascending, and + desc to indicate descending. The default is ascending order. Ties will be broken by the match + scores of documents. If no OrderBy is specified, the default sort order is descending by + document match score. There can be at most 32 $orderby clauses. + :type order_by: list[str] + :keyword query_type: A value that specifies the syntax of the search query. The default is + 'simple'. Use 'full' if your query uses the Lucene query syntax. Possible values include: + 'simple', 'full'. + :type query_type: str or ~search_index_client.models.QueryType + :keyword scoring_parameters: The list of parameter values to be used in scoring functions (for + example, referencePointParameter) using the format name-values. For example, if the scoring + profile defines a function with a parameter called 'mylocation' the parameter string would be + "mylocation--122.2,44.8" (without the quotes). + :type scoring_parameters: list[str] + :keyword scoring_profile: The name of a scoring profile to evaluate match scores for matching + documents in order to sort the results. + :type scoring_profile: str + :keyword search_fields: The list of field names to which to scope the full-text search. When + using fielded search (fieldName:searchExpression) in a full Lucene query, the field names of + each fielded search expression take precedence over any field names listed in this parameter. + :type search_fields: list[str] + :keyword search_mode: A value that specifies whether any or all of the search terms must be + matched in order to count the document as a match. Possible values include: 'any', 'all'. + :type search_mode: str or ~search_index_client.models.SearchMode + :keyword select: The list of fields to retrieve. If unspecified, all fields marked as retrievable + in the schema are included. + :type select: list[str] + :keyword skip: The number of search results to skip. This value cannot be greater than 100,000. + If you need to scan documents in sequence, but cannot use $skip due to this limitation, + consider using $orderby on a totally-ordered key and $filter with a range query instead. + :type skip: int + :keyword top: The number of search results to retrieve. This can be used in conjunction with + $skip to implement client-side paging of search results. If results are truncated due to + server-side paging, the response will include a continuation token that can be used to issue + another Search request for the next page of results. + :type top: int :rtype: SearchItemPaged[dict] .. admonition:: Example: @@ -217,6 +283,41 @@ def suggest(self, search_text, suggester_name, **kwargs): character, and no more than 100 characters. :param str suggester_name: Required. The name of the suggester as specified in the suggesters collection that's part of the index definition. + :keyword filter: An OData expression that filters the documents considered for suggestions. + :type filter: str + :keyword use_fuzzy_matching: A value indicating whether to use fuzzy matching for the suggestions + query. Default is false. When set to true, the query will find terms even if there's a + substituted or missing character in the search text. While this provides a better experience in + some scenarios, it comes at a performance cost as fuzzy suggestions queries are slower and + consume more resources. + :type use_fuzzy_matching: bool + :keyword highlight_post_tag: A string tag that is appended to hit highlights. Must be set with + highlightPreTag. If omitted, hit highlighting of suggestions is disabled. + :type highlight_post_tag: str + :keyword highlight_pre_tag: A string tag that is prepended to hit highlights. Must be set with + highlightPostTag. If omitted, hit highlighting of suggestions is disabled. + :type highlight_pre_tag: str + :keyword minimum_coverage: A number between 0 and 100 indicating the percentage of the index that + must be covered by a suggestions query in order for the query to be reported as a success. This + parameter can be useful for ensuring search availability even for services with only one + replica. The default is 80. + :type minimum_coverage: float + :keyword order_by: The list of OData $orderby expressions by which to sort the results. Each + expression can be either a field name or a call to either the geo.distance() or the + search.score() functions. Each expression can be followed by asc to indicate ascending, or desc + to indicate descending. The default is ascending order. Ties will be broken by the match scores + of documents. If no $orderby is specified, the default sort order is descending by document + match score. There can be at most 32 $orderby clauses. + :type order_by: list[str] + :keyword search_fields: The list of field names to search for the specified search text. Target + fields must be included in the specified suggester. + :type search_fields: list[str] + :keyword select: The list of fields to retrieve. If unspecified, only the key field will be + included in the results. + :type select: list[str] + :keyword top: The number of suggestions to retrieve. The value must be a number between 1 and + 100. The default is 5. + :type top: int :rtype: List[dict] .. admonition:: Example: @@ -266,6 +367,36 @@ def autocomplete(self, search_text, suggester_name, **kwargs): :param str search_text: The search text on which to base autocomplete results. :param str suggester_name: The name of the suggester as specified in the suggesters collection that's part of the index definition. + :keyword autocomplete_mode: Specifies the mode for Autocomplete. The default is 'oneTerm'. Use + 'twoTerms' to get shingles and 'oneTermWithContext' to use the current context while producing + auto-completed terms. Possible values include: 'oneTerm', 'twoTerms', 'oneTermWithContext'. + :type autocomplete_mode: str or ~search_index_client.models.AutocompleteMode + :keyword filter: An OData expression that filters the documents used to produce completed terms + for the Autocomplete result. + :type filter: str + :keyword use_fuzzy_matching: A value indicating whether to use fuzzy matching for the + autocomplete query. Default is false. When set to true, the query will find terms even if + there's a substituted or missing character in the search text. While this provides a better + experience in some scenarios, it comes at a performance cost as fuzzy autocomplete queries are + slower and consume more resources. + :type use_fuzzy_matching: bool + :keyword highlight_post_tag: A string tag that is appended to hit highlights. Must be set with + highlightPreTag. If omitted, hit highlighting is disabled. + :type highlight_post_tag: str + :keyword highlight_pre_tag: A string tag that is prepended to hit highlights. Must be set with + highlightPostTag. If omitted, hit highlighting is disabled. + :type highlight_pre_tag: str + :keyword minimum_coverage: A number between 0 and 100 indicating the percentage of the index that + must be covered by an autocomplete query in order for the query to be reported as a success. + This parameter can be useful for ensuring search availability even for services with only one + replica. The default is 80. + :type minimum_coverage: float + :keyword search_fields: The list of field names to consider when querying for auto-completed + terms. Target fields must be included in the specified suggester. + :type search_fields: list[str] + :keyword top: The number of auto-completed terms to retrieve. This must be a value between 1 and + 100. The default is 5. + :type top: int :rtype: List[dict] .. admonition:: Example: diff --git a/sdk/search/azure-search-documents/azure/search/documents/_internal/aio/_search_client_async.py b/sdk/search/azure-search-documents/azure/search/documents/_internal/aio/_search_client_async.py index 7a2ed34e2402..b4355dcd234b 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_internal/aio/_search_client_async.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_internal/aio/_search_client_async.py @@ -11,6 +11,7 @@ from .._generated.models import IndexBatch, IndexingResult from .._index_documents_batch import IndexDocumentsBatch from .._queries import AutocompleteQuery, SearchQuery, SuggestQuery +from ..._api_versions import get_api_version from ..._headers_mixin import HeadersMixin from ..._version import SDK_MONIKER @@ -29,6 +30,8 @@ class SearchClient(HeadersMixin): :type index_name: str :param credential: A credential to authorize search client requests :type credential: ~azure.core.credentials.AzureKeyCredential + :keyword str api_version: + The Search API version to use for requests. Default value is "2019-05-06-Preview". .. admonition:: Example: @@ -45,6 +48,7 @@ class SearchClient(HeadersMixin): def __init__(self, endpoint, index_name, credential, **kwargs): # type: (str, str, AzureKeyCredential, **Any) -> None + get_api_version(kwargs, "2019-05-06-Preview") self._endpoint = endpoint # type: str self._index_name = index_name # type: str self._credential = credential # type: AzureKeyCredential @@ -108,6 +112,68 @@ async def search(self, search_text, **kwargs): :param str search_text: A full-text search query expression; Use "*" or omit this parameter to match all documents. + :keyword include_total_result_count: A value that specifies whether to fetch the total count of + results. Default is false. Setting this value to true may have a performance impact. Note that + the count returned is an approximation. + :type include_total_result_count: bool + :keyword facets: The list of facet expressions to apply to the search query. Each facet + expression contains a field name, optionally followed by a comma-separated list of name:value + pairs. + :type facets: list[str] + :keyword filter: The OData $filter expression to apply to the search query. + :type filter: str + :keyword highlight_fields: The list of field names to use for hit highlights. Only searchable + fields can be used for hit highlighting. + :type highlight_fields: list[str] + :keyword highlight_post_tag: A string tag that is appended to hit highlights. Must be set with + highlightPreTag. Default is </em>. + :type highlight_post_tag: str + :keyword highlight_pre_tag: A string tag that is prepended to hit highlights. Must be set with + highlightPostTag. Default is <em>. + :type highlight_pre_tag: str + :keyword minimum_coverage: A number between 0 and 100 indicating the percentage of the index that + must be covered by a search query in order for the query to be reported as a success. This + parameter can be useful for ensuring search availability even for services with only one + replica. The default is 100. + :type minimum_coverage: float + :keyword order_by: The list of OData $orderby expressions by which to sort the results. Each + expression can be either a field name or a call to either the geo.distance() or the + search.score() functions. Each expression can be followed by asc to indicate ascending, and + desc to indicate descending. The default is ascending order. Ties will be broken by the match + scores of documents. If no OrderBy is specified, the default sort order is descending by + document match score. There can be at most 32 $orderby clauses. + :type order_by: list[str] + :keyword query_type: A value that specifies the syntax of the search query. The default is + 'simple'. Use 'full' if your query uses the Lucene query syntax. Possible values include: + 'simple', 'full'. + :type query_type: str or ~search_index_client.models.QueryType + :keyword scoring_parameters: The list of parameter values to be used in scoring functions (for + example, referencePointParameter) using the format name-values. For example, if the scoring + profile defines a function with a parameter called 'mylocation' the parameter string would be + "mylocation--122.2,44.8" (without the quotes). + :type scoring_parameters: list[str] + :keyword scoring_profile: The name of a scoring profile to evaluate match scores for matching + documents in order to sort the results. + :type scoring_profile: str + :keyword search_fields: The list of field names to which to scope the full-text search. When + using fielded search (fieldName:searchExpression) in a full Lucene query, the field names of + each fielded search expression take precedence over any field names listed in this parameter. + :type search_fields: list[str] + :keyword search_mode: A value that specifies whether any or all of the search terms must be + matched in order to count the document as a match. Possible values include: 'any', 'all'. + :type search_mode: str or ~search_index_client.models.SearchMode + :keyword select: The list of fields to retrieve. If unspecified, all fields marked as retrievable + in the schema are included. + :type select: list[str] + :keyword skip: The number of search results to skip. This value cannot be greater than 100,000. + If you need to scan documents in sequence, but cannot use $skip due to this limitation, + consider using $orderby on a totally-ordered key and $filter with a range query instead. + :type skip: int + :keyword top: The number of search results to retrieve. This can be used in conjunction with + $skip to implement client-side paging of search results. If results are truncated due to + server-side paging, the response will include a continuation token that can be used to issue + another Search request for the next page of results. + :type top: int :rtype: AsyncSearchItemPaged[dict] .. admonition:: Example: @@ -187,6 +253,41 @@ async def suggest(self, search_text, suggester_name, **kwargs): character, and no more than 100 characters. :param str suggester_name: Required. The name of the suggester as specified in the suggesters collection that's part of the index definition. + :keyword filter: An OData expression that filters the documents considered for suggestions. + :type filter: str + :keyword use_fuzzy_matching: A value indicating whether to use fuzzy matching for the suggestions + query. Default is false. When set to true, the query will find terms even if there's a + substituted or missing character in the search text. While this provides a better experience in + some scenarios, it comes at a performance cost as fuzzy suggestions queries are slower and + consume more resources. + :type use_fuzzy_matching: bool + :keyword highlight_post_tag: A string tag that is appended to hit highlights. Must be set with + highlightPreTag. If omitted, hit highlighting of suggestions is disabled. + :type highlight_post_tag: str + :keyword highlight_pre_tag: A string tag that is prepended to hit highlights. Must be set with + highlightPostTag. If omitted, hit highlighting of suggestions is disabled. + :type highlight_pre_tag: str + :keyword minimum_coverage: A number between 0 and 100 indicating the percentage of the index that + must be covered by a suggestions query in order for the query to be reported as a success. This + parameter can be useful for ensuring search availability even for services with only one + replica. The default is 80. + :type minimum_coverage: float + :keyword order_by: The list of OData $orderby expressions by which to sort the results. Each + expression can be either a field name or a call to either the geo.distance() or the + search.score() functions. Each expression can be followed by asc to indicate ascending, or desc + to indicate descending. The default is ascending order. Ties will be broken by the match scores + of documents. If no $orderby is specified, the default sort order is descending by document + match score. There can be at most 32 $orderby clauses. + :type order_by: list[str] + :keyword search_fields: The list of field names to search for the specified search text. Target + fields must be included in the specified suggester. + :type search_fields: list[str] + :keyword select: The list of fields to retrieve. If unspecified, only the key field will be + included in the results. + :type select: list[str] + :keyword top: The number of suggestions to retrieve. The value must be a number between 1 and + 100. The default is 5. + :type top: int :rtype: List[dict] .. admonition:: Example: @@ -236,6 +337,36 @@ async def autocomplete(self, search_text, suggester_name, **kwargs): :param str search_text: The search text on which to base autocomplete results. :param str suggester_name: The name of the suggester as specified in the suggesters collection that's part of the index definition. + :keyword autocomplete_mode: Specifies the mode for Autocomplete. The default is 'oneTerm'. Use + 'twoTerms' to get shingles and 'oneTermWithContext' to use the current context while producing + auto-completed terms. Possible values include: 'oneTerm', 'twoTerms', 'oneTermWithContext'. + :type autocomplete_mode: str or ~search_index_client.models.AutocompleteMode + :keyword filter: An OData expression that filters the documents used to produce completed terms + for the Autocomplete result. + :type filter: str + :keyword use_fuzzy_matching: A value indicating whether to use fuzzy matching for the + autocomplete query. Default is false. When set to true, the query will find terms even if + there's a substituted or missing character in the search text. While this provides a better + experience in some scenarios, it comes at a performance cost as fuzzy autocomplete queries are + slower and consume more resources. + :type use_fuzzy_matching: bool + :keyword highlight_post_tag: A string tag that is appended to hit highlights. Must be set with + highlightPreTag. If omitted, hit highlighting is disabled. + :type highlight_post_tag: str + :keyword highlight_pre_tag: A string tag that is prepended to hit highlights. Must be set with + highlightPostTag. If omitted, hit highlighting is disabled. + :type highlight_pre_tag: str + :keyword minimum_coverage: A number between 0 and 100 indicating the percentage of the index that + must be covered by an autocomplete query in order for the query to be reported as a success. + This parameter can be useful for ensuring search availability even for services with only one + replica. The default is 80. + :type minimum_coverage: float + :keyword search_fields: The list of field names to consider when querying for auto-completed + terms. Target fields must be included in the specified suggester. + :type search_fields: list[str] + :keyword top: The number of auto-completed terms to retrieve. This must be a value between 1 and + 100. The default is 5. + :type top: int :rtype: List[dict] .. admonition:: Example: diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_index_client.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_index_client.py index bb6c2cc46c27..54cd85570a8e 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_index_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_index_client.py @@ -9,6 +9,7 @@ from azure.core.tracing.decorator import distributed_trace from azure.core.paging import ItemPaged +from ..._api_versions import get_api_version from ._generated import SearchServiceClient as _SearchServiceClient from ._utils import ( unpack_search_index, @@ -32,12 +33,20 @@ class SearchIndexClient(HeadersMixin): """A client to interact with Azure search service index. + :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 + :keyword str api_version: + The Search API version to use for requests. Default value is "2019-05-06-Preview". + """ _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str def __init__(self, endpoint, credential, **kwargs): # type: (str, AzureKeyCredential, **Any) -> None + get_api_version(kwargs, "2019-05-06-Preview") self._endpoint = normalize_endpoint(endpoint) # type: str self._credential = credential # type: AzureKeyCredential self._client = _SearchServiceClient( diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_indexer_client.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_indexer_client.py index 41c73f023fa7..c29256bc368c 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_indexer_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_indexer_client.py @@ -16,6 +16,7 @@ pack_search_indexer_data_source, unpack_search_indexer_data_source, ) +from ..._api_versions import get_api_version from ..._headers_mixin import HeadersMixin from ..._version import SDK_MONIKER @@ -29,6 +30,13 @@ class SearchIndexerClient(HeadersMixin): # pylint: disable=R0904 """A client to interact with Azure search service Indexers. + :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 + :keyword str api_version: + The Search API version to use for requests. Default value is "2019-05-06-Preview". + """ _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str @@ -36,6 +44,7 @@ class SearchIndexerClient(HeadersMixin): # pylint: disable=R0904 def __init__(self, endpoint, credential, **kwargs): # type: (str, AzureKeyCredential, **Any) -> None + get_api_version(kwargs, "2019-05-06-Preview") self._endpoint = normalize_endpoint(endpoint) # type: str self._credential = credential # type: AzureKeyCredential self._client = _SearchServiceClient( diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_index_client.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_index_client.py index 49bcaace91e6..541ae2ba673d 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_index_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_index_client.py @@ -19,6 +19,7 @@ get_access_conditions, normalize_endpoint, ) +from ...._api_versions import get_api_version from ...._headers_mixin import HeadersMixin from ...._version import SDK_MONIKER @@ -33,8 +34,12 @@ class SearchIndexClient(HeadersMixin): """A client to interact with Azure search service Indexes. - This class is not normally instantiated directly, instead use - `get_skillsets_client()` from a `SearchServiceClient` + :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 + :keyword str api_version: + The Search API version to use for requests. Default value is "2019-05-06-Preview". """ @@ -43,6 +48,7 @@ class SearchIndexClient(HeadersMixin): def __init__(self, endpoint, credential, **kwargs): # type: (str, AzureKeyCredential, **Any) -> None + get_api_version(kwargs, "2019-05-06-Preview") self._endpoint = normalize_endpoint(endpoint) # type: str self._credential = credential # type: AzureKeyCredential self._client = _SearchServiceClient( diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_indexer_client.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_indexer_client.py index d4194179bcec..c12e5a24561f 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_indexer_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_indexer_client.py @@ -16,6 +16,7 @@ pack_search_indexer_data_source, unpack_search_indexer_data_source, ) +from ...._api_versions import get_api_version from ...._headers_mixin import HeadersMixin from ...._version import SDK_MONIKER @@ -29,6 +30,13 @@ class SearchIndexerClient(HeadersMixin): # pylint: disable=R0904 """A client to interact with Azure search service Indexers. + :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 + :keyword str api_version: + The Search API version to use for requests. Default value is "2019-05-06-Preview". + """ _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str @@ -36,6 +44,7 @@ class SearchIndexerClient(HeadersMixin): # pylint: disable=R0904 def __init__(self, endpoint, credential, **kwargs): # type: (str, AzureKeyCredential, **Any) -> None + get_api_version(kwargs, "2019-05-06-Preview") self._endpoint = normalize_endpoint(endpoint) # type: str self._credential = credential # type: AzureKeyCredential self._client = _SearchServiceClient( From d3b9a21c627893aeb2195b5cfe191d670a4d8cae Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Tue, 23 Jun 2020 16:25:12 -0700 Subject: [PATCH 2/7] update version --- .../azure-search-documents/CHANGELOG.md | 47 ++++++++++++++----- .../azure/search/documents/_version.py | 2 +- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/sdk/search/azure-search-documents/CHANGELOG.md b/sdk/search/azure-search-documents/CHANGELOG.md index c98afa0f7947..56907c494f72 100644 --- a/sdk/search/azure-search-documents/CHANGELOG.md +++ b/sdk/search/azure-search-documents/CHANGELOG.md @@ -1,5 +1,28 @@ # Release History +## 11.0.0 (2020-07-07) + +- Exposed more models: + + * BM25SimilarityAlgorithm + * ClassicSimilarityAlgorithm + * EdgeNGramTokenFilterSide + * EntityCategory + * EntityRecognitionSkillLanguage + * FieldMapping + * FieldMappingFunction + * ImageAnalysisSkillLanguage + * ImageDetail + * IndexerExecutionStatus + * IndexerStatus + * KeyPhraseExtractionSkillLanguage + * MicrosoftStemmingTokenizerLanguage + * MicrosoftTokenizerLanguage + * OcrSkillLanguage + * PhoneticEncoder + * ScoringFunctionAggregation + * ScoringFunctionInterpolation + ## 1.0.0b4 (2020-06-09) **Breaking Changes** @@ -10,18 +33,18 @@ - Now Search Synonym Map creation/update returns a model #11514 - Renaming #11565 - SearchIndexerDataSource -> SearchIndexerDataSourceConnection - SearchField.SynonymMaps -> SearchField.SynonymMapNames - SearchField.Analyzer -> SearchField.AnalyzerName - SearchField.IndexAnalyzer -> SearchField.IndexAnalyzerName - SearchField.SearchAnalyzer -> SearchField.SearchAnalyzerName - SearchableField.SynonymMaps -> SearchableField.SynonymMapNames - SearchableField.Analyzer -> SearchableField.AnalyzerName - SearchableField.IndexAnalyzer -> SearchableField.IndexAnalyzerName - SearchableField.SearchAnalyzer -> SearchableField.SearchAnalyzerName - Similarity -> SimilarityAlgorithm - Suggester -> SearchSuggester - PathHierarchyTokenizerV2 -> PathHierarchyTokenizer + * SearchIndexerDataSource -> SearchIndexerDataSourceConnection + * SearchField.SynonymMaps -> SearchField.SynonymMapNames + * SearchField.Analyzer -> SearchField.AnalyzerName + * SearchField.IndexAnalyzer -> SearchField.IndexAnalyzerName + * SearchField.SearchAnalyzer -> SearchField.SearchAnalyzerName + * SearchableField.SynonymMaps -> SearchableField.SynonymMapNames + * SearchableField.Analyzer -> SearchableField.AnalyzerName + * SearchableField.IndexAnalyzer -> SearchableField.IndexAnalyzerName + * SearchableField.SearchAnalyzer -> SearchableField.SearchAnalyzerName + * Similarity -> SimilarityAlgorithm + * Suggester -> SearchSuggester + * PathHierarchyTokenizerV2 -> PathHierarchyTokenizer - Renamed DataSource methods to DataSourceConnection #11693 - Autocomplete & suggest methods now takes arguments search_text & suggester_name rather than query objects #11747 - Create_or_updates methods does not support partial updates #11800 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 10e578c87b24..65eea3955bdf 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.0b4" # type: str +VERSION = "11.0.0" # type: str SDK_MONIKER = "search-documents/{}".format(VERSION) # type: str From 61b036cf9ecd7b6d0d58315839ea95e03f4835f8 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Thu, 25 Jun 2020 11:56:24 -0700 Subject: [PATCH 3/7] update --- .../azure-search-documents/CHANGELOG.md | 2 + sdk/search/azure-search-documents/README.md | 7 +- .../azure/search/documents/_api_versions.py | 12 ++- .../documents/_internal/_search_client.py | 102 +++++++----------- .../_internal/aio/_search_client_async.py | 102 +++++++----------- .../indexes/_internal/_search_index_client.py | 6 +- .../_internal/_search_indexer_client.py | 6 +- .../_internal/aio/_search_index_client.py | 6 +- .../_internal/aio/_search_indexer_client.py | 6 +- 9 files changed, 105 insertions(+), 144 deletions(-) diff --git a/sdk/search/azure-search-documents/CHANGELOG.md b/sdk/search/azure-search-documents/CHANGELOG.md index 56907c494f72..86987b517c03 100644 --- a/sdk/search/azure-search-documents/CHANGELOG.md +++ b/sdk/search/azure-search-documents/CHANGELOG.md @@ -2,6 +2,8 @@ ## 11.0.0 (2020-07-07) +**Features** + - Exposed more models: * BM25SimilarityAlgorithm diff --git a/sdk/search/azure-search-documents/README.md b/sdk/search/azure-search-documents/README.md index bfb9a21a7d7b..e96c01e5f2b6 100644 --- a/sdk/search/azure-search-documents/README.md +++ b/sdk/search/azure-search-documents/README.md @@ -334,14 +334,15 @@ for more information. ```py +from azure.core.credentials import AzureKeyCredential from azure.search.documents.aio import SearchClient -client = SearchClient( - endpoint, index_name, AzureKeyCredential(api_key) - ) +client = SearchClient(endpoint, index_name, AzureKeyCredential(api_key)) async with client: results = await client.search(search_text="hotel") + async for result in results: + print("{}: {})".format(result["hotelId"], result["hotelName"])) ... diff --git a/sdk/search/azure-search-documents/azure/search/documents/_api_versions.py b/sdk/search/azure-search-documents/azure/search/documents/_api_versions.py index b9f90073729d..b7ada7b3fd47 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_api_versions.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_api_versions.py @@ -7,10 +7,16 @@ "2019-05-06-Preview", ] +def check_api_version(api_version): + # type: (str) -> None + if api_version not in _SUPPORTED_API_VERSIONS: + versions = '\n'.join(_SUPPORTED_API_VERSIONS) + raise ValueError("Unsupported API version '{}'. Please select from:\n{}".format(api_version, versions)) + + def get_api_version(kwargs, default): # type: (Dict[str, Any]) -> str api_version = kwargs.pop('api_version', None) - if api_version and api_version not in _SUPPORTED_API_VERSIONS: - versions = '\n'.join(_SUPPORTED_API_VERSIONS) - raise ValueError("Unsupported API version '{}'. Please select from:\n{}".format(api_version, versions)) + if api_version: + check_api_version(api_version) return api_version or default diff --git a/sdk/search/azure-search-documents/azure/search/documents/_internal/_search_client.py b/sdk/search/azure-search-documents/azure/search/documents/_internal/_search_client.py index dff4d2a01152..957d7a3b4631 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_internal/_search_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_internal/_search_client.py @@ -8,7 +8,7 @@ import six from azure.core.tracing.decorator import distributed_trace -from .._api_versions import get_api_version +from .._api_versions import check_api_version from ._generated import SearchIndexClient from ._generated.models import IndexBatch, IndexingResult from ._index_documents_batch import IndexDocumentsBatch @@ -78,7 +78,9 @@ class SearchClient(HeadersMixin): def __init__(self, endpoint, index_name, credential, **kwargs): # type: (str, str, AzureKeyCredential, **Any) -> None - get_api_version(kwargs, "2019-05-06-Preview") + api_version = kwargs.pop('api_version', None) + if api_version: + check_api_version(api_version) self._endpoint = endpoint # type: str self._index_name = index_name # type: str self._credential = credential # type: AzureKeyCredential @@ -142,68 +144,54 @@ def search(self, search_text, **kwargs): :param str search_text: A full-text search query expression; Use "*" or omit this parameter to match all documents. - :keyword include_total_result_count: A value that specifies whether to fetch the total count of + :keyword bool include_total_result_count: A value that specifies whether to fetch the total count of results. Default is false. Setting this value to true may have a performance impact. Note that the count returned is an approximation. - :type include_total_result_count: bool - :keyword facets: The list of facet expressions to apply to the search query. Each facet + :keyword list[str] facets: The list of facet expressions to apply to the search query. Each facet expression contains a field name, optionally followed by a comma-separated list of name:value pairs. - :type facets: list[str] - :keyword filter: The OData $filter expression to apply to the search query. - :type filter: str - :keyword highlight_fields: The list of field names to use for hit highlights. Only searchable + :keyword str filter: The OData $filter expression to apply to the search query. + :keyword list[str] highlight_fields: The list of field names to use for hit highlights. Only searchable fields can be used for hit highlighting. - :type highlight_fields: list[str] - :keyword highlight_post_tag: A string tag that is appended to hit highlights. Must be set with + :keyword str highlight_post_tag: A string tag that is appended to hit highlights. Must be set with highlightPreTag. Default is </em>. - :type highlight_post_tag: str - :keyword highlight_pre_tag: A string tag that is prepended to hit highlights. Must be set with + :keyword str highlight_pre_tag: A string tag that is prepended to hit highlights. Must be set with highlightPostTag. Default is <em>. - :type highlight_pre_tag: str - :keyword minimum_coverage: A number between 0 and 100 indicating the percentage of the index that + :keyword float minimum_coverage: A number between 0 and 100 indicating the percentage of the index that must be covered by a search query in order for the query to be reported as a success. This parameter can be useful for ensuring search availability even for services with only one replica. The default is 100. - :type minimum_coverage: float - :keyword order_by: The list of OData $orderby expressions by which to sort the results. Each + :keyword list[str] order_by: The list of OData $orderby expressions by which to sort the results. Each expression can be either a field name or a call to either the geo.distance() or the search.score() functions. Each expression can be followed by asc to indicate ascending, and desc to indicate descending. The default is ascending order. Ties will be broken by the match scores of documents. If no OrderBy is specified, the default sort order is descending by document match score. There can be at most 32 $orderby clauses. - :type order_by: list[str] :keyword query_type: A value that specifies the syntax of the search query. The default is 'simple'. Use 'full' if your query uses the Lucene query syntax. Possible values include: 'simple', 'full'. - :type query_type: str or ~search_index_client.models.QueryType - :keyword scoring_parameters: The list of parameter values to be used in scoring functions (for + :paramtype query_type: str or ~search_index_client.models.QueryType + :keyword list[str] scoring_parameters: The list of parameter values to be used in scoring functions (for example, referencePointParameter) using the format name-values. For example, if the scoring profile defines a function with a parameter called 'mylocation' the parameter string would be "mylocation--122.2,44.8" (without the quotes). - :type scoring_parameters: list[str] - :keyword scoring_profile: The name of a scoring profile to evaluate match scores for matching + :keyword str scoring_profile: The name of a scoring profile to evaluate match scores for matching documents in order to sort the results. - :type scoring_profile: str - :keyword search_fields: The list of field names to which to scope the full-text search. When + :keyword list[str] search_fields: The list of field names to which to scope the full-text search. When using fielded search (fieldName:searchExpression) in a full Lucene query, the field names of each fielded search expression take precedence over any field names listed in this parameter. - :type search_fields: list[str] :keyword search_mode: A value that specifies whether any or all of the search terms must be matched in order to count the document as a match. Possible values include: 'any', 'all'. - :type search_mode: str or ~search_index_client.models.SearchMode - :keyword select: The list of fields to retrieve. If unspecified, all fields marked as retrievable + :paramtype search_mode: str or ~search_index_client.models.SearchMode + :keyword list[str] select: The list of fields to retrieve. If unspecified, all fields marked as retrievable in the schema are included. - :type select: list[str] - :keyword skip: The number of search results to skip. This value cannot be greater than 100,000. + :keyword int skip: The number of search results to skip. This value cannot be greater than 100,000. If you need to scan documents in sequence, but cannot use $skip due to this limitation, consider using $orderby on a totally-ordered key and $filter with a range query instead. - :type skip: int - :keyword top: The number of search results to retrieve. This can be used in conjunction with + :keyword int top: The number of search results to retrieve. This can be used in conjunction with $skip to implement client-side paging of search results. If results are truncated due to server-side paging, the response will include a continuation token that can be used to issue another Search request for the next page of results. - :type top: int :rtype: SearchItemPaged[dict] .. admonition:: Example: @@ -283,41 +271,32 @@ def suggest(self, search_text, suggester_name, **kwargs): character, and no more than 100 characters. :param str suggester_name: Required. The name of the suggester as specified in the suggesters collection that's part of the index definition. - :keyword filter: An OData expression that filters the documents considered for suggestions. - :type filter: str - :keyword use_fuzzy_matching: A value indicating whether to use fuzzy matching for the suggestions + :keyword str filter: An OData expression that filters the documents considered for suggestions. + :keyword bool use_fuzzy_matching: A value indicating whether to use fuzzy matching for the suggestions query. Default is false. When set to true, the query will find terms even if there's a substituted or missing character in the search text. While this provides a better experience in some scenarios, it comes at a performance cost as fuzzy suggestions queries are slower and consume more resources. - :type use_fuzzy_matching: bool - :keyword highlight_post_tag: A string tag that is appended to hit highlights. Must be set with + :keyword str highlight_post_tag: A string tag that is appended to hit highlights. Must be set with highlightPreTag. If omitted, hit highlighting of suggestions is disabled. - :type highlight_post_tag: str - :keyword highlight_pre_tag: A string tag that is prepended to hit highlights. Must be set with + :keyword str highlight_pre_tag: A string tag that is prepended to hit highlights. Must be set with highlightPostTag. If omitted, hit highlighting of suggestions is disabled. - :type highlight_pre_tag: str - :keyword minimum_coverage: A number between 0 and 100 indicating the percentage of the index that + :keyword float minimum_coverage: A number between 0 and 100 indicating the percentage of the index that must be covered by a suggestions query in order for the query to be reported as a success. This parameter can be useful for ensuring search availability even for services with only one replica. The default is 80. - :type minimum_coverage: float - :keyword order_by: The list of OData $orderby expressions by which to sort the results. Each + :keyword list[str] order_by: The list of OData $orderby expressions by which to sort the results. Each expression can be either a field name or a call to either the geo.distance() or the search.score() functions. Each expression can be followed by asc to indicate ascending, or desc to indicate descending. The default is ascending order. Ties will be broken by the match scores of documents. If no $orderby is specified, the default sort order is descending by document match score. There can be at most 32 $orderby clauses. - :type order_by: list[str] - :keyword search_fields: The list of field names to search for the specified search text. Target + :keyword list[str] search_fields: The list of field names to search for the specified search text. Target fields must be included in the specified suggester. - :type search_fields: list[str] - :keyword select: The list of fields to retrieve. If unspecified, only the key field will be + :keyword list[str] select: The list of fields to retrieve. If unspecified, only the key field will be included in the results. - :type select: list[str] - :keyword top: The number of suggestions to retrieve. The value must be a number between 1 and + :keyword int top: The number of suggestions to retrieve. The value must be a number between 1 and 100. The default is 5. - :type top: int :rtype: List[dict] .. admonition:: Example: @@ -370,33 +349,26 @@ def autocomplete(self, search_text, suggester_name, **kwargs): :keyword autocomplete_mode: Specifies the mode for Autocomplete. The default is 'oneTerm'. Use 'twoTerms' to get shingles and 'oneTermWithContext' to use the current context while producing auto-completed terms. Possible values include: 'oneTerm', 'twoTerms', 'oneTermWithContext'. - :type autocomplete_mode: str or ~search_index_client.models.AutocompleteMode - :keyword filter: An OData expression that filters the documents used to produce completed terms + :paramtype autocomplete_mode: str or ~search_index_client.models.AutocompleteMode + :keyword str filter: An OData expression that filters the documents used to produce completed terms for the Autocomplete result. - :type filter: str - :keyword use_fuzzy_matching: A value indicating whether to use fuzzy matching for the + :keyword bool use_fuzzy_matching: A value indicating whether to use fuzzy matching for the autocomplete query. Default is false. When set to true, the query will find terms even if there's a substituted or missing character in the search text. While this provides a better experience in some scenarios, it comes at a performance cost as fuzzy autocomplete queries are slower and consume more resources. - :type use_fuzzy_matching: bool - :keyword highlight_post_tag: A string tag that is appended to hit highlights. Must be set with + :keyword str highlight_post_tag: A string tag that is appended to hit highlights. Must be set with highlightPreTag. If omitted, hit highlighting is disabled. - :type highlight_post_tag: str - :keyword highlight_pre_tag: A string tag that is prepended to hit highlights. Must be set with + :keyword str highlight_pre_tag: A string tag that is prepended to hit highlights. Must be set with highlightPostTag. If omitted, hit highlighting is disabled. - :type highlight_pre_tag: str - :keyword minimum_coverage: A number between 0 and 100 indicating the percentage of the index that + :keyword float minimum_coverage: A number between 0 and 100 indicating the percentage of the index that must be covered by an autocomplete query in order for the query to be reported as a success. This parameter can be useful for ensuring search availability even for services with only one replica. The default is 80. - :type minimum_coverage: float - :keyword search_fields: The list of field names to consider when querying for auto-completed + :keyword list[str] search_fields: The list of field names to consider when querying for auto-completed terms. Target fields must be included in the specified suggester. - :type search_fields: list[str] - :keyword top: The number of auto-completed terms to retrieve. This must be a value between 1 and + :keyword int top: The number of auto-completed terms to retrieve. This must be a value between 1 and 100. The default is 5. - :type top: int :rtype: List[dict] .. admonition:: Example: diff --git a/sdk/search/azure-search-documents/azure/search/documents/_internal/aio/_search_client_async.py b/sdk/search/azure-search-documents/azure/search/documents/_internal/aio/_search_client_async.py index b4355dcd234b..6d3f2da0da82 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_internal/aio/_search_client_async.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_internal/aio/_search_client_async.py @@ -11,7 +11,7 @@ from .._generated.models import IndexBatch, IndexingResult from .._index_documents_batch import IndexDocumentsBatch from .._queries import AutocompleteQuery, SearchQuery, SuggestQuery -from ..._api_versions import get_api_version +from ..._api_versions import check_api_version from ..._headers_mixin import HeadersMixin from ..._version import SDK_MONIKER @@ -48,7 +48,9 @@ class SearchClient(HeadersMixin): def __init__(self, endpoint, index_name, credential, **kwargs): # type: (str, str, AzureKeyCredential, **Any) -> None - get_api_version(kwargs, "2019-05-06-Preview") + api_version = kwargs.pop('api_version', None) + if api_version: + check_api_version(api_version) self._endpoint = endpoint # type: str self._index_name = index_name # type: str self._credential = credential # type: AzureKeyCredential @@ -112,68 +114,54 @@ async def search(self, search_text, **kwargs): :param str search_text: A full-text search query expression; Use "*" or omit this parameter to match all documents. - :keyword include_total_result_count: A value that specifies whether to fetch the total count of + :keyword bool include_total_result_count: A value that specifies whether to fetch the total count of results. Default is false. Setting this value to true may have a performance impact. Note that the count returned is an approximation. - :type include_total_result_count: bool - :keyword facets: The list of facet expressions to apply to the search query. Each facet + :keyword list[str] facets: The list of facet expressions to apply to the search query. Each facet expression contains a field name, optionally followed by a comma-separated list of name:value pairs. - :type facets: list[str] - :keyword filter: The OData $filter expression to apply to the search query. - :type filter: str - :keyword highlight_fields: The list of field names to use for hit highlights. Only searchable + :keyword str filter: The OData $filter expression to apply to the search query. + :keyword list[str] highlight_fields: The list of field names to use for hit highlights. Only searchable fields can be used for hit highlighting. - :type highlight_fields: list[str] - :keyword highlight_post_tag: A string tag that is appended to hit highlights. Must be set with + :keyword str highlight_post_tag: A string tag that is appended to hit highlights. Must be set with highlightPreTag. Default is </em>. - :type highlight_post_tag: str - :keyword highlight_pre_tag: A string tag that is prepended to hit highlights. Must be set with + :keyword str highlight_pre_tag: A string tag that is prepended to hit highlights. Must be set with highlightPostTag. Default is <em>. - :type highlight_pre_tag: str - :keyword minimum_coverage: A number between 0 and 100 indicating the percentage of the index that + :keyword float minimum_coverage: A number between 0 and 100 indicating the percentage of the index that must be covered by a search query in order for the query to be reported as a success. This parameter can be useful for ensuring search availability even for services with only one replica. The default is 100. - :type minimum_coverage: float - :keyword order_by: The list of OData $orderby expressions by which to sort the results. Each + :keyword list[str] order_by: The list of OData $orderby expressions by which to sort the results. Each expression can be either a field name or a call to either the geo.distance() or the search.score() functions. Each expression can be followed by asc to indicate ascending, and desc to indicate descending. The default is ascending order. Ties will be broken by the match scores of documents. If no OrderBy is specified, the default sort order is descending by document match score. There can be at most 32 $orderby clauses. - :type order_by: list[str] :keyword query_type: A value that specifies the syntax of the search query. The default is 'simple'. Use 'full' if your query uses the Lucene query syntax. Possible values include: 'simple', 'full'. - :type query_type: str or ~search_index_client.models.QueryType - :keyword scoring_parameters: The list of parameter values to be used in scoring functions (for + :paramtype query_type: str or ~search_index_client.models.QueryType + :keyword list[str] scoring_parameters: The list of parameter values to be used in scoring functions (for example, referencePointParameter) using the format name-values. For example, if the scoring profile defines a function with a parameter called 'mylocation' the parameter string would be "mylocation--122.2,44.8" (without the quotes). - :type scoring_parameters: list[str] - :keyword scoring_profile: The name of a scoring profile to evaluate match scores for matching + :keyword str scoring_profile: The name of a scoring profile to evaluate match scores for matching documents in order to sort the results. - :type scoring_profile: str - :keyword search_fields: The list of field names to which to scope the full-text search. When + :keyword list[str] search_fields: The list of field names to which to scope the full-text search. When using fielded search (fieldName:searchExpression) in a full Lucene query, the field names of each fielded search expression take precedence over any field names listed in this parameter. - :type search_fields: list[str] :keyword search_mode: A value that specifies whether any or all of the search terms must be matched in order to count the document as a match. Possible values include: 'any', 'all'. - :type search_mode: str or ~search_index_client.models.SearchMode - :keyword select: The list of fields to retrieve. If unspecified, all fields marked as retrievable + :paramtype search_mode: str or ~search_index_client.models.SearchMode + :keyword list[str] select: The list of fields to retrieve. If unspecified, all fields marked as retrievable in the schema are included. - :type select: list[str] - :keyword skip: The number of search results to skip. This value cannot be greater than 100,000. + :keyword int skip: The number of search results to skip. This value cannot be greater than 100,000. If you need to scan documents in sequence, but cannot use $skip due to this limitation, consider using $orderby on a totally-ordered key and $filter with a range query instead. - :type skip: int - :keyword top: The number of search results to retrieve. This can be used in conjunction with + :keyword int top: The number of search results to retrieve. This can be used in conjunction with $skip to implement client-side paging of search results. If results are truncated due to server-side paging, the response will include a continuation token that can be used to issue another Search request for the next page of results. - :type top: int :rtype: AsyncSearchItemPaged[dict] .. admonition:: Example: @@ -253,41 +241,32 @@ async def suggest(self, search_text, suggester_name, **kwargs): character, and no more than 100 characters. :param str suggester_name: Required. The name of the suggester as specified in the suggesters collection that's part of the index definition. - :keyword filter: An OData expression that filters the documents considered for suggestions. - :type filter: str - :keyword use_fuzzy_matching: A value indicating whether to use fuzzy matching for the suggestions + :keyword str filter: An OData expression that filters the documents considered for suggestions. + :keyword bool use_fuzzy_matching: A value indicating whether to use fuzzy matching for the suggestions query. Default is false. When set to true, the query will find terms even if there's a substituted or missing character in the search text. While this provides a better experience in some scenarios, it comes at a performance cost as fuzzy suggestions queries are slower and consume more resources. - :type use_fuzzy_matching: bool - :keyword highlight_post_tag: A string tag that is appended to hit highlights. Must be set with + :keyword str highlight_post_tag: A string tag that is appended to hit highlights. Must be set with highlightPreTag. If omitted, hit highlighting of suggestions is disabled. - :type highlight_post_tag: str - :keyword highlight_pre_tag: A string tag that is prepended to hit highlights. Must be set with + :keyword str highlight_pre_tag: A string tag that is prepended to hit highlights. Must be set with highlightPostTag. If omitted, hit highlighting of suggestions is disabled. - :type highlight_pre_tag: str - :keyword minimum_coverage: A number between 0 and 100 indicating the percentage of the index that + :keyword float minimum_coverage: A number between 0 and 100 indicating the percentage of the index that must be covered by a suggestions query in order for the query to be reported as a success. This parameter can be useful for ensuring search availability even for services with only one replica. The default is 80. - :type minimum_coverage: float - :keyword order_by: The list of OData $orderby expressions by which to sort the results. Each + :keyword list[str] order_by: The list of OData $orderby expressions by which to sort the results. Each expression can be either a field name or a call to either the geo.distance() or the search.score() functions. Each expression can be followed by asc to indicate ascending, or desc to indicate descending. The default is ascending order. Ties will be broken by the match scores of documents. If no $orderby is specified, the default sort order is descending by document match score. There can be at most 32 $orderby clauses. - :type order_by: list[str] - :keyword search_fields: The list of field names to search for the specified search text. Target + :keyword list[str] search_fields: The list of field names to search for the specified search text. Target fields must be included in the specified suggester. - :type search_fields: list[str] - :keyword select: The list of fields to retrieve. If unspecified, only the key field will be + :keyword list[str] select: The list of fields to retrieve. If unspecified, only the key field will be included in the results. - :type select: list[str] - :keyword top: The number of suggestions to retrieve. The value must be a number between 1 and + :keyword int top: The number of suggestions to retrieve. The value must be a number between 1 and 100. The default is 5. - :type top: int :rtype: List[dict] .. admonition:: Example: @@ -340,33 +319,26 @@ async def autocomplete(self, search_text, suggester_name, **kwargs): :keyword autocomplete_mode: Specifies the mode for Autocomplete. The default is 'oneTerm'. Use 'twoTerms' to get shingles and 'oneTermWithContext' to use the current context while producing auto-completed terms. Possible values include: 'oneTerm', 'twoTerms', 'oneTermWithContext'. - :type autocomplete_mode: str or ~search_index_client.models.AutocompleteMode - :keyword filter: An OData expression that filters the documents used to produce completed terms + :paramtype autocomplete_mode: str or ~search_index_client.models.AutocompleteMode + :keyword str filter: An OData expression that filters the documents used to produce completed terms for the Autocomplete result. - :type filter: str - :keyword use_fuzzy_matching: A value indicating whether to use fuzzy matching for the + :keyword bool use_fuzzy_matching: A value indicating whether to use fuzzy matching for the autocomplete query. Default is false. When set to true, the query will find terms even if there's a substituted or missing character in the search text. While this provides a better experience in some scenarios, it comes at a performance cost as fuzzy autocomplete queries are slower and consume more resources. - :type use_fuzzy_matching: bool - :keyword highlight_post_tag: A string tag that is appended to hit highlights. Must be set with + :keyword str highlight_post_tag: A string tag that is appended to hit highlights. Must be set with highlightPreTag. If omitted, hit highlighting is disabled. - :type highlight_post_tag: str - :keyword highlight_pre_tag: A string tag that is prepended to hit highlights. Must be set with + :keyword str highlight_pre_tag: A string tag that is prepended to hit highlights. Must be set with highlightPostTag. If omitted, hit highlighting is disabled. - :type highlight_pre_tag: str - :keyword minimum_coverage: A number between 0 and 100 indicating the percentage of the index that + :keyword float minimum_coverage: A number between 0 and 100 indicating the percentage of the index that must be covered by an autocomplete query in order for the query to be reported as a success. This parameter can be useful for ensuring search availability even for services with only one replica. The default is 80. - :type minimum_coverage: float - :keyword search_fields: The list of field names to consider when querying for auto-completed + :keyword list[str] search_fields: The list of field names to consider when querying for auto-completed terms. Target fields must be included in the specified suggester. - :type search_fields: list[str] - :keyword top: The number of auto-completed terms to retrieve. This must be a value between 1 and + :keyword int top: The number of auto-completed terms to retrieve. This must be a value between 1 and 100. The default is 5. - :type top: int :rtype: List[dict] .. admonition:: Example: diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_index_client.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_index_client.py index 54cd85570a8e..9307a96ad77e 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_index_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_index_client.py @@ -9,7 +9,7 @@ from azure.core.tracing.decorator import distributed_trace from azure.core.paging import ItemPaged -from ..._api_versions import get_api_version +from ..._api_versions import check_api_version from ._generated import SearchServiceClient as _SearchServiceClient from ._utils import ( unpack_search_index, @@ -46,7 +46,9 @@ class SearchIndexClient(HeadersMixin): def __init__(self, endpoint, credential, **kwargs): # type: (str, AzureKeyCredential, **Any) -> None - get_api_version(kwargs, "2019-05-06-Preview") + api_version = kwargs.pop('api_version', None) + if api_version: + check_api_version(api_version) self._endpoint = normalize_endpoint(endpoint) # type: str self._credential = credential # type: AzureKeyCredential self._client = _SearchServiceClient( diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_indexer_client.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_indexer_client.py index c29256bc368c..7ba918ea740c 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_indexer_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_indexer_client.py @@ -16,7 +16,7 @@ pack_search_indexer_data_source, unpack_search_indexer_data_source, ) -from ..._api_versions import get_api_version +from ..._api_versions import check_api_version from ..._headers_mixin import HeadersMixin from ..._version import SDK_MONIKER @@ -44,7 +44,9 @@ class SearchIndexerClient(HeadersMixin): # pylint: disable=R0904 def __init__(self, endpoint, credential, **kwargs): # type: (str, AzureKeyCredential, **Any) -> None - get_api_version(kwargs, "2019-05-06-Preview") + api_version = kwargs.pop('api_version', None) + if api_version: + check_api_version(api_version) self._endpoint = normalize_endpoint(endpoint) # type: str self._credential = credential # type: AzureKeyCredential self._client = _SearchServiceClient( diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_index_client.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_index_client.py index 541ae2ba673d..f3983284cc7f 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_index_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_index_client.py @@ -19,7 +19,7 @@ get_access_conditions, normalize_endpoint, ) -from ...._api_versions import get_api_version +from ...._api_versions import check_api_version from ...._headers_mixin import HeadersMixin from ...._version import SDK_MONIKER @@ -48,7 +48,9 @@ class SearchIndexClient(HeadersMixin): def __init__(self, endpoint, credential, **kwargs): # type: (str, AzureKeyCredential, **Any) -> None - get_api_version(kwargs, "2019-05-06-Preview") + api_version = kwargs.pop('api_version', None) + if api_version: + check_api_version(api_version) self._endpoint = normalize_endpoint(endpoint) # type: str self._credential = credential # type: AzureKeyCredential self._client = _SearchServiceClient( diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_indexer_client.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_indexer_client.py index c12e5a24561f..f9d7d86c3cf6 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_indexer_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_indexer_client.py @@ -16,7 +16,7 @@ pack_search_indexer_data_source, unpack_search_indexer_data_source, ) -from ...._api_versions import get_api_version +from ...._api_versions import check_api_version from ...._headers_mixin import HeadersMixin from ...._version import SDK_MONIKER @@ -44,7 +44,9 @@ class SearchIndexerClient(HeadersMixin): # pylint: disable=R0904 def __init__(self, endpoint, credential, **kwargs): # type: (str, AzureKeyCredential, **Any) -> None - get_api_version(kwargs, "2019-05-06-Preview") + api_version = kwargs.pop('api_version', None) + if api_version: + check_api_version(api_version) self._endpoint = normalize_endpoint(endpoint) # type: str self._credential = credential # type: AzureKeyCredential self._client = _SearchServiceClient( From fc5212d558526c1f13dba07290816182da567c6f Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Thu, 25 Jun 2020 12:00:48 -0700 Subject: [PATCH 4/7] remove default api version in docstring --- .../azure/search/documents/_internal/_search_client.py | 3 +-- .../search/documents/_internal/aio/_search_client_async.py | 3 +-- .../search/documents/indexes/_internal/_search_index_client.py | 3 +-- .../documents/indexes/_internal/_search_indexer_client.py | 3 +-- .../documents/indexes/_internal/aio/_search_index_client.py | 3 +-- .../documents/indexes/_internal/aio/_search_indexer_client.py | 3 +-- 6 files changed, 6 insertions(+), 12 deletions(-) diff --git a/sdk/search/azure-search-documents/azure/search/documents/_internal/_search_client.py b/sdk/search/azure-search-documents/azure/search/documents/_internal/_search_client.py index 957d7a3b4631..d10787159b30 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_internal/_search_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_internal/_search_client.py @@ -60,8 +60,7 @@ class SearchClient(HeadersMixin): :type index_name: str :param credential: A credential to authorize search client requests :type credential: ~azure.core.credentials.AzureKeyCredential - :keyword str api_version: - The Search API version to use for requests. Default value is "2019-05-06-Preview". + :keyword str api_version: The Search API version to use for requests. .. admonition:: Example: diff --git a/sdk/search/azure-search-documents/azure/search/documents/_internal/aio/_search_client_async.py b/sdk/search/azure-search-documents/azure/search/documents/_internal/aio/_search_client_async.py index 6d3f2da0da82..7be4e5248319 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_internal/aio/_search_client_async.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_internal/aio/_search_client_async.py @@ -30,8 +30,7 @@ class SearchClient(HeadersMixin): :type index_name: str :param credential: A credential to authorize search client requests :type credential: ~azure.core.credentials.AzureKeyCredential - :keyword str api_version: - The Search API version to use for requests. Default value is "2019-05-06-Preview". + :keyword str api_version: The Search API version to use for requests. .. admonition:: Example: diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_index_client.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_index_client.py index 9307a96ad77e..6a94595a3973 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_index_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_index_client.py @@ -37,8 +37,7 @@ class SearchIndexClient(HeadersMixin): :type endpoint: str :param credential: A credential to authorize search client requests :type credential: ~azure.core.credentials.AzureKeyCredential - :keyword str api_version: - The Search API version to use for requests. Default value is "2019-05-06-Preview". + :keyword str api_version: The Search API version to use for requests. """ _ODATA_ACCEPT = "application/json;odata.metadata=minimal" # type: str diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_indexer_client.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_indexer_client.py index 7ba918ea740c..eb4f4ee68ab5 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_indexer_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_indexer_client.py @@ -34,8 +34,7 @@ class SearchIndexerClient(HeadersMixin): # pylint: disable=R0904 :type endpoint: str :param credential: A credential to authorize search client requests :type credential: ~azure.core.credentials.AzureKeyCredential - :keyword str api_version: - The Search API version to use for requests. Default value is "2019-05-06-Preview". + :keyword str api_version: The Search API version to use for requests. """ diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_index_client.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_index_client.py index f3983284cc7f..a734f66e40b6 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_index_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_index_client.py @@ -38,8 +38,7 @@ class SearchIndexClient(HeadersMixin): :type endpoint: str :param credential: A credential to authorize search client requests :type credential: ~azure.core.credentials.AzureKeyCredential - :keyword str api_version: - The Search API version to use for requests. Default value is "2019-05-06-Preview". + :keyword str api_version: The Search API version to use for requests. """ diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_indexer_client.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_indexer_client.py index f9d7d86c3cf6..17e10430c712 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_indexer_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_indexer_client.py @@ -34,8 +34,7 @@ class SearchIndexerClient(HeadersMixin): # pylint: disable=R0904 :type endpoint: str :param credential: A credential to authorize search client requests :type credential: ~azure.core.credentials.AzureKeyCredential - :keyword str api_version: - The Search API version to use for requests. Default value is "2019-05-06-Preview". + :keyword str api_version: The Search API version to use for requests. """ From 123f2d65bf9582b49c2c420ee6196ee4b68c1111 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Thu, 25 Jun 2020 12:51:14 -0700 Subject: [PATCH 5/7] update kwarg names --- .../azure/search/documents/_internal/_search_client.py | 10 +++++----- .../documents/_internal/aio/_search_client_async.py | 10 +++++----- .../tests/async_tests/test_index_live_async.py | 2 +- .../azure-search-documents/tests/test_index_live.py | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/sdk/search/azure-search-documents/azure/search/documents/_internal/_search_client.py b/sdk/search/azure-search-documents/azure/search/documents/_internal/_search_client.py index d10787159b30..a8f60fd873a7 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_internal/_search_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_internal/_search_client.py @@ -143,7 +143,7 @@ def search(self, search_text, **kwargs): :param str search_text: A full-text search query expression; Use "*" or omit this parameter to match all documents. - :keyword bool include_total_result_count: A value that specifies whether to fetch the total count of + :keyword bool include_total_count: A value that specifies whether to fetch the total count of results. Default is false. Setting this value to true may have a performance impact. Note that the count returned is an approximation. :keyword list[str] facets: The list of facet expressions to apply to the search query. Each facet @@ -220,7 +220,7 @@ def search(self, search_text, **kwargs): :dedent: 4 :caption: Get search result facets. """ - include_total_result_count = kwargs.pop("include_total_result_count", None) + include_total_result_count = kwargs.pop("include_total_count", None) facets = kwargs.pop("facets", None) filter_arg = kwargs.pop("filter", None) highlight_fields = kwargs.pop("highlight_fields", None) @@ -345,10 +345,10 @@ def autocomplete(self, search_text, suggester_name, **kwargs): :param str search_text: The search text on which to base autocomplete results. :param str suggester_name: The name of the suggester as specified in the suggesters collection that's part of the index definition. - :keyword autocomplete_mode: Specifies the mode for Autocomplete. The default is 'oneTerm'. Use + :keyword mode: Specifies the mode for Autocomplete. The default is 'oneTerm'. Use 'twoTerms' to get shingles and 'oneTermWithContext' to use the current context while producing auto-completed terms. Possible values include: 'oneTerm', 'twoTerms', 'oneTermWithContext'. - :paramtype autocomplete_mode: str or ~search_index_client.models.AutocompleteMode + :paramtype mode: str or ~search_index_client.models.AutocompleteMode :keyword str filter: An OData expression that filters the documents used to produce completed terms for the Autocomplete result. :keyword bool use_fuzzy_matching: A value indicating whether to use fuzzy matching for the @@ -379,7 +379,7 @@ def autocomplete(self, search_text, suggester_name, **kwargs): :dedent: 4 :caption: Get a auto-completions. """ - autocomplete_mode = kwargs.pop("autocomplete_mode", None) + autocomplete_mode = kwargs.pop("mode", None) filter_arg = kwargs.pop("filter", None) use_fuzzy_matching = kwargs.pop("use_fuzzy_matching", None) highlight_post_tag = kwargs.pop("highlight_post_tag", None) diff --git a/sdk/search/azure-search-documents/azure/search/documents/_internal/aio/_search_client_async.py b/sdk/search/azure-search-documents/azure/search/documents/_internal/aio/_search_client_async.py index 7be4e5248319..70fe16200fc1 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_internal/aio/_search_client_async.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_internal/aio/_search_client_async.py @@ -113,7 +113,7 @@ async def search(self, search_text, **kwargs): :param str search_text: A full-text search query expression; Use "*" or omit this parameter to match all documents. - :keyword bool include_total_result_count: A value that specifies whether to fetch the total count of + :keyword bool include_total_count: A value that specifies whether to fetch the total count of results. Default is false. Setting this value to true may have a performance impact. Note that the count returned is an approximation. :keyword list[str] facets: The list of facet expressions to apply to the search query. Each facet @@ -190,7 +190,7 @@ async def search(self, search_text, **kwargs): :dedent: 4 :caption: Get search result facets. """ - include_total_result_count = kwargs.pop("include_total_result_count", None) + include_total_result_count = kwargs.pop("include_total_count", None) facets = kwargs.pop("facets", None) filter_arg = kwargs.pop("filter", None) highlight_fields = kwargs.pop("highlight_fields", None) @@ -315,10 +315,10 @@ async def autocomplete(self, search_text, suggester_name, **kwargs): :param str search_text: The search text on which to base autocomplete results. :param str suggester_name: The name of the suggester as specified in the suggesters collection that's part of the index definition. - :keyword autocomplete_mode: Specifies the mode for Autocomplete. The default is 'oneTerm'. Use + :keyword mode: Specifies the mode for Autocomplete. The default is 'oneTerm'. Use 'twoTerms' to get shingles and 'oneTermWithContext' to use the current context while producing auto-completed terms. Possible values include: 'oneTerm', 'twoTerms', 'oneTermWithContext'. - :paramtype autocomplete_mode: str or ~search_index_client.models.AutocompleteMode + :paramtype mode: str or ~search_index_client.models.AutocompleteMode :keyword str filter: An OData expression that filters the documents used to produce completed terms for the Autocomplete result. :keyword bool use_fuzzy_matching: A value indicating whether to use fuzzy matching for the @@ -349,7 +349,7 @@ async def autocomplete(self, search_text, suggester_name, **kwargs): :dedent: 4 :caption: Get a auto-completions. """ - autocomplete_mode = kwargs.pop("autocomplete_mode", None) + autocomplete_mode = kwargs.pop("mode", None) filter_arg = kwargs.pop("filter", None) use_fuzzy_matching = kwargs.pop("use_fuzzy_matching", None) highlight_post_tag = kwargs.pop("highlight_post_tag", None) diff --git a/sdk/search/azure-search-documents/tests/async_tests/test_index_live_async.py b/sdk/search/azure-search-documents/tests/async_tests/test_index_live_async.py index b47e3c78ffcf..c2c674baf673 100644 --- a/sdk/search/azure-search-documents/tests/async_tests/test_index_live_async.py +++ b/sdk/search/azure-search-documents/tests/async_tests/test_index_live_async.py @@ -135,7 +135,7 @@ async def test_get_search_counts(self, api_key, endpoint, index_name, **kwargs): results = await client.search(search_text="hotel") assert await results.get_count() is None - results = await client.search(search_text="hotel", include_total_result_count=True) + results = await client.search(search_text="hotel", include_total_count=True) assert await results.get_count() == 7 @ResourceGroupPreparer(random_name_enabled=True) diff --git a/sdk/search/azure-search-documents/tests/test_index_live.py b/sdk/search/azure-search-documents/tests/test_index_live.py index 4401009e4734..8b8317c14126 100644 --- a/sdk/search/azure-search-documents/tests/test_index_live.py +++ b/sdk/search/azure-search-documents/tests/test_index_live.py @@ -104,7 +104,7 @@ def test_get_search_counts(self, api_key, endpoint, index_name, **kwargs): results = client.search(search_text="hotel") assert results.get_count() is None - results = client.search(search_text="hotel", include_total_result_count=True) + results = client.search(search_text="hotel", include_total_count=True) assert results.get_count() == 7 @ResourceGroupPreparer(random_name_enabled=True) From b64ccacf111580ad8d5ddd5dd91bbae484116ef3 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Thu, 25 Jun 2020 13:46:34 -0700 Subject: [PATCH 6/7] update --- .../azure/search/documents/_api_versions.py | 8 +++++--- .../azure/search/documents/_internal/_search_client.py | 5 ++--- .../documents/_internal/aio/_search_client_async.py | 5 ++--- .../documents/indexes/_internal/_search_index_client.py | 5 ++--- .../documents/indexes/_internal/_search_indexer_client.py | 5 ++--- .../indexes/_internal/aio/_search_index_client.py | 5 ++--- .../indexes/_internal/aio/_search_indexer_client.py | 5 ++--- 7 files changed, 17 insertions(+), 21 deletions(-) diff --git a/sdk/search/azure-search-documents/azure/search/documents/_api_versions.py b/sdk/search/azure-search-documents/azure/search/documents/_api_versions.py index b7ada7b3fd47..3d75e3b72471 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_api_versions.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_api_versions.py @@ -7,8 +7,11 @@ "2019-05-06-Preview", ] -def check_api_version(api_version): +def validate_api_version(api_version): # type: (str) -> None + """Raise error if api_version is invalid """ + if not api_version: + return if api_version not in _SUPPORTED_API_VERSIONS: versions = '\n'.join(_SUPPORTED_API_VERSIONS) raise ValueError("Unsupported API version '{}'. Please select from:\n{}".format(api_version, versions)) @@ -17,6 +20,5 @@ def check_api_version(api_version): def get_api_version(kwargs, default): # type: (Dict[str, Any]) -> str api_version = kwargs.pop('api_version', None) - if api_version: - check_api_version(api_version) + validate_api_version(api_version) return api_version or default diff --git a/sdk/search/azure-search-documents/azure/search/documents/_internal/_search_client.py b/sdk/search/azure-search-documents/azure/search/documents/_internal/_search_client.py index a8f60fd873a7..de70b29cbc99 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_internal/_search_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_internal/_search_client.py @@ -8,7 +8,7 @@ import six from azure.core.tracing.decorator import distributed_trace -from .._api_versions import check_api_version +from .._api_versions import validate_api_version from ._generated import SearchIndexClient from ._generated.models import IndexBatch, IndexingResult from ._index_documents_batch import IndexDocumentsBatch @@ -78,8 +78,7 @@ def __init__(self, endpoint, index_name, credential, **kwargs): # type: (str, str, AzureKeyCredential, **Any) -> None api_version = kwargs.pop('api_version', None) - if api_version: - check_api_version(api_version) + validate_api_version(api_version) self._endpoint = endpoint # type: str self._index_name = index_name # type: str self._credential = credential # type: AzureKeyCredential diff --git a/sdk/search/azure-search-documents/azure/search/documents/_internal/aio/_search_client_async.py b/sdk/search/azure-search-documents/azure/search/documents/_internal/aio/_search_client_async.py index 70fe16200fc1..084ebe9a2448 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_internal/aio/_search_client_async.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_internal/aio/_search_client_async.py @@ -11,7 +11,7 @@ from .._generated.models import IndexBatch, IndexingResult from .._index_documents_batch import IndexDocumentsBatch from .._queries import AutocompleteQuery, SearchQuery, SuggestQuery -from ..._api_versions import check_api_version +from ..._api_versions import validate_api_version from ..._headers_mixin import HeadersMixin from ..._version import SDK_MONIKER @@ -48,8 +48,7 @@ def __init__(self, endpoint, index_name, credential, **kwargs): # type: (str, str, AzureKeyCredential, **Any) -> None api_version = kwargs.pop('api_version', None) - if api_version: - check_api_version(api_version) + validate_api_version(api_version) self._endpoint = endpoint # type: str self._index_name = index_name # type: str self._credential = credential # type: AzureKeyCredential diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_index_client.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_index_client.py index 6a94595a3973..8fe294555ec1 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_index_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_index_client.py @@ -9,7 +9,7 @@ from azure.core.tracing.decorator import distributed_trace from azure.core.paging import ItemPaged -from ..._api_versions import check_api_version +from ..._api_versions import validate_api_version from ._generated import SearchServiceClient as _SearchServiceClient from ._utils import ( unpack_search_index, @@ -46,8 +46,7 @@ def __init__(self, endpoint, credential, **kwargs): # type: (str, AzureKeyCredential, **Any) -> None api_version = kwargs.pop('api_version', None) - if api_version: - check_api_version(api_version) + validate_api_version(api_version) self._endpoint = normalize_endpoint(endpoint) # type: str self._credential = credential # type: AzureKeyCredential self._client = _SearchServiceClient( diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_indexer_client.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_indexer_client.py index eb4f4ee68ab5..243bd19369f4 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_indexer_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_indexer_client.py @@ -16,7 +16,7 @@ pack_search_indexer_data_source, unpack_search_indexer_data_source, ) -from ..._api_versions import check_api_version +from ..._api_versions import validate_api_version from ..._headers_mixin import HeadersMixin from ..._version import SDK_MONIKER @@ -44,8 +44,7 @@ def __init__(self, endpoint, credential, **kwargs): # type: (str, AzureKeyCredential, **Any) -> None api_version = kwargs.pop('api_version', None) - if api_version: - check_api_version(api_version) + validate_api_version(api_version) self._endpoint = normalize_endpoint(endpoint) # type: str self._credential = credential # type: AzureKeyCredential self._client = _SearchServiceClient( diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_index_client.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_index_client.py index a734f66e40b6..de914c628294 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_index_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_index_client.py @@ -19,7 +19,7 @@ get_access_conditions, normalize_endpoint, ) -from ...._api_versions import check_api_version +from ...._api_versions import validate_api_version from ...._headers_mixin import HeadersMixin from ...._version import SDK_MONIKER @@ -48,8 +48,7 @@ def __init__(self, endpoint, credential, **kwargs): # type: (str, AzureKeyCredential, **Any) -> None api_version = kwargs.pop('api_version', None) - if api_version: - check_api_version(api_version) + validate_api_version(api_version) self._endpoint = normalize_endpoint(endpoint) # type: str self._credential = credential # type: AzureKeyCredential self._client = _SearchServiceClient( diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_indexer_client.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_indexer_client.py index 17e10430c712..bb561041cc26 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_indexer_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_indexer_client.py @@ -16,7 +16,7 @@ pack_search_indexer_data_source, unpack_search_indexer_data_source, ) -from ...._api_versions import check_api_version +from ...._api_versions import validate_api_version from ...._headers_mixin import HeadersMixin from ...._version import SDK_MONIKER @@ -44,8 +44,7 @@ def __init__(self, endpoint, credential, **kwargs): # type: (str, AzureKeyCredential, **Any) -> None api_version = kwargs.pop('api_version', None) - if api_version: - check_api_version(api_version) + validate_api_version(api_version) self._endpoint = normalize_endpoint(endpoint) # type: str self._credential = credential # type: AzureKeyCredential self._client = _SearchServiceClient( From 13baf4ec6493bc81e30ed1b89a63bd46fa86b8be Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Thu, 25 Jun 2020 14:22:32 -0700 Subject: [PATCH 7/7] update --- .../azure/search/documents/_api_versions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/search/azure-search-documents/azure/search/documents/_api_versions.py b/sdk/search/azure-search-documents/azure/search/documents/_api_versions.py index 3d75e3b72471..72934ea501b9 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_api_versions.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_api_versions.py @@ -18,7 +18,7 @@ def validate_api_version(api_version): def get_api_version(kwargs, default): - # type: (Dict[str, Any]) -> str + # type: (Dict[str, Any], str) -> str api_version = kwargs.pop('api_version', None) validate_api_version(api_version) return api_version or default