Download react-query/examples/react/algolia/src/algolia.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 963 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/examples/react/algolia/src/algolia.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/examples/react/algolia/src/algolia.ts
-
curl -L -o algolia.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/examples/react/algolia/src/algolia.ts
963 Bytes
| import { searchClient } from '@algolia/client-search' | |
| import type { Hit } from '@algolia/client-search' | |
| // From Algolia example | |
| // https://github.com/algolia/react-instantsearch | |
| const ALGOLIA_APP_ID = 'latency' | |
| const ALGOLIA_SEARCH_API_KEY = '6be0576ff61c053d5f9a3225e2a90f76' | |
| type SearchOptions = { | |
| indexName: string | |
| query: string | |
| pageParam: number | |
| hitsPerPage: number | |
| } | |
| export async function search<TData>({ | |
| indexName, | |
| query, | |
| pageParam, | |
| hitsPerPage = 10, | |
| }: SearchOptions): Promise<{ | |
| hits: Array<Hit<TData>> | |
| nextPage: number | undefined | |
| }> { | |
| const client = searchClient(ALGOLIA_APP_ID, ALGOLIA_SEARCH_API_KEY) | |
| console.log('algolia:search', { indexName, query, pageParam, hitsPerPage }) | |
| const { hits, page, nbPages } = await client.searchSingleIndex<TData>({ | |
| indexName, | |
| searchParams: { query, page: pageParam, hitsPerPage }, | |
| }) | |
| const nextPage = page + 1 < nbPages ? page + 1 : undefined | |
| return { hits, nextPage } | |
| } | |