Open History to see the last commit
1import { searchClient } from '@algolia/client-search'
2import type { Hit } from '@algolia/client-search'
3β
4// From Algolia example
5// https://github.com/algolia/react-instantsearch
6const ALGOLIA_APP_ID = 'latency'
7const ALGOLIA_SEARCH_API_KEY = '6be0576ff61c053d5f9a3225e2a90f76'
8β
9type SearchOptions = {
10 indexName: string
11 query: string
12 pageParam: number
13 hitsPerPage: number
14}
15β
16export async function search<TData>({
17 indexName,
18 query,
19 pageParam,
20 hitsPerPage = 10,
21}: SearchOptions): Promise<{
22 hits: Array<Hit<TData>>
23 nbPages: number
24}> {
25 const client = searchClient(ALGOLIA_APP_ID, ALGOLIA_SEARCH_API_KEY)
26β
27 console.log('algolia:search', { indexName, query, pageParam, hitsPerPage })
28β
29 const { hits, nbPages = 0 } = await client.searchSingleIndex<TData>({
30 indexName,
31 searchParams: { query, page: pageParam, hitsPerPage },
32 })
33β
34 return { hits, nbPages }
35}