Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class SearchClient(_SearchClientOperationsMixin):
"""SearchClient.

:param endpoint: Service host. Required.
:param endpoint: The endpoint URL of the search service. Required.
:type endpoint: str
:param credential: Credential used to authenticate requests to the service. Is either a key
credential type or a token credential type. Required.
Expand All @@ -35,8 +35,8 @@ class SearchClient(_SearchClientOperationsMixin):
:param index_name: The name of the index. Required.
:type index_name: str
:keyword api_version: The API version to use for this operation. Known values are
"2025-11-01-preview" and None. Default value is "2025-11-01-preview". Note that overriding this
default value may result in unsupported behavior.
"2026-05-01-preview". Default value is "2026-05-01-preview". Note that overriding this default
value may result in unsupported behavior.
:paramtype api_version: str
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SearchClientConfiguration: # pylint: disable=too-many-instance-attributes
Note that all parameters used to create this instance are saved as instance
attributes.

:param endpoint: Service host. Required.
:param endpoint: The endpoint URL of the search service. Required.
:type endpoint: str
:param credential: Credential used to authenticate requests to the service. Is either a key
credential type or a token credential type. Required.
Expand All @@ -32,15 +32,15 @@ class SearchClientConfiguration: # pylint: disable=too-many-instance-attributes
:param index_name: The name of the index. Required.
:type index_name: str
:keyword api_version: The API version to use for this operation. Known values are
"2025-11-01-preview" and None. Default value is "2025-11-01-preview". Note that overriding this
default value may result in unsupported behavior.
"2026-05-01-preview". Default value is "2026-05-01-preview". Note that overriding this default
value may result in unsupported behavior.
:paramtype api_version: str
"""

def __init__(
self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], index_name: str, **kwargs: Any
) -> None:
api_version: str = kwargs.pop("api_version", "2025-11-01-preview")
api_version: str = kwargs.pop("api_version", "2026-05-01-preview")

if endpoint is None:
raise ValueError("Parameter 'endpoint' must not be None.")
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def _build_search_request(
query_rewrites_count: Optional[int] = None,
debug: Optional[Union[str, _models.QueryDebugMode]] = None,
hybrid_search: Optional[_models.HybridSearch] = None,
relevance_score_mode: Optional[Union[str, _models.RelevanceScoreMode]] = None,
query_insights_enabled: Optional[bool] = None,
) -> _models.SearchRequest:
# pylint:disable=too-many-locals
"""Build a SearchRequest from search parameters.
Expand Down Expand Up @@ -176,6 +178,8 @@ def _build_search_request(
:keyword int query_rewrites_count: The maximum number of query rewrites to apply.
:keyword debug: The debug mode for the search query.
:keyword hybrid_search: The hybrid search configuration for the search query.
:keyword relevance_score_mode: The relevance scoring mode to use when ranking results.
:keyword bool query_insights_enabled: A value indicating whether to include query performance insights.
:return: SearchRequest
:rtype: ~azure.search.documents.models.SearchRequest
"""
Expand Down Expand Up @@ -240,6 +244,8 @@ def _build_search_request(
query_rewrites=rewrites,
debug=debug,
hybrid_search=hybrid_search,
relevance_score_mode=relevance_score_mode,
query_insights_enabled=query_insights_enabled,
)


Expand All @@ -256,7 +262,7 @@ def __init__(self, client, initial_request: _models.SearchRequest, kwargs, conti
self._initial_request = initial_request
self._kwargs = kwargs
self._facets: Optional[Dict[str, List[Dict[str, Any]]]] = None
self._api_version = kwargs.get("api_version", "2025-11-01-preview")
self._api_version = kwargs.get("api_version", "2026-05-01-preview")

def _get_next_cb(self, continuation_token):
if continuation_token is None:
Expand Down Expand Up @@ -306,6 +312,12 @@ def get_debug_info(self) -> Optional[_models.DebugInfo]:
response = cast(_models.SearchDocumentsResult, self._response)
return response.debug_info

@_ensure_response
def get_query_insights(self) -> Optional[_models.QueryInsights]:
self.continuation_token = None
response = cast(_models.SearchDocumentsResult, self._response)
return response.query_insights


class SearchItemPaged(ItemPaged[ReturnType]):
"""A pageable list of search results."""
Expand Down Expand Up @@ -368,6 +380,14 @@ def get_debug_info(self) -> _models.DebugInfo:
"""
return cast(_models.DebugInfo, self._first_iterator_instance().get_debug_info())

def get_query_insights(self) -> Optional[_models.QueryInsights]:
"""Return query performance insights. Only populated when query_insights_enabled is True.

:return: query insights
:rtype: ~azure.search.documents.models.QueryInsights or None
"""
return cast(Optional[_models.QueryInsights], self._first_iterator_instance().get_query_insights())


class _SearchClientOperationsMixin(_SearchClientOperationsMixinGenerated):
"""SearchClient operations mixin customizations."""
Expand Down Expand Up @@ -567,6 +587,8 @@ def search(
hybrid_search: Optional[_models.HybridSearch] = None,
query_source_authorization: Optional[str] = None,
enable_elevated_read: Optional[bool] = None,
relevance_score_mode: Optional[Union[str, _models.RelevanceScoreMode]] = None,
query_insights_enabled: Optional[bool] = None,
**kwargs: Any,
) -> SearchItemPaged[Dict]:
# pylint:disable=too-many-locals
Expand Down Expand Up @@ -706,6 +728,11 @@ def search(
:keyword enable_elevated_read: A value that enables elevated read that bypass document level
permission checks for the query operation. Default value is None.
:paramtype enable_elevated_read: bool
:keyword relevance_score_mode: Specifies the relevance scoring mode to use when ranking results.
Known values are: "classic", "enhanced", and "learned".
:paramtype relevance_score_mode: str or ~azure.search.documents.models.RelevanceScoreMode
:keyword bool query_insights_enabled: A value indicating whether to include query performance
insights in the response.
:return: List of search results.
:rtype: SearchItemPaged[dict]

Expand Down Expand Up @@ -775,6 +802,8 @@ def search(
query_rewrites_count=query_rewrites_count,
debug=debug,
hybrid_search=hybrid_search,
relevance_score_mode=relevance_score_mode,
query_insights_enabled=query_insights_enabled,
)

# Create kwargs for the search_post call
Expand All @@ -792,7 +821,7 @@ def autocomplete(
search_text: str,
suggester_name: str,
*,
mode: Optional[Union[str, _models.AutocompleteMode]] = None,
mode: Optional[Union[str, _models._enums.AutocompleteMode]] = None,
filter: Optional[str] = None,
use_fuzzy_matching: Optional[bool] = None,
highlight_post_tag: Optional[str] = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ class ApiVersion(str, Enum, metaclass=CaseInsensitiveEnumMeta):
V2024_07_01 = "2024-07-01"
V2025_09_01 = "2025-09-01"
V2025_11_01_PREVIEW = "2025-11-01-preview"
V2026_05_01_PREVIEW = "2026-05-01-preview"


DEFAULT_VERSION = ApiVersion.V2025_11_01_PREVIEW
DEFAULT_VERSION = ApiVersion.V2026_05_01_PREVIEW


class SearchClient(_SearchClient):
Expand All @@ -58,7 +59,7 @@ class SearchClient(_SearchClient):
:param index_name: The name of the index. Required.
:type index_name: str
:keyword api_version: The API version to use for this operation. Default value is
"2025-11-01-preview". Note that overriding this default value may result in unsupported
"2026-05-01-preview". Note that overriding this default value may result in unsupported
behavior.
:paramtype api_version: str
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,8 @@ def setdefault(self, key: str, default: typing.Any = _UNSET) -> typing.Any:
return self._data.setdefault(key, default)

def __eq__(self, other: typing.Any) -> bool:
if isinstance(other, _MyMutableMapping):
return self._data == other._data
try:
other_model = self.__class__(other)
except Exception:
Expand Down Expand Up @@ -628,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None:
if len(items) > 0:
existed_attr_keys.append(xml_name)
dict_to_pass[rf._rest_name] = _deserialize(rf._type, items)
elif not rf._is_optional:
existed_attr_keys.append(xml_name)
dict_to_pass[rf._rest_name] = []
continue

# text element is primitive type
Expand Down Expand Up @@ -889,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur
# is it optional?
try:
if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore
if rf:
rf._is_optional = True
if len(annotation.__args__) <= 2: # pyright: ignore
if_obj_deserializer = _get_deserialize_callable_from_annotation(
next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore
Expand Down Expand Up @@ -981,16 +988,20 @@ def _deserialize_with_callable(
return float(value.text) if value.text else None
if deserializer is bool:
return value.text == "true" if value.text else None
if deserializer and deserializer in _DESERIALIZE_MAPPING.values():
return deserializer(value.text) if value.text else None
if deserializer and deserializer in _DESERIALIZE_MAPPING_WITHFORMAT.values():
return deserializer(value.text) if value.text else None
if deserializer is None:
return value
if deserializer in [int, float, bool]:
return deserializer(value)
if isinstance(deserializer, CaseInsensitiveEnumMeta):
try:
return deserializer(value)
return deserializer(value.text if isinstance(value, ET.Element) else value)
except ValueError:
# for unknown value, return raw value
return value
return value.text if isinstance(value, ET.Element) else value
if isinstance(deserializer, type) and issubclass(deserializer, Model):
return deserializer._deserialize(value, [])
return typing.cast(typing.Callable[[typing.Any], typing.Any], deserializer)(value)
Expand Down Expand Up @@ -1043,6 +1054,7 @@ def _failsafe_deserialize_xml(
return None


# pylint: disable=too-many-instance-attributes
class _RestField:
def __init__(
self,
Expand All @@ -1062,6 +1074,7 @@ def __init__(
self._is_discriminator = is_discriminator
self._visibility = visibility
self._is_model = False
self._is_optional = False
self._default = default
self._format = format
self._is_multipart_file_input = is_multipart_file_input
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
import functools


def api_version_validation(**kwargs):
params_added_on = kwargs.pop("params_added_on", {})
method_added_on = kwargs.pop("method_added_on", "")
api_versions_list = kwargs.pop("api_versions_list", [])

def _index_with_default(value: str, default: int = -1) -> int:
"""Get the index of value in lst, or return default if not found.

:param value: The value to search for in the api_versions_list.
:type value: str
:param default: The default value to return if the value is not found.
:type default: int
:return: The index of the value in the list, or the default value if not found.
:rtype: int
"""
try:
return int(api_versions_list.index(value))
except ValueError:
return default

def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
try:
# this assumes the client has an _api_version attribute
client = args[0]
client_api_version = client._config.api_version # pylint: disable=protected-access
except AttributeError:
return func(*args, **kwargs)

if _index_with_default(method_added_on) > _index_with_default(client_api_version):
raise ValueError(
f"'{func.__name__}' is not available in API version "
f"{client_api_version}. Pass service API version {method_added_on} or newer to your client."
)

unsupported = {
parameter: api_version
for api_version, parameters in params_added_on.items()
for parameter in parameters
if parameter in kwargs and _index_with_default(api_version) > _index_with_default(client_api_version)
}
if unsupported:
raise ValueError(
"".join(
[
f"'{param}' is not available in API version {client_api_version}. "
f"Use service API version {version} or newer.\n"
for param, version in unsupported.items()
]
)
)
return func(*args, **kwargs)

return wrapper

return decorator
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class SearchClient(_SearchClientOperationsMixin):
"""SearchClient.

:param endpoint: Service host. Required.
:param endpoint: The endpoint URL of the search service. Required.
:type endpoint: str
:param credential: Credential used to authenticate requests to the service. Is either a key
credential type or a token credential type. Required.
Expand All @@ -35,8 +35,8 @@ class SearchClient(_SearchClientOperationsMixin):
:param index_name: The name of the index. Required.
:type index_name: str
:keyword api_version: The API version to use for this operation. Known values are
"2025-11-01-preview" and None. Default value is "2025-11-01-preview". Note that overriding this
default value may result in unsupported behavior.
"2026-05-01-preview". Default value is "2026-05-01-preview". Note that overriding this default
value may result in unsupported behavior.
:paramtype api_version: str
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SearchClientConfiguration: # pylint: disable=too-many-instance-attributes
Note that all parameters used to create this instance are saved as instance
attributes.

:param endpoint: Service host. Required.
:param endpoint: The endpoint URL of the search service. Required.
:type endpoint: str
:param credential: Credential used to authenticate requests to the service. Is either a key
credential type or a token credential type. Required.
Expand All @@ -32,8 +32,8 @@ class SearchClientConfiguration: # pylint: disable=too-many-instance-attributes
:param index_name: The name of the index. Required.
:type index_name: str
:keyword api_version: The API version to use for this operation. Known values are
"2025-11-01-preview" and None. Default value is "2025-11-01-preview". Note that overriding this
default value may result in unsupported behavior.
"2026-05-01-preview". Default value is "2026-05-01-preview". Note that overriding this default
value may result in unsupported behavior.
:paramtype api_version: str
"""

Expand All @@ -44,7 +44,7 @@ def __init__(
index_name: str,
**kwargs: Any,
) -> None:
api_version: str = kwargs.pop("api_version", "2025-11-01-preview")
api_version: str = kwargs.pop("api_version", "2026-05-01-preview")

if endpoint is None:
raise ValueError("Parameter 'endpoint' must not be None.")
Expand Down
Loading
Loading