Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(discoveryengine): update search sample to disable auto paginate #3500

Merged
merged 5 commits into from
Sep 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions discoveryengine/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,27 @@ async function main(
servingConfig: name,
};

const IResponseParams = {
ISearchResult: 0,
ISearchRequest: 1,
ISearchResponse: 2,
};
chenlei1216 marked this conversation as resolved.
Show resolved Hide resolved

// Perform search request
const response = await client.search(request);
const response = await client.search(request, {
// Warning: Should always disable autoPaginate to avoid iterate through all pages.
//
// By default NodeJS SDK returns an iterable where you can iterate through all
// search results instead of only the limited number of results requested on
// pageSize, by sending multiple sequential search requests page-by-page while
// iterating, until it exhausts all the search results. This will be unexpected and
// may cause high Search API usage and long wait time, especially when the matched
// document numbers are huge.
autoPaginate: false,
});
const results = response[IResponseParams.ISearchResponse].results;

for (const result of response) {
for (const result of results) {
console.log(result);
}
}
Expand Down
Loading