95
95
# @param request_options [Hash] the requestOptions to send along with the query, they will be forwarded to the `browse` method.
96
96
# @param block [Proc] the block to execute on each object of the index.
97
97
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)
99
101
100
102
hits = []
101
103
loop do
@@ -107,8 +109,9 @@ def browse_objects(index_name, browse_params = Search::BrowseParamsObject.new, r
107
109
else
108
110
hits.concat(res.hits)
109
111
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?
112
115
end
113
116
114
117
hits unless block_given?
120
123
# @param search_rules_params [SearchRulesParams] the parameters to send along with the query, they will be forwarded to the `searchRules` method.
121
124
# @param request_options [Hash] the requestOptions to send along with the query, they will be forwarded to the `searchRules` method.
122
125
# @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
+
124
131
rules = []
125
132
loop do
126
133
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
131
138
else
132
139
rules.concat(res.hits)
133
140
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]
136
143
end
137
144
138
145
rules unless block_given?
144
151
# @param search_synonyms_params [SearchSynonymsParams] the parameters to send along with the query, they will be forwarded to the `searchSynonyms` method.
145
152
# @param request_options [Hash] the requestOptions to send along with the query, they will be forwarded to the `searchSynonyms` method.
146
153
# @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
+
148
159
synonyms = []
149
160
loop do
150
161
res = search_synonyms(index_name, search_synonyms_params, request_options)
@@ -155,8 +166,8 @@ def browse_synonyms(index_name, search_synonyms_params = Search::SearchSynonymsP
155
166
else
156
167
synonyms.concat(res.hits)
157
168
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]
160
171
end
161
172
162
173
synonyms unless block_given?
@@ -405,4 +416,4 @@ def index_exists?(index_name)
405
416
end
406
417
407
418
true
408
- end
419
+ end
0 commit comments