({
query,
state: sourcesState,
setContext,
setStatus,
searchClient,
indexes: indices,
insights,
appId,
apiKey,
maxResultsPerGroup,
transformItems = identity,
saveRecentSearch,
onClose,
}: {
query: string;
state: BuildQuerySourcesState;
setContext: (context: Partial<DocSearchState<InternalDocSearchHit>['context']>) => void;
setStatus: (status: DocSearchState<InternalDocSearchHit>['status']) => void;
searchClient: ReturnType<typeof useSearchClient>;
indexes: DocSearchIndex[];
insights: boolean;
appId?: string;
apiKey?: string;
maxResultsPerGroup?: number;
transformItems?: DocSearchProps['transformItems'];
saveRecentSearch: (item: InternalDocSearchHit) => void;
onClose: () => void;
})
| 123 | * note: we only need specific parts of the state, not the full DocSearchState. |
| 124 | */ |
| 125 | const buildQuerySources = async ({ |
| 126 | query, |
| 127 | state: sourcesState, |
| 128 | setContext, |
| 129 | setStatus, |
| 130 | searchClient, |
| 131 | indexes: indices, |
| 132 | insights, |
| 133 | appId, |
| 134 | apiKey, |
| 135 | maxResultsPerGroup, |
| 136 | transformItems = identity, |
| 137 | saveRecentSearch, |
| 138 | onClose, |
| 139 | }: { |
| 140 | query: string; |
| 141 | state: BuildQuerySourcesState; |
| 142 | setContext: (context: Partial<DocSearchState<InternalDocSearchHit>['context']>) => void; |
| 143 | setStatus: (status: DocSearchState<InternalDocSearchHit>['status']) => void; |
| 144 | searchClient: ReturnType<typeof useSearchClient>; |
| 145 | indexes: DocSearchIndex[]; |
| 146 | insights: boolean; |
| 147 | appId?: string; |
| 148 | apiKey?: string; |
| 149 | maxResultsPerGroup?: number; |
| 150 | transformItems?: DocSearchProps['transformItems']; |
| 151 | saveRecentSearch: (item: InternalDocSearchHit) => void; |
| 152 | onClose: () => void; |
| 153 | }): Promise<Array<AutocompleteSource<InternalDocSearchHit>>> => { |
| 154 | const insightsActive = insights; |
| 155 | |
| 156 | try { |
| 157 | const { results } = await searchClient.search<DocSearchHit>({ |
| 158 | requests: indices.map((index) => { |
| 159 | const indexName = typeof index === 'string' ? index : index.name; |
| 160 | const searchParams = typeof index === 'string' ? {} : index.searchParameters; |
| 161 | |
| 162 | return { |
| 163 | query, |
| 164 | indexName, |
| 165 | attributesToRetrieve: searchParams?.attributesToRetrieve ?? [ |
| 166 | 'hierarchy.lvl0', |
| 167 | 'hierarchy.lvl1', |
| 168 | 'hierarchy.lvl2', |
| 169 | 'hierarchy.lvl3', |
| 170 | 'hierarchy.lvl4', |
| 171 | 'hierarchy.lvl5', |
| 172 | 'hierarchy.lvl6', |
| 173 | 'content', |
| 174 | 'type', |
| 175 | 'url', |
| 176 | ], |
| 177 | attributesToSnippet: searchParams?.attributesToSnippet ?? [ |
| 178 | `hierarchy.lvl1:${SNIPPET_LENGTH}`, |
| 179 | `hierarchy.lvl2:${SNIPPET_LENGTH}`, |
| 180 | `hierarchy.lvl3:${SNIPPET_LENGTH}`, |
| 181 | `hierarchy.lvl4:${SNIPPET_LENGTH}`, |
| 182 | `hierarchy.lvl5:${SNIPPET_LENGTH}`, |
no test coverage detected