Skip to content

Commit fea1cae

Browse files
committed
fix: ruby
1 parent fff5766 commit fea1cae

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

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.browse_objects('qigbuery-RECORDS', {})
9+
res = client.browse_objects('qigbuery-RECORDS')
1010
puts res
1111

1212
=begin

templates/ruby/search_helpers.mustache

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ end
9595
# @param request_options [Hash] the requestOptions to send along with the query, they will be forwarded to the `browse` method.
9696
# @param block [Proc] the block to execute on each object of the index.
9797
def browse_objects(index_name, browse_params = Search::BrowseParamsObject.new, request_options = {}, &block)
98-
browse_params.hits_per_page ||= 1000
98+
browse_params = api_client.object_to_hash(browse_params)
99+
100+
browse_params[:hitsPerPage] = 1000 unless browse_params.key?(:hitsPerPage)
99101

100102
hits = []
101103
loop do
@@ -107,8 +109,9 @@ def browse_objects(index_name, browse_params = Search::BrowseParamsObject.new, r
107109
else
108110
hits.concat(res.hits)
109111
end
110-
browse_params.cursor = res.cursor
111-
break if browse_params.cursor.nil?
112+
113+
browse_params[:cursor] = res.cursor
114+
break if browse_params[:cursor].nil?
112115
end
113116

114117
hits unless block_given?
@@ -120,7 +123,11 @@ end
120123
# @param search_rules_params [SearchRulesParams] the parameters to send along with the query, they will be forwarded to the `searchRules` method.
121124
# @param request_options [Hash] the requestOptions to send along with the query, they will be forwarded to the `searchRules` method.
122125
# @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)
126+
def browse_rules(index_name, search_rules_params = Search::SearchRulesParams.new, request_options = {}, &block)
127+
search_rules_params = api_client.object_to_hash(search_rules_params)
128+
129+
search_rules_params[:hitsPerPage] = 1000 unless search_rules_params.key?(:hitsPerPage)
130+
124131
rules = []
125132
loop do
126133
res = search_rules(index_name, search_rules_params, request_options)
@@ -131,8 +138,8 @@ def browse_rules(index_name, search_rules_params = Search::SearchRulesParams.new
131138
else
132139
rules.concat(res.hits)
133140
end
134-
search_rules_params.page += 1
135-
break if res.hits.length < search_rules_params.hits_per_page
141+
search_rules_params[:page] += 1
142+
break if res.hits.length < search_rules_params[:hitsPerPage]
136143
end
137144

138145
rules unless block_given?
@@ -144,7 +151,11 @@ end
144151
# @param search_synonyms_params [SearchSynonymsParams] the parameters to send along with the query, they will be forwarded to the `searchSynonyms` method.
145152
# @param request_options [Hash] the requestOptions to send along with the query, they will be forwarded to the `searchSynonyms` method.
146153
# @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)
154+
def browse_synonyms(index_name, search_synonyms_params = Search::SearchSynonymsParams.new, request_options = {}, &block)
155+
search_synonyms_params = api_client.object_to_hash(search_synonyms_params)
156+
157+
search_synonyms_params[:hitsPerPage] = 1000 unless search_synonyms_params.key?(:hitsPerPage)
158+
148159
synonyms = []
149160
loop do
150161
res = search_synonyms(index_name, search_synonyms_params, request_options)
@@ -155,8 +166,8 @@ def browse_synonyms(index_name, search_synonyms_params = Search::SearchSynonymsP
155166
else
156167
synonyms.concat(res.hits)
157168
end
158-
search_synonyms_params.page += 1
159-
break if res.hits.length < search_synonyms_params.hits_per_page
169+
search_synonyms_params[:page] += 1
170+
break if res.hits.length < search_synonyms_params[:hitsPerPage]
160171
end
161172

162173
synonyms unless block_given?
@@ -405,4 +416,4 @@ def index_exists?(index_name)
405416
end
406417

407418
true
408-
end
419+
end

0 commit comments

Comments
 (0)