Open History to see the last commit
1import algoliasearch from 'algoliasearch'
2import { 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 = 0,
20 hitsPerPage = 10,
21}: SearchOptions): Promise<{
22 hits: Hit<TData>[]
23 nextPage: number | undefined
24}> {
25 const client = algoliasearch(ALGOLIA_APP_ID, ALGOLIA_SEARCH_API_KEY)
26 const index = client.initIndex(indexName)
27β
28 console.log('alogolia:search', { indexName, query, pageParam, hitsPerPage })
29β
30 const { hits, page, nbPages } = await index.search<TData>(query, {
31 page: pageParam,
32 hitsPerPage,
33 })
34β
35 const nextPage = page + 1 < nbPages ? page + 1 : undefined
36β
37 return { hits, nextPage }
38}