|
8 | 8 | FacetDistribution, |
9 | 9 | PaginationState, |
10 | 10 | MeilisearchConfig, |
| 11 | + AlgoliaSearchForFacetValuesRequest, |
| 12 | + AlgoliaSearchForFacetValuesResponse, |
11 | 13 | } from '../types' |
12 | 14 | import { |
13 | 15 | getApiKey, |
@@ -132,13 +134,38 @@ export function instantMeiliSearch( |
132 | 134 | throw new Error(e) |
133 | 135 | } |
134 | 136 | }, |
135 | | - searchForFacetValues: async function (_: any) { |
136 | | - return await new Promise((resolve, reject) => { |
137 | | - reject( |
138 | | - new Error('SearchForFacetValues is not compatible with Meilisearch') |
139 | | - ) |
140 | | - resolve([]) // added here to avoid compilation error |
141 | | - }) |
| 137 | + searchForFacetValues: async function ( |
| 138 | + requests: AlgoliaSearchForFacetValuesRequest |
| 139 | + ): Promise<AlgoliaSearchForFacetValuesResponse[]> { |
| 140 | + console.log(requests) |
| 141 | + |
| 142 | + const results = [] |
| 143 | + for (const request of requests) { |
| 144 | + const index = request.indexName |
| 145 | + const meilisearchRequest = { |
| 146 | + facetQuery: request.params.facetQuery, |
| 147 | + facetName: request.params.facetName, |
| 148 | + } |
| 149 | + |
| 150 | + const meilisearchResponse = await meilisearchClient |
| 151 | + .index(index) |
| 152 | + .searchForFacetValues(meilisearchRequest) |
| 153 | + |
| 154 | + const facetHits = meilisearchResponse.facetHits.map((facetHit) => ({ |
| 155 | + ...facetHit, |
| 156 | + // not currently supported |
| 157 | + highlighted: facetHit.value, |
| 158 | + })) |
| 159 | + const result = { |
| 160 | + facetHits, |
| 161 | + exhaustiveFacetsCount: false, |
| 162 | + processingTimeMS: meilisearchResponse.processingTimeMs, |
| 163 | + } |
| 164 | + |
| 165 | + results.push(result) |
| 166 | + } |
| 167 | + |
| 168 | + return results |
142 | 169 | }, |
143 | 170 | } |
144 | 171 | } |
0 commit comments