@@ -67,40 +67,52 @@ export function instantMeiliSearch(
6767 instantSearchRequests : readonly AlgoliaMultipleQueriesQuery [ ]
6868 ) : Promise < { results : Array < AlgoliaSearchResponse < T > > } > {
6969 try {
70- const searchRequest = instantSearchRequests [ 0 ]
71- const searchContext : SearchContext = createSearchContext (
72- searchRequest ,
73- instantMeiliSearchOptions ,
74- defaultFacetDistribution
75- )
70+ const searchResponses : { results : Array < AlgoliaSearchResponse < T > > } = {
71+ results : [ ] ,
72+ }
7673
77- // Adapt search request to Meilisearch compliant search request
78- const adaptedSearchRequest = adaptSearchParams ( searchContext )
74+ const requests = instantSearchRequests
75+ for ( const searchRequest of requests ) {
76+ const searchContext : SearchContext = createSearchContext (
77+ searchRequest ,
78+ instantMeiliSearchOptions ,
79+ defaultFacetDistribution
80+ const adaptedSearchRequest = adaptSearchParams ( searchContext )
81+
82+
83+ // Cache first facets distribution of the instantMeilisearch instance
84+ // Needed to add in the facetDistribution the fields that were not returned
85+ // When the user sets `keepZeroFacets` to true.
86+ if ( defaultFacetDistribution === undefined ) {
87+ defaultFacetDistribution = await cacheFirstFacetDistribution (
88+ searchResolver ,
89+ searchContext
90+ )
91+ searchContext . defaultFacetDistribution = defaultFacetDistribution
92+ }
93+
94+ // Search response from Meilisearch
95+ const searchResponse = await searchResolver . searchResponse (
96+ searchContext ,
97+ adaptedSearchRequest
98+ )
7999
80- // Cache first facets distribution of the instantMeilisearch instance
81- // Needed to add in the facetDistribution the fields that were not returned
82- // When the user sets `keepZeroFacets` to true.
83- if ( defaultFacetDistribution === undefined ) {
84- defaultFacetDistribution = await cacheFirstFacetDistribution (
85- searchResolver ,
100+ if ( log ) {
101+ console . log ( 'Meilisearch response' )
102+ console . log ( searchResponse )
103+ }
104+
105+ // Adapt the Meilisearch responsne to a compliant instantsearch.js response
106+ const adaptedSearchResponse = adaptSearchResponse < T > (
107+ searchResponse ,
86108 searchContext
87109 )
88- searchContext . defaultFacetDistribution = defaultFacetDistribution
89- }
90110
91- // Search response from Meilisearch
92- const searchResponse = await searchResolver . searchResponse (
93- searchContext ,
94- adaptedSearchRequest
95- )
96-
97- // Adapt the Meilisearch responsne to a compliant instantsearch.js response
98- const adaptedSearchResponse = adaptSearchResponse < T > (
99- searchResponse ,
100- searchContext
101- )
111+ searchResponses . results . push ( adaptedSearchResponse . results [ 0 ] )
112+ }
102113
103- return adaptedSearchResponse
114+ searchResponses . results . push ( adaptedSearchResponse . results [ 0 ] )
115+ return searchResponses
104116 } catch ( e : any ) {
105117 console . error ( e )
106118 throw new Error ( e )
0 commit comments