@@ -310,6 +310,58 @@ export async function fetchSearchResults({
310310 } ;
311311}
312312
313+ /* eslint-disable no-await-in-loop */
314+ export async function fetchAllSearchResults (
315+ params : FetchSearchParams ,
316+ ) : Promise < {
317+ hits : HitType [ ] ;
318+ totalHits : number ;
319+ blockTypes : Record < string , number > ;
320+ problemTypes : Record < string , number > ;
321+ publishStatus : Record < string , number > ;
322+ } > {
323+ const allHits : HitType [ ] = [ ] ;
324+ const limit = params . limit ?? 20 ;
325+
326+ let offset = 0 ;
327+ let nextOffset : number | undefined ;
328+
329+ // Facets + totals only need to be read once (from the first page)
330+ let totalHits = 0 ;
331+ let blockTypes : Record < string , number > = { } ;
332+ let problemTypes : Record < string , number > = { } ;
333+ let publishStatus : Record < string , number > = { } ;
334+
335+ do {
336+ const page = await fetchSearchResults ( {
337+ ...params ,
338+ offset,
339+ limit,
340+ } ) ;
341+
342+ allHits . push ( ...page . hits ) ;
343+
344+ if ( offset === 0 ) {
345+ totalHits = page . totalHits ;
346+ blockTypes = page . blockTypes ;
347+ problemTypes = page . problemTypes ;
348+ publishStatus = page . publishStatus ;
349+ }
350+
351+ nextOffset = page . nextOffset ;
352+ offset = nextOffset ?? offset ;
353+ } while ( nextOffset !== undefined ) ;
354+
355+ return {
356+ hits : allHits ,
357+ totalHits,
358+ blockTypes,
359+ problemTypes,
360+ publishStatus,
361+ } ;
362+ }
363+ /* eslint-enable no-await-in-loop */
364+
313365/**
314366 * Fetch the block types facet distribution for the search results.
315367 */
0 commit comments