Skip to content

Commit 04b9b15

Browse files
authored
Merge 966cba2 into 880dc38
2 parents 880dc38 + 966cba2 commit 04b9b15

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed

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)