Skip to content

Commit ae85461

Browse files
algolia-botmillotp
andcommitted
fix(specs): make the searchParams compatible with v4 [skip-bc] (generated)
algolia/api-clients-automation#4108 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Pierre Millot <[email protected]>
1 parent 6112cd0 commit ae85461

14 files changed

+574
-61
lines changed

algoliasearch/recommend/models/fallback_params.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
)
3131
from algoliasearch.recommend.models.facet_filters import FacetFilters
3232
from algoliasearch.recommend.models.ignore_plurals import IgnorePlurals
33+
from algoliasearch.recommend.models.inside_bounding_box import InsideBoundingBox
3334
from algoliasearch.recommend.models.numeric_filters import NumericFilters
3435
from algoliasearch.recommend.models.optional_filters import OptionalFilters
36+
from algoliasearch.recommend.models.optional_words import OptionalWords
3537
from algoliasearch.recommend.models.query_type import QueryType
3638
from algoliasearch.recommend.models.re_ranking_apply_filter import ReRankingApplyFilter
3739
from algoliasearch.recommend.models.remove_stop_words import RemoveStopWords
@@ -90,6 +92,7 @@
9092
"user_data": "userData",
9193
"custom_normalization": "customNormalization",
9294
"attribute_for_distinct": "attributeForDistinct",
95+
"max_facet_hits": "maxFacetHits",
9396
"attributes_to_retrieve": "attributesToRetrieve",
9497
"ranking": "ranking",
9598
"relevancy_strictness": "relevancyStrictness",
@@ -122,7 +125,6 @@
122125
"replace_synonyms_in_highlight": "replaceSynonymsInHighlight",
123126
"min_proximity": "minProximity",
124127
"response_fields": "responseFields",
125-
"max_facet_hits": "maxFacetHits",
126128
"max_values_per_facet": "maxValuesPerFacet",
127129
"sort_facet_values_by": "sortFacetValuesBy",
128130
"attribute_criteria_computed_by_min_proximity": "attributeCriteriaComputedByMinProximity",
@@ -165,8 +167,7 @@ class FallbackParams(BaseModel):
165167
around_precision: Optional[AroundPrecision] = None
166168
minimum_around_radius: Optional[int] = None
167169
""" Minimum radius (in meters) for a search around a location when `aroundRadius` isn't set. """
168-
inside_bounding_box: Optional[List[List[float]]] = None
169-
""" Coordinates for a rectangular area in which to search. Each bounding box is defined by the two opposite points of its diagonal, and expressed as latitude and longitude pair: `[p1 lat, p1 long, p2 lat, p2 long]`. Provide multiple bounding boxes as nested arrays. For more information, see [rectangular area](https://www.algolia.com/doc/guides/managing-results/refine-results/geolocation/#filtering-inside-rectangular-or-polygonal-areas). """
170+
inside_bounding_box: Optional[InsideBoundingBox] = None
170171
inside_polygon: Optional[List[List[float]]] = None
171172
""" Coordinates of a polygon in which to search. Polygons are defined by 3 to 10,000 points. Each point is represented by its latitude and longitude. Provide multiple polygons as nested arrays. For more information, see [filtering inside polygons](https://www.algolia.com/doc/guides/managing-results/refine-results/geolocation/#filtering-inside-rectangular-or-polygonal-areas). This parameter is ignored if you also specify `insideBoundingBox`. """
172173
natural_languages: Optional[List[SupportedLanguage]] = None
@@ -227,6 +228,8 @@ class FallbackParams(BaseModel):
227228
""" Characters and their normalized replacements. This overrides Algolia's default [normalization](https://www.algolia.com/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/normalization/). """
228229
attribute_for_distinct: Optional[str] = None
229230
""" Attribute that should be used to establish groups of results. Attribute names are case-sensitive. All records with the same value for this attribute are considered a group. You can combine `attributeForDistinct` with the `distinct` search parameter to control how many items per group are included in the search results. If you want to use the same attribute also for faceting, use the `afterDistinct` modifier of the `attributesForFaceting` setting. This applies faceting _after_ deduplication, which will result in accurate facet counts. """
231+
max_facet_hits: Optional[int] = None
232+
""" Maximum number of facet values to return when [searching for facet values](https://www.algolia.com/doc/guides/managing-results/refine-results/faceting/#search-for-facet-values). """
230233
attributes_to_retrieve: Optional[List[str]] = None
231234
""" Attributes to include in the API response. To reduce the size of your response, you can retrieve only some of the attributes. Attribute names are case-sensitive. - `*` retrieves all attributes, except attributes included in the `customRanking` and `unretrievableAttributes` settings. - To retrieve all attributes except a specific one, prefix the attribute with a dash and combine it with the `*`: `[\"*\", \"-ATTRIBUTE\"]`. - The `objectID` attribute is always included. """
232235
ranking: Optional[List[str]] = None
@@ -268,8 +271,7 @@ class FallbackParams(BaseModel):
268271
remove_words_if_no_results: Optional[RemoveWordsIfNoResults] = None
269272
advanced_syntax: Optional[bool] = None
270273
""" Whether to support phrase matching and excluding words from search queries. Use the `advancedSyntaxFeatures` parameter to control which feature is supported. """
271-
optional_words: Optional[List[str]] = None
272-
""" Words that should be considered optional when found in the query. By default, records must match all words in the search query to be included in the search results. Adding optional words can help to increase the number of search results by running an additional search query that doesn't include the optional words. For example, if the search query is \"action video\" and \"video\" is an optional word, the search engine runs two queries. One for \"action video\" and one for \"action\". Records that match all words are ranked higher. For a search query with 4 or more words **and** all its words are optional, the number of matched words required for a record to be included in the search results increases for every 1,000 records: - If `optionalWords` has less than 10 words, the required number of matched words increases by 1: results 1 to 1,000 require 1 matched word, results 1,001 to 2000 need 2 matched words. - If `optionalWords` has 10 or more words, the number of required matched words increases by the number of optional words divided by 5 (rounded down). For example, with 18 optional words: results 1 to 1,000 require 1 matched word, results 1,001 to 2000 need 4 matched words. For more information, see [Optional words](https://www.algolia.com/doc/guides/managing-results/optimize-search-results/empty-or-insufficient-results/#creating-a-list-of-optional-words). """
274+
optional_words: Optional[OptionalWords] = None
273275
disable_exact_on_attributes: Optional[List[str]] = None
274276
""" Searchable attributes for which you want to [turn off the Exact ranking criterion](https://www.algolia.com/doc/guides/managing-results/optimize-search-results/override-search-engine-defaults/in-depth/adjust-exact-settings/#turn-off-exact-for-some-attributes). Attribute names are case-sensitive. This can be useful for attributes with long values, where the likelihood of an exact match is high, such as product descriptions. Turning off the Exact ranking criterion for these attributes favors exact matching on other attributes. This reduces the impact of individual attributes with a lot of content on ranking. """
275277
exact_on_single_word_query: Optional[ExactOnSingleWordQuery] = None
@@ -284,8 +286,6 @@ class FallbackParams(BaseModel):
284286
""" Minimum proximity score for two matching words. This adjusts the [Proximity ranking criterion](https://www.algolia.com/doc/guides/managing-results/relevance-overview/in-depth/ranking-criteria/#proximity) by equally scoring matches that are farther apart. For example, if `minProximity` is 2, neighboring matches and matches with one word between them would have the same score. """
285287
response_fields: Optional[List[str]] = None
286288
""" Properties to include in the API response of `search` and `browse` requests. By default, all response properties are included. To reduce the response size, you can select, which attributes should be included. You can't exclude these properties: `message`, `warning`, `cursor`, `serverUsed`, `indexUsed`, `abTestVariantID`, `parsedQuery`, or any property triggered by the `getRankingInfo` parameter. Don't exclude properties that you might need in your search UI. """
287-
max_facet_hits: Optional[int] = None
288-
""" Maximum number of facet values to return when [searching for facet values](https://www.algolia.com/doc/guides/managing-results/refine-results/faceting/#search-for-facet-values). """
289289
max_values_per_facet: Optional[int] = None
290290
""" Maximum number of facet values to return for each facet. """
291291
sort_facet_values_by: Optional[str] = None
@@ -360,6 +360,11 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
360360
if obj.get("aroundPrecision") is not None
361361
else None
362362
)
363+
obj["insideBoundingBox"] = (
364+
InsideBoundingBox.from_dict(obj["insideBoundingBox"])
365+
if obj.get("insideBoundingBox") is not None
366+
else None
367+
)
363368
obj["naturalLanguages"] = obj.get("naturalLanguages")
364369
obj["indexLanguages"] = obj.get("indexLanguages")
365370
obj["typoTolerance"] = (
@@ -380,6 +385,11 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
380385
obj["queryLanguages"] = obj.get("queryLanguages")
381386
obj["queryType"] = obj.get("queryType")
382387
obj["removeWordsIfNoResults"] = obj.get("removeWordsIfNoResults")
388+
obj["optionalWords"] = (
389+
OptionalWords.from_dict(obj["optionalWords"])
390+
if obj.get("optionalWords") is not None
391+
else None
392+
)
383393
obj["exactOnSingleWordQuery"] = obj.get("exactOnSingleWordQuery")
384394
obj["alternativesAsExact"] = obj.get("alternativesAsExact")
385395
obj["advancedSyntaxFeatures"] = obj.get("advancedSyntaxFeatures")
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# coding: utf-8
2+
3+
"""
4+
Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
5+
"""
6+
7+
from __future__ import annotations
8+
9+
from json import dumps, loads
10+
from sys import version_info
11+
from typing import Any, Dict, List, Optional, Set, Union
12+
13+
from pydantic import BaseModel, Field, ValidationError, model_serializer
14+
15+
if version_info >= (3, 11):
16+
from typing import Self
17+
else:
18+
from typing_extensions import Self
19+
20+
21+
class InsideBoundingBox(BaseModel):
22+
"""
23+
InsideBoundingBox
24+
"""
25+
26+
oneof_schema_1_validator: Optional[str] = Field(default=None)
27+
28+
oneof_schema_2_validator: Optional[List[List[float]]] = Field(default=None)
29+
""" Coordinates for a rectangular area in which to search. Each bounding box is defined by the two opposite points of its diagonal, and expressed as latitude and longitude pair: `[p1 lat, p1 long, p2 lat, p2 long]`. Provide multiple bounding boxes as nested arrays. For more information, see [rectangular area](https://www.algolia.com/doc/guides/managing-results/refine-results/geolocation/#filtering-inside-rectangular-or-polygonal-areas). """
30+
actual_instance: Union[List[List[float]], str, None] = None
31+
one_of_schemas: Set[str] = {"List[List[float]]", "str"}
32+
33+
def __init__(self, *args, **kwargs) -> None:
34+
if args:
35+
if len(args) > 1:
36+
raise ValueError(
37+
"If a position argument is used, only 1 is allowed to set `actual_instance`"
38+
)
39+
if kwargs:
40+
raise ValueError(
41+
"If a position argument is used, keyword arguments cannot be used."
42+
)
43+
super().__init__(actual_instance=args[0]) # pyright: ignore
44+
else:
45+
super().__init__(**kwargs)
46+
47+
@model_serializer
48+
def unwrap_actual_instance(self) -> Union[List[List[float]], str, Self, None]:
49+
"""
50+
Unwraps the `actual_instance` when calling the `to_json` method.
51+
"""
52+
return self.actual_instance if hasattr(self, "actual_instance") else self
53+
54+
@classmethod
55+
def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self:
56+
"""Create an instance of InsideBoundingBox from a JSON string"""
57+
return cls.from_json(dumps(obj))
58+
59+
@classmethod
60+
def from_json(cls, json_str: Optional[str]) -> Self:
61+
"""Returns the object represented by the json string"""
62+
instance = cls.model_construct()
63+
if json_str is None:
64+
return instance
65+
66+
error_messages = []
67+
68+
try:
69+
instance.oneof_schema_1_validator = loads(json_str)
70+
instance.actual_instance = instance.oneof_schema_1_validator
71+
72+
return instance
73+
except (ValidationError, ValueError) as e:
74+
error_messages.append(str(e))
75+
try:
76+
instance.oneof_schema_2_validator = loads(json_str)
77+
instance.actual_instance = instance.oneof_schema_2_validator
78+
79+
return instance
80+
except (ValidationError, ValueError) as e:
81+
error_messages.append(str(e))
82+
83+
raise ValueError(
84+
"No match found when deserializing the JSON string into InsideBoundingBox with oneOf schemas: List[List[float]], str. Details: "
85+
+ ", ".join(error_messages)
86+
)
87+
88+
def to_json(self) -> str:
89+
"""Returns the JSON representation of the actual instance"""
90+
if self.actual_instance is None:
91+
return "null"
92+
93+
if hasattr(self.actual_instance, "to_json") and callable(
94+
self.actual_instance.to_json # pyright: ignore
95+
):
96+
return self.actual_instance.to_json() # pyright: ignore
97+
else:
98+
return dumps(self.actual_instance)
99+
100+
def to_dict(self) -> Optional[Union[Dict[str, Any], List[List[float]], str]]:
101+
"""Returns the dict representation of the actual instance"""
102+
if self.actual_instance is None:
103+
return None
104+
105+
if hasattr(self.actual_instance, "to_dict") and callable(
106+
self.actual_instance.to_dict # pyright: ignore
107+
):
108+
return self.actual_instance.to_dict() # pyright: ignore
109+
else:
110+
return self.actual_instance # pyright: ignore
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# coding: utf-8
2+
3+
"""
4+
Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
5+
"""
6+
7+
from __future__ import annotations
8+
9+
from json import dumps, loads
10+
from sys import version_info
11+
from typing import Any, Dict, List, Optional, Set, Union
12+
13+
from pydantic import BaseModel, Field, ValidationError, model_serializer
14+
15+
if version_info >= (3, 11):
16+
from typing import Self
17+
else:
18+
from typing_extensions import Self
19+
20+
21+
class OptionalWords(BaseModel):
22+
"""
23+
OptionalWords
24+
"""
25+
26+
oneof_schema_1_validator: Optional[str] = Field(default=None)
27+
28+
oneof_schema_2_validator: Optional[List[str]] = Field(default=None)
29+
""" Words that should be considered optional when found in the query. By default, records must match all words in the search query to be included in the search results. Adding optional words can help to increase the number of search results by running an additional search query that doesn't include the optional words. For example, if the search query is \"action video\" and \"video\" is an optional word, the search engine runs two queries. One for \"action video\" and one for \"action\". Records that match all words are ranked higher. For a search query with 4 or more words **and** all its words are optional, the number of matched words required for a record to be included in the search results increases for every 1,000 records: - If `optionalWords` has less than 10 words, the required number of matched words increases by 1: results 1 to 1,000 require 1 matched word, results 1,001 to 2000 need 2 matched words. - If `optionalWords` has 10 or more words, the number of required matched words increases by the number of optional words divided by 5 (rounded down). For example, with 18 optional words: results 1 to 1,000 require 1 matched word, results 1,001 to 2000 need 4 matched words. For more information, see [Optional words](https://www.algolia.com/doc/guides/managing-results/optimize-search-results/empty-or-insufficient-results/#creating-a-list-of-optional-words). """
30+
actual_instance: Union[List[str], str, None] = None
31+
one_of_schemas: Set[str] = {"List[str]", "str"}
32+
33+
def __init__(self, *args, **kwargs) -> None:
34+
if args:
35+
if len(args) > 1:
36+
raise ValueError(
37+
"If a position argument is used, only 1 is allowed to set `actual_instance`"
38+
)
39+
if kwargs:
40+
raise ValueError(
41+
"If a position argument is used, keyword arguments cannot be used."
42+
)
43+
super().__init__(actual_instance=args[0]) # pyright: ignore
44+
else:
45+
super().__init__(**kwargs)
46+
47+
@model_serializer
48+
def unwrap_actual_instance(self) -> Union[List[str], str, Self, None]:
49+
"""
50+
Unwraps the `actual_instance` when calling the `to_json` method.
51+
"""
52+
return self.actual_instance if hasattr(self, "actual_instance") else self
53+
54+
@classmethod
55+
def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self:
56+
"""Create an instance of OptionalWords from a JSON string"""
57+
return cls.from_json(dumps(obj))
58+
59+
@classmethod
60+
def from_json(cls, json_str: Optional[str]) -> Self:
61+
"""Returns the object represented by the json string"""
62+
instance = cls.model_construct()
63+
if json_str is None:
64+
return instance
65+
66+
error_messages = []
67+
68+
try:
69+
instance.oneof_schema_1_validator = loads(json_str)
70+
instance.actual_instance = instance.oneof_schema_1_validator
71+
72+
return instance
73+
except (ValidationError, ValueError) as e:
74+
error_messages.append(str(e))
75+
try:
76+
instance.oneof_schema_2_validator = loads(json_str)
77+
instance.actual_instance = instance.oneof_schema_2_validator
78+
79+
return instance
80+
except (ValidationError, ValueError) as e:
81+
error_messages.append(str(e))
82+
83+
raise ValueError(
84+
"No match found when deserializing the JSON string into OptionalWords with oneOf schemas: List[str], str. Details: "
85+
+ ", ".join(error_messages)
86+
)
87+
88+
def to_json(self) -> str:
89+
"""Returns the JSON representation of the actual instance"""
90+
if self.actual_instance is None:
91+
return "null"
92+
93+
if hasattr(self.actual_instance, "to_json") and callable(
94+
self.actual_instance.to_json # pyright: ignore
95+
):
96+
return self.actual_instance.to_json() # pyright: ignore
97+
else:
98+
return dumps(self.actual_instance)
99+
100+
def to_dict(self) -> Optional[Union[Dict[str, Any], List[str], str]]:
101+
"""Returns the dict representation of the actual instance"""
102+
if self.actual_instance is None:
103+
return None
104+
105+
if hasattr(self.actual_instance, "to_dict") and callable(
106+
self.actual_instance.to_dict # pyright: ignore
107+
):
108+
return self.actual_instance.to_dict() # pyright: ignore
109+
else:
110+
return self.actual_instance # pyright: ignore

0 commit comments

Comments
 (0)