Skip to content

Commit c22c7c7

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 72293fb commit c22c7c7

14 files changed

+558
-194
lines changed

lib/algolia/models/recommend/fallback_params.rb

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class FallbackParams
4545
# Minimum radius (in meters) for a search around a location when `aroundRadius` isn't set.
4646
attr_accessor :minimum_around_radius
4747

48-
# 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).
4948
attr_accessor :inside_bounding_box
5049

5150
# 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`.
@@ -138,6 +137,9 @@ class FallbackParams
138137
# 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.
139138
attr_accessor :attribute_for_distinct
140139

140+
# 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).
141+
attr_accessor :max_facet_hits
142+
141143
# 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.
142144
attr_accessor :attributes_to_retrieve
143145

@@ -202,7 +204,6 @@ class FallbackParams
202204
# Whether to support phrase matching and excluding words from search queries. Use the `advancedSyntaxFeatures` parameter to control which feature is supported.
203205
attr_accessor :advanced_syntax
204206

205-
# 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).
206207
attr_accessor :optional_words
207208

208209
# 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.
@@ -227,9 +228,6 @@ class FallbackParams
227228
# 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.
228229
attr_accessor :response_fields
229230

230-
# 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).
231-
attr_accessor :max_facet_hits
232-
233231
# Maximum number of facet values to return for each facet.
234232
attr_accessor :max_values_per_facet
235233

@@ -295,6 +293,7 @@ def self.attribute_map
295293
:user_data => :userData,
296294
:custom_normalization => :customNormalization,
297295
:attribute_for_distinct => :attributeForDistinct,
296+
:max_facet_hits => :maxFacetHits,
298297
:attributes_to_retrieve => :attributesToRetrieve,
299298
:ranking => :ranking,
300299
:relevancy_strictness => :relevancyStrictness,
@@ -327,7 +326,6 @@ def self.attribute_map
327326
:replace_synonyms_in_highlight => :replaceSynonymsInHighlight,
328327
:min_proximity => :minProximity,
329328
:response_fields => :responseFields,
330-
:max_facet_hits => :maxFacetHits,
331329
:max_values_per_facet => :maxValuesPerFacet,
332330
:sort_facet_values_by => :sortFacetValuesBy,
333331
:attribute_criteria_computed_by_min_proximity => :attributeCriteriaComputedByMinProximity,
@@ -360,7 +358,7 @@ def self.types_mapping
360358
:around_radius => :"AroundRadius",
361359
:around_precision => :"AroundPrecision",
362360
:minimum_around_radius => :"Integer",
363-
:inside_bounding_box => :"Array<Array<Float>>",
361+
:inside_bounding_box => :"InsideBoundingBox",
364362
:inside_polygon => :"Array<Array<Float>>",
365363
:natural_languages => :"Array<SupportedLanguage>",
366364
:rule_contexts => :"Array<String>",
@@ -391,6 +389,7 @@ def self.types_mapping
391389
:user_data => :"Object",
392390
:custom_normalization => :"Hash<String, Hash<String, String>>",
393391
:attribute_for_distinct => :"String",
392+
:max_facet_hits => :"Integer",
394393
:attributes_to_retrieve => :"Array<String>",
395394
:ranking => :"Array<String>",
396395
:relevancy_strictness => :"Integer",
@@ -414,7 +413,7 @@ def self.types_mapping
414413
:query_type => :"QueryType",
415414
:remove_words_if_no_results => :"RemoveWordsIfNoResults",
416415
:advanced_syntax => :"Boolean",
417-
:optional_words => :"Array<String>",
416+
:optional_words => :"OptionalWords",
418417
:disable_exact_on_attributes => :"Array<String>",
419418
:exact_on_single_word_query => :"ExactOnSingleWordQuery",
420419
:alternatives_as_exact => :"Array<AlternativesAsExact>",
@@ -423,7 +422,6 @@ def self.types_mapping
423422
:replace_synonyms_in_highlight => :"Boolean",
424423
:min_proximity => :"Integer",
425424
:response_fields => :"Array<String>",
426-
:max_facet_hits => :"Integer",
427425
:max_values_per_facet => :"Integer",
428426
:sort_facet_values_by => :"String",
429427
:attribute_criteria_computed_by_min_proximity => :"Boolean",
@@ -436,7 +434,10 @@ def self.types_mapping
436434
# List of attributes with nullable: true
437435
def self.openapi_nullable
438436
Set.new(
439-
[]
437+
[
438+
:inside_bounding_box,
439+
:optional_words
440+
]
440441
)
441442
end
442443

@@ -535,9 +536,7 @@ def initialize(attributes = {})
535536
end
536537

537538
if attributes.key?(:inside_bounding_box)
538-
if (value = attributes[:inside_bounding_box]).is_a?(Array)
539-
self.inside_bounding_box = value
540-
end
539+
self.inside_bounding_box = attributes[:inside_bounding_box]
541540
end
542541

543542
if attributes.key?(:inside_polygon)
@@ -690,6 +689,10 @@ def initialize(attributes = {})
690689
self.attribute_for_distinct = attributes[:attribute_for_distinct]
691690
end
692691

692+
if attributes.key?(:max_facet_hits)
693+
self.max_facet_hits = attributes[:max_facet_hits]
694+
end
695+
693696
if attributes.key?(:attributes_to_retrieve)
694697
if (value = attributes[:attributes_to_retrieve]).is_a?(Array)
695698
self.attributes_to_retrieve = value
@@ -795,9 +798,7 @@ def initialize(attributes = {})
795798
end
796799

797800
if attributes.key?(:optional_words)
798-
if (value = attributes[:optional_words]).is_a?(Array)
799-
self.optional_words = value
800-
end
801+
self.optional_words = attributes[:optional_words]
801802
end
802803

803804
if attributes.key?(:disable_exact_on_attributes)
@@ -840,10 +841,6 @@ def initialize(attributes = {})
840841
end
841842
end
842843

843-
if attributes.key?(:max_facet_hits)
844-
self.max_facet_hits = attributes[:max_facet_hits]
845-
end
846-
847844
if attributes.key?(:max_values_per_facet)
848845
self.max_values_per_facet = attributes[:max_values_per_facet]
849846
end
@@ -920,6 +917,7 @@ def ==(other)
920917
user_data == other.user_data &&
921918
custom_normalization == other.custom_normalization &&
922919
attribute_for_distinct == other.attribute_for_distinct &&
920+
max_facet_hits == other.max_facet_hits &&
923921
attributes_to_retrieve == other.attributes_to_retrieve &&
924922
ranking == other.ranking &&
925923
relevancy_strictness == other.relevancy_strictness &&
@@ -952,7 +950,6 @@ def ==(other)
952950
replace_synonyms_in_highlight == other.replace_synonyms_in_highlight &&
953951
min_proximity == other.min_proximity &&
954952
response_fields == other.response_fields &&
955-
max_facet_hits == other.max_facet_hits &&
956953
max_values_per_facet == other.max_values_per_facet &&
957954
sort_facet_values_by == other.sort_facet_values_by &&
958955
attribute_criteria_computed_by_min_proximity == other.attribute_criteria_computed_by_min_proximity &&
@@ -1017,6 +1014,7 @@ def hash
10171014
user_data,
10181015
custom_normalization,
10191016
attribute_for_distinct,
1017+
max_facet_hits,
10201018
attributes_to_retrieve,
10211019
ranking,
10221020
relevancy_strictness,
@@ -1049,7 +1047,6 @@ def hash
10491047
replace_synonyms_in_highlight,
10501048
min_proximity,
10511049
response_fields,
1052-
max_facet_hits,
10531050
max_values_per_facet,
10541051
sort_facet_values_by,
10551052
attribute_criteria_computed_by_min_proximity,
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# 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.
2+
3+
require "date"
4+
require "time"
5+
6+
module Algolia
7+
module Recommend
8+
module InsideBoundingBox
9+
class << self
10+
# List of class defined in oneOf (OpenAPI v3)
11+
def openapi_one_of
12+
[
13+
:"Array<Array<Float>>",
14+
:"String"
15+
]
16+
end
17+
18+
# Builds the object
19+
# @param [Mixed] Data to be matched against the list of oneOf items
20+
# @return [Object] Returns the model or the data itself
21+
def build(data)
22+
# Go through the list of oneOf items and attempt to identify the appropriate one.
23+
# Note:
24+
# - We do not attempt to check whether exactly one item matches.
25+
# - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
26+
# due to the way the deserialization is made in the base_object template (it just casts without verifying).
27+
# - TODO: scalar values are de facto behaving as if they were nullable.
28+
# - TODO: logging when debugging is set.
29+
openapi_one_of.each do |klass|
30+
begin
31+
# "nullable: true"
32+
next if klass == :AnyType
33+
typed_data = find_and_cast_into_type(klass, data)
34+
return typed_data if typed_data
35+
# rescue all errors so we keep iterating even if the current item lookup raises
36+
rescue
37+
end
38+
end
39+
40+
openapi_one_of.include?(:AnyType) ? data : nil
41+
end
42+
43+
private
44+
45+
SchemaMismatchError = Class.new(StandardError)
46+
47+
# Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
48+
def find_and_cast_into_type(klass, data)
49+
return if data.nil?
50+
51+
case klass.to_s
52+
when "Boolean"
53+
return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
54+
when "Float"
55+
return data if data.instance_of?(Float)
56+
when "Integer"
57+
return data if data.instance_of?(Integer)
58+
when "Time"
59+
return Time.parse(data)
60+
when "Date"
61+
return Date.parse(data)
62+
when "String"
63+
return data if data.instance_of?(String)
64+
# "type: object"
65+
when "Object"
66+
return data if data.instance_of?(Hash)
67+
# "type: array"
68+
when /\AArray<(?<sub_type>.+)>\z/
69+
if data.instance_of?(Array)
70+
sub_type = Regexp.last_match[:sub_type]
71+
return data.map { |item| find_and_cast_into_type(sub_type, item) }
72+
end
73+
# "type: object" with "additionalProperties: { ... }"
74+
when /\AHash<String, (?<sub_type>.+)>\z/
75+
if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
76+
sub_type = Regexp.last_match[:sub_type]
77+
return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
78+
end
79+
# model
80+
else
81+
const = Algolia::Recommend.const_get(klass)
82+
if const
83+
if const.respond_to?(:openapi_one_of)
84+
# nested oneOf model
85+
model = const.build(data)
86+
elsif const.respond_to?(:acceptable_attributes)
87+
# raise if data contains keys that are not known to the model
88+
raise unless (data.keys - const.acceptable_attributes).empty?
89+
model = const.build_from_hash(data)
90+
else
91+
# maybe it's an enum
92+
model = const.build_from_hash(data)
93+
end
94+
95+
return model if model
96+
end
97+
end
98+
99+
# if no match by now, raise
100+
raise
101+
rescue
102+
raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
103+
end
104+
end
105+
end
106+
107+
end
108+
end
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# 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.
2+
3+
require "date"
4+
require "time"
5+
6+
module Algolia
7+
module Recommend
8+
module OptionalWords
9+
class << self
10+
# List of class defined in oneOf (OpenAPI v3)
11+
def openapi_one_of
12+
[
13+
:"Array<String>",
14+
:"String"
15+
]
16+
end
17+
18+
# Builds the object
19+
# @param [Mixed] Data to be matched against the list of oneOf items
20+
# @return [Object] Returns the model or the data itself
21+
def build(data)
22+
# Go through the list of oneOf items and attempt to identify the appropriate one.
23+
# Note:
24+
# - We do not attempt to check whether exactly one item matches.
25+
# - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
26+
# due to the way the deserialization is made in the base_object template (it just casts without verifying).
27+
# - TODO: scalar values are de facto behaving as if they were nullable.
28+
# - TODO: logging when debugging is set.
29+
openapi_one_of.each do |klass|
30+
begin
31+
# "nullable: true"
32+
next if klass == :AnyType
33+
typed_data = find_and_cast_into_type(klass, data)
34+
return typed_data if typed_data
35+
# rescue all errors so we keep iterating even if the current item lookup raises
36+
rescue
37+
end
38+
end
39+
40+
openapi_one_of.include?(:AnyType) ? data : nil
41+
end
42+
43+
private
44+
45+
SchemaMismatchError = Class.new(StandardError)
46+
47+
# Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
48+
def find_and_cast_into_type(klass, data)
49+
return if data.nil?
50+
51+
case klass.to_s
52+
when "Boolean"
53+
return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
54+
when "Float"
55+
return data if data.instance_of?(Float)
56+
when "Integer"
57+
return data if data.instance_of?(Integer)
58+
when "Time"
59+
return Time.parse(data)
60+
when "Date"
61+
return Date.parse(data)
62+
when "String"
63+
return data if data.instance_of?(String)
64+
# "type: object"
65+
when "Object"
66+
return data if data.instance_of?(Hash)
67+
# "type: array"
68+
when /\AArray<(?<sub_type>.+)>\z/
69+
if data.instance_of?(Array)
70+
sub_type = Regexp.last_match[:sub_type]
71+
return data.map { |item| find_and_cast_into_type(sub_type, item) }
72+
end
73+
# "type: object" with "additionalProperties: { ... }"
74+
when /\AHash<String, (?<sub_type>.+)>\z/
75+
if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
76+
sub_type = Regexp.last_match[:sub_type]
77+
return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
78+
end
79+
# model
80+
else
81+
const = Algolia::Recommend.const_get(klass)
82+
if const
83+
if const.respond_to?(:openapi_one_of)
84+
# nested oneOf model
85+
model = const.build(data)
86+
elsif const.respond_to?(:acceptable_attributes)
87+
# raise if data contains keys that are not known to the model
88+
raise unless (data.keys - const.acceptable_attributes).empty?
89+
model = const.build_from_hash(data)
90+
else
91+
# maybe it's an enum
92+
model = const.build_from_hash(data)
93+
end
94+
95+
return model if model
96+
end
97+
end
98+
99+
# if no match by now, raise
100+
raise
101+
rescue
102+
raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
103+
end
104+
end
105+
end
106+
107+
end
108+
end

0 commit comments

Comments
 (0)