Skip to content

Commit d70419d

Browse files
authored
Merge pull request #151 from Rigo-m/patch-1
Added key to useAsyncAlgoliaSearch
2 parents d0af3d9 + 4701ab2 commit d70419d

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

docs/content/1.getting-started/3.usage.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ const { data, error } = await useAsyncAlgoliaSearch({ indexName: 'test_index', q
5353
This composable accepts an object as a param with following properties:
5454

5555
* `indexName` - the name of you index in Algolia dashboard. For more details about initializing index check out the official documentation [here](https://www.algolia.com/doc/api-client/getting-started/instantiate-client-index/javascript/?client=javascript#initialize-an-index). If you passed a global index in your module configuration, this property can be skipped.
56-
* `query` - a keywoard, sentence, or text that you want to search the index with.
56+
* `query` - a keyword, sentence, or text that you want to search the index with.
57+
* `key` - if you need multiple asyncAlgoliaSearch calls in a single page, add a unique key to get passed to the useAsyncData underneath, so new calls won't overwrite old data.
5758
* `requestOptions` optional object with options for the request like filters. You can check more about is [here](https://www.algolia.com/doc/api-reference/api-methods/search/#method-param-requestoptions)
5859

5960
## `useAlgoliaFacetedSearch`

src/runtime/composables/useAsyncAlgoliaSearch.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import type { RequestOptionsObject } from '../../types'
33
import { useAlgoliaInitIndex } from './useAlgoliaInitIndex'
44
import { useNuxtApp, useAsyncData, useRuntimeConfig } from '#imports'
55

6-
export type SearchParams = { query: string, indexName?: string } & RequestOptionsObject;
6+
export type SearchParams = { query: string, indexName?: string, key?: string } & RequestOptionsObject;
77

8-
export async function useAsyncAlgoliaSearch ({ query, requestOptions, indexName }: SearchParams) {
8+
export async function useAsyncAlgoliaSearch ({ query, requestOptions, indexName, key }: SearchParams) {
99
const config = useRuntimeConfig();
1010
const index = indexName || config.public.algolia.globalIndex
1111

1212
if (!index) throw new Error('`[@nuxtjs/algolia]` Cannot search in Algolia without `indexName`')
1313

1414
const algoliaIndex = useAlgoliaInitIndex(index)
1515

16-
const result = await useAsyncData(`${index}-async-search-result`, async () => {
16+
const result = await useAsyncData(`${index}-async-search-result-${key ?? ''}`, async () => {
1717
if (process.server) {
1818
const nuxtApp = useNuxtApp()
1919
nuxtApp.$algolia.transporter.requester = (await import('@algolia/requester-node-http').then(lib => lib.default || lib)).createNodeHttpRequester()

0 commit comments

Comments
 (0)