Skip to content

Commit 6a9477f

Browse files
authored
Merge branch 'main' into fix/specs-ingestion-custom-timeout-endpoint
2 parents 9e8cb3f + b957077 commit 6a9477f

File tree

6 files changed

+84
-31
lines changed

6 files changed

+84
-31
lines changed

clients/algoliasearch-client-python/algoliasearch/search/client.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,9 @@ async def browse_objects(
354354
"""
355355
Helper: Iterate on the `browse` method of the client to allow aggregating objects of an index.
356356
"""
357+
if isinstance(browse_params, dict):
358+
browse_params = BrowseParamsObject().from_dict(browse_params)
359+
357360
if browse_params is None:
358361
browse_params = BrowseParamsObject(hits_per_page=1000)
359362

@@ -385,6 +388,9 @@ async def browse_rules(
385388
"""
386389
Helper: Iterate on the `search_rules` method of the client to allow aggregating rules of an index.
387390
"""
391+
if isinstance(search_rules_params, dict):
392+
search_rules_params = SearchRulesParams().from_dict(search_rules_params)
393+
388394
if search_rules_params is None:
389395
search_rules_params = SearchRulesParams(hits_per_page=1000)
390396

@@ -418,6 +424,11 @@ async def browse_synonyms(
418424
"""
419425
Helper: Iterate on the `search_synonyms` method of the client to allow aggregating synonyms of an index.
420426
"""
427+
if isinstance(search_synonyms_params, dict):
428+
search_synonyms_params = SearchSynonymsParams().from_dict(
429+
search_synonyms_params
430+
)
431+
421432
if search_synonyms_params is None:
422433
search_synonyms_params = SearchSynonymsParams(hits_per_page=1000, page=0)
423434
hits_per_page = 1000
@@ -453,6 +464,7 @@ async def generate_secured_api_key(
453464
"""
454465
if restrictions is None:
455466
restrictions = SecuredApiKeyRestrictions()
467+
456468
restrictions_dict = {}
457469
if isinstance(restrictions, SecuredApiKeyRestrictions):
458470
restrictions_dict = restrictions.to_dict()
@@ -5384,6 +5396,9 @@ def browse_objects(
53845396
"""
53855397
Helper: Iterate on the `browse` method of the client to allow aggregating objects of an index.
53865398
"""
5399+
if isinstance(browse_params, dict):
5400+
browse_params = BrowseParamsObject().from_dict(browse_params)
5401+
53875402
if browse_params is None:
53885403
browse_params = BrowseParamsObject(hits_per_page=1000)
53895404

@@ -5415,6 +5430,9 @@ def browse_rules(
54155430
"""
54165431
Helper: Iterate on the `search_rules` method of the client to allow aggregating rules of an index.
54175432
"""
5433+
if isinstance(search_rules_params, dict):
5434+
search_rules_params = SearchRulesParams().from_dict(search_rules_params)
5435+
54185436
if search_rules_params is None:
54195437
search_rules_params = SearchRulesParams(hits_per_page=1000)
54205438

@@ -5448,6 +5466,11 @@ def browse_synonyms(
54485466
"""
54495467
Helper: Iterate on the `search_synonyms` method of the client to allow aggregating synonyms of an index.
54505468
"""
5469+
if isinstance(search_synonyms_params, dict):
5470+
search_synonyms_params = SearchSynonymsParams().from_dict(
5471+
search_synonyms_params
5472+
)
5473+
54515474
if search_synonyms_params is None:
54525475
search_synonyms_params = SearchSynonymsParams(hits_per_page=1000, page=0)
54535476
hits_per_page = 1000
@@ -5481,6 +5504,7 @@ def generate_secured_api_key(
54815504
"""
54825505
if restrictions is None:
54835506
restrictions = SecuredApiKeyRestrictions()
5507+
54845508
restrictions_dict = {}
54855509
if isinstance(restrictions, SecuredApiKeyRestrictions):
54865510
restrictions_dict = restrictions.to_dict()

clients/algoliasearch-client-ruby/lib/algolia/api/search_client.rb

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3150,19 +3150,21 @@ def wait_for_app_task(
31503150
def wait_for_api_key(
31513151
key,
31523152
operation,
3153-
api_key = {},
3153+
api_key = Search::ApiKey.new,
31543154
max_retries = 50,
31553155
timeout = -> (retry_count) { [retry_count * 200, 5000].min },
31563156
request_options = {}
31573157
)
3158+
api_key = api_client.object_to_hash(api_key)
3159+
31583160
retries = 0
31593161
if operation == "update"
31603162
raise ArgumentError, "`api_key` is required when waiting for an `update` operation." if api_key.nil?
31613163
while retries < max_retries
31623164
updated_key = get_api_key(key, request_options)
31633165
updated_key_hash = updated_key.to_hash
31643166
equals = true
3165-
api_key.to_hash.each do |k, v|
3167+
api_key.each do |k, v|
31663168
equals &&= updated_key_hash[k] == v
31673169
end
31683170

@@ -3201,7 +3203,9 @@ def wait_for_api_key(
32013203
# @param request_options [Hash] the requestOptions to send along with the query, they will be forwarded to the `browse` method.
32023204
# @param block [Proc] the block to execute on each object of the index.
32033205
def browse_objects(index_name, browse_params = Search::BrowseParamsObject.new, request_options = {}, &block)
3204-
browse_params.hits_per_page ||= 1000
3206+
browse_params = api_client.object_to_hash(browse_params)
3207+
3208+
browse_params[:hitsPerPage] = 1000 unless browse_params.key?(:hitsPerPage)
32053209

32063210
hits = []
32073211
loop do
@@ -3214,8 +3218,8 @@ def browse_objects(index_name, browse_params = Search::BrowseParamsObject.new, r
32143218
hits.concat(res.hits)
32153219
end
32163220

3217-
browse_params.cursor = res.cursor
3218-
break if browse_params.cursor.nil?
3221+
browse_params[:cursor] = res.cursor
3222+
break if browse_params[:cursor].nil?
32193223
end
32203224

32213225
hits unless block_given?
@@ -3227,12 +3231,11 @@ def browse_objects(index_name, browse_params = Search::BrowseParamsObject.new, r
32273231
# @param search_rules_params [SearchRulesParams] the parameters to send along with the query, they will be forwarded to the `searchRules` method.
32283232
# @param request_options [Hash] the requestOptions to send along with the query, they will be forwarded to the `searchRules` method.
32293233
# @param block [Proc] the block to execute on each rule of the index.
3230-
def browse_rules(
3231-
index_name,
3232-
search_rules_params = Search::SearchRulesParams.new(hits_per_page: 1000, page: 0),
3233-
request_options = {},
3234-
&block
3235-
)
3234+
def browse_rules(index_name, search_rules_params = Search::SearchRulesParams.new, request_options = {}, &block)
3235+
search_rules_params = api_client.object_to_hash(search_rules_params)
3236+
3237+
search_rules_params[:hitsPerPage] = 1000 unless search_rules_params.key?(:hitsPerPage)
3238+
32363239
rules = []
32373240
loop do
32383241
res = search_rules(index_name, search_rules_params, request_options)
@@ -3244,8 +3247,8 @@ def browse_rules(
32443247
rules.concat(res.hits)
32453248
end
32463249

3247-
search_rules_params.page += 1
3248-
break if res.hits.length < search_rules_params.hits_per_page
3250+
search_rules_params[:page] += 1
3251+
break if res.hits.length < search_rules_params[:hitsPerPage]
32493252
end
32503253

32513254
rules unless block_given?
@@ -3259,10 +3262,14 @@ def browse_rules(
32593262
# @param block [Proc] the block to execute on each synonym of the index.
32603263
def browse_synonyms(
32613264
index_name,
3262-
search_synonyms_params = Search::SearchSynonymsParams.new(hits_per_page: 1000, page: 0),
3265+
search_synonyms_params = Search::SearchSynonymsParams.new,
32633266
request_options = {},
32643267
&block
32653268
)
3269+
search_synonyms_params = api_client.object_to_hash(search_synonyms_params)
3270+
3271+
search_synonyms_params[:hitsPerPage] = 1000 unless search_synonyms_params.key?(:hitsPerPage)
3272+
32663273
synonyms = []
32673274
loop do
32683275
res = search_synonyms(index_name, search_synonyms_params, request_options)
@@ -3274,8 +3281,8 @@ def browse_synonyms(
32743281
synonyms.concat(res.hits)
32753282
end
32763283

3277-
search_synonyms_params.page += 1
3278-
break if res.hits.length < search_synonyms_params.hits_per_page
3284+
search_synonyms_params[:page] += 1
3285+
break if res.hits.length < search_synonyms_params[:hitsPerPage]
32793286
end
32803287

32813288
synonyms unless block_given?
@@ -3543,6 +3550,5 @@ def index_exists?(index_name)
35433550

35443551
true
35453552
end
3546-
35473553
end
35483554
end

playground/ruby/Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: ../../clients/algoliasearch-client-ruby
33
specs:
4-
algolia (3.10.0)
4+
algolia (3.10.1)
55
base64 (>= 0.2.0, < 1)
66
faraday (>= 1.0.1, < 3.0)
77
faraday-net_http_persistent (>= 0.15, < 3)

playground/ruby/search.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
client = Algolia::SearchClient.create(ENV['ALGOLIA_APPLICATION_ID'], ENV['ALGOLIA_ADMIN_KEY'])
77
# set a custom user agent
88
client.add_user_agent_segment('Algolia for rails', "test")
9-
res = client.search_single_index('contacts', Algolia::Search::SearchParamsObject.new(query: 'Jimmie'))
9+
res = client.browse_objects('qigbuery-RECORDS')
1010
puts res
1111

1212
=begin

templates/python/search_helpers.mustache

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@
128128
"""
129129
Helper: Iterate on the `browse` method of the client to allow aggregating objects of an index.
130130
"""
131+
if isinstance(browse_params, dict):
132+
browse_params = BrowseParamsObject().from_dict(browse_params)
133+
131134
if browse_params is None:
132135
browse_params = BrowseParamsObject(hits_per_page=1000)
133136

@@ -159,6 +162,9 @@
159162
"""
160163
Helper: Iterate on the `search_rules` method of the client to allow aggregating rules of an index.
161164
"""
165+
if isinstance(search_rules_params, dict):
166+
search_rules_params = SearchRulesParams().from_dict(search_rules_params)
167+
162168
if search_rules_params is None:
163169
search_rules_params = SearchRulesParams(hits_per_page=1000)
164170

@@ -191,6 +197,9 @@
191197
"""
192198
Helper: Iterate on the `search_synonyms` method of the client to allow aggregating synonyms of an index.
193199
"""
200+
if isinstance(search_synonyms_params, dict):
201+
search_synonyms_params = SearchSynonymsParams().from_dict(search_synonyms_params)
202+
194203
if search_synonyms_params is None:
195204
search_synonyms_params = SearchSynonymsParams(
196205
hits_per_page=1000,
@@ -226,6 +235,7 @@
226235
"""
227236
if restrictions is None:
228237
restrictions = SecuredApiKeyRestrictions()
238+
229239
restrictions_dict = {}
230240
if isinstance(restrictions, SecuredApiKeyRestrictions):
231241
restrictions_dict = restrictions.to_dict()

templates/ruby/search_helpers.mustache

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ end
4848
# @param timeout [Proc] the function to decide how long to wait between retries.
4949
# @param request_options [Hash] the requestOptions to send along with the query, they will be forwarded to the `getApikey` method and merged with the transporter requestOptions.
5050
# @return [Http::Response] the last get_api_key response
51-
def wait_for_api_key(key, operation, api_key = {}, max_retries = 50, timeout = -> (retry_count) { [retry_count * 200, 5000].min }, request_options = {})
51+
def wait_for_api_key(key, operation, api_key = Search::ApiKey.new, max_retries = 50, timeout = -> (retry_count) { [retry_count * 200, 5000].min }, request_options = {})
52+
api_key = api_client.object_to_hash(api_key)
53+
5254
retries = 0
5355
if operation == 'update'
5456
raise ArgumentError, '`api_key` is required when waiting for an `update` operation.' if api_key.nil?
5557
while retries < max_retries
5658
updated_key = get_api_key(key, request_options)
5759
updated_key_hash = updated_key.to_hash
5860
equals = true
59-
api_key.to_hash.each do |k, v|
61+
api_key.each do |k, v|
6062
equals &&= updated_key_hash[k] == v
6163
end
6264

@@ -95,7 +97,9 @@ end
9597
# @param request_options [Hash] the requestOptions to send along with the query, they will be forwarded to the `browse` method.
9698
# @param block [Proc] the block to execute on each object of the index.
9799
def browse_objects(index_name, browse_params = Search::BrowseParamsObject.new, request_options = {}, &block)
98-
browse_params.hits_per_page ||= 1000
100+
browse_params = api_client.object_to_hash(browse_params)
101+
102+
browse_params[:hitsPerPage] = 1000 unless browse_params.key?(:hitsPerPage)
99103

100104
hits = []
101105
loop do
@@ -107,8 +111,9 @@ def browse_objects(index_name, browse_params = Search::BrowseParamsObject.new, r
107111
else
108112
hits.concat(res.hits)
109113
end
110-
browse_params.cursor = res.cursor
111-
break if browse_params.cursor.nil?
114+
115+
browse_params[:cursor] = res.cursor
116+
break if browse_params[:cursor].nil?
112117
end
113118

114119
hits unless block_given?
@@ -120,7 +125,11 @@ end
120125
# @param search_rules_params [SearchRulesParams] the parameters to send along with the query, they will be forwarded to the `searchRules` method.
121126
# @param request_options [Hash] the requestOptions to send along with the query, they will be forwarded to the `searchRules` method.
122127
# @param block [Proc] the block to execute on each rule of the index.
123-
def browse_rules(index_name, search_rules_params = Search::SearchRulesParams.new(hits_per_page: 1000, page: 0), request_options = {}, &block)
128+
def browse_rules(index_name, search_rules_params = Search::SearchRulesParams.new, request_options = {}, &block)
129+
search_rules_params = api_client.object_to_hash(search_rules_params)
130+
131+
search_rules_params[:hitsPerPage] = 1000 unless search_rules_params.key?(:hitsPerPage)
132+
124133
rules = []
125134
loop do
126135
res = search_rules(index_name, search_rules_params, request_options)
@@ -131,8 +140,8 @@ def browse_rules(index_name, search_rules_params = Search::SearchRulesParams.new
131140
else
132141
rules.concat(res.hits)
133142
end
134-
search_rules_params.page += 1
135-
break if res.hits.length < search_rules_params.hits_per_page
143+
search_rules_params[:page] += 1
144+
break if res.hits.length < search_rules_params[:hitsPerPage]
136145
end
137146

138147
rules unless block_given?
@@ -144,7 +153,11 @@ end
144153
# @param search_synonyms_params [SearchSynonymsParams] the parameters to send along with the query, they will be forwarded to the `searchSynonyms` method.
145154
# @param request_options [Hash] the requestOptions to send along with the query, they will be forwarded to the `searchSynonyms` method.
146155
# @param block [Proc] the block to execute on each synonym of the index.
147-
def browse_synonyms(index_name, search_synonyms_params = Search::SearchSynonymsParams.new(hits_per_page: 1000, page: 0), request_options = {}, &block)
156+
def browse_synonyms(index_name, search_synonyms_params = Search::SearchSynonymsParams.new, request_options = {}, &block)
157+
search_synonyms_params = api_client.object_to_hash(search_synonyms_params)
158+
159+
search_synonyms_params[:hitsPerPage] = 1000 unless search_synonyms_params.key?(:hitsPerPage)
160+
148161
synonyms = []
149162
loop do
150163
res = search_synonyms(index_name, search_synonyms_params, request_options)
@@ -155,8 +168,8 @@ def browse_synonyms(index_name, search_synonyms_params = Search::SearchSynonymsP
155168
else
156169
synonyms.concat(res.hits)
157170
end
158-
search_synonyms_params.page += 1
159-
break if res.hits.length < search_synonyms_params.hits_per_page
171+
search_synonyms_params[:page] += 1
172+
break if res.hits.length < search_synonyms_params[:hitsPerPage]
160173
end
161174

162175
synonyms unless block_given?
@@ -405,4 +418,4 @@ def index_exists?(index_name)
405418
end
406419

407420
true
408-
end
421+
end

0 commit comments

Comments
 (0)