Skip to content

Commit aecc7c2

Browse files
committed
chore(clients): add default hitsPerPage for browse objects helper
1 parent 2ed81ce commit aecc7c2

File tree

6 files changed

+22
-2
lines changed

6 files changed

+22
-2
lines changed

clients/algoliasearch-client-swift/Sources/Search/Extra/SearchClientExtension.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,13 @@ public extension SearchClient {
243243
aggregator: @escaping (BrowseResponse<T>) -> Void,
244244
requestOptions: RequestOptions? = nil
245245
) async throws -> BrowseResponse<T> {
246-
try await createIterable(
246+
var updatedBrowseParams = browseParams
247+
if updatedBrowseParams.hitsPerPage == nil {
248+
updatedBrowseParams.hitsPerPage = 1000
249+
}
250+
251+
return try await createIterable(
247252
execute: { previousResponse in
248-
var updatedBrowseParams = browseParams
249253
if let previousResponse {
250254
updatedBrowseParams.cursor = previousResponse.cursor
251255
}

templates/go/search_helpers.mustache

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,10 @@ func (c *APIClient) BrowseObjects(
305305
browseParams BrowseParamsObject,
306306
opts ...IterableOption,
307307
) error {
308+
if browseParams.HitsPerPage == nil {
309+
browseParams.HitsPerPage = utils.ToPtr(int32(1000))
310+
}
311+
308312
_, err := CreateIterable( //nolint:wrapcheck
309313
func(previousResponse *BrowseResponse, previousErr error) (*BrowseResponse, error) {
310314
if previousResponse != nil {

templates/java/api_helpers.mustache

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ public GetApiKeyResponse waitForApiKey(String key, ApiKeyOperation operation) {
298298
public <T> Iterable<T> browseObjects(String indexName, BrowseParamsObject params, Class<T> innerType, RequestOptions requestOptions) {
299299
final Holder<String> currentCursor = new Holder<>();
300300
301+
if (params.getHitsPerPage() == null) {
302+
params.setHitsPerPage(1000);
303+
}
304+
301305
return AlgoliaIterableHelper.createIterable(
302306
() -> {
303307
BrowseResponse<T> response = this.browse(indexName, params, innerType, requestOptions);

templates/javascript/clients/client/api/helpers.mustache

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ browseObjects<T>(
169169
}: BrowseOptions<BrowseResponse<T>> & BrowseProps,
170170
requestOptions?: RequestOptions
171171
): Promise<BrowseResponse<T>> {
172+
if (browseParams.hitsPerPage == null) {
173+
browseParams.hitsPerPage = 1000;
174+
}
175+
172176
return createIterablePromise<BrowseResponse<T>>({
173177
func: (previousResponse) => {
174178
return this.browse(

templates/python/search_helpers.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@
128128
"""
129129
Helper: Iterate on the `browse` method of the client to allow aggregating objects of an index.
130130
"""
131+
browse_params.hits_per_page = browse_params.hits_per_page or 1000
132+
131133
{{^isSyncClient}}async {{/isSyncClient}}def _func(_prev: Optional[BrowseResponse]) -> BrowseResponse:
132134
if _prev is not None and _prev.cursor is not None:
133135
browse_params.cursor = _prev.cursor

templates/ruby/search_helpers.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ 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] = browse_params[:hits_per_page] || 1000
99+
98100
hits = []
99101
loop do
100102
res = browse(index_name, browse_params, request_options)

0 commit comments

Comments
 (0)