Skip to content

Commit ea2f81b

Browse files
docs(createQuerySuggestionsPlugin): rewrite docs (#468)
* docs(createQuerySuggestionsPlugin): rewrite docs * fix(createQuerySuggestionsPlugin): fix name * fix: apply suggestions from code review Co-authored-by: François Chalifour <[email protected]> * docs(createQuerySuggestionsPlugin): document new parameters * fix: apply suggestions from code review Co-authored-by: François Chalifour <[email protected]> * docs(createQuerySuggestionsPlugin): clarify description Co-authored-by: François Chalifour <[email protected]>
1 parent b230909 commit ea2f81b

File tree

1 file changed

+76
-13
lines changed

1 file changed

+76
-13
lines changed

packages/website/docs/createQuerySuggestionsPlugin.md

Lines changed: 76 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,35 @@
22
id: createQuerySuggestionsPlugin
33
---
44

5+
The Query Suggestions plugin adds [Algolia Query Suggestions](https://www.algolia.com/doc/guides/building-search-ui/ui-and-ux-patterns/query-suggestions/js/) to your autocomplete.
6+
7+
## Installation
8+
9+
First, you need to install the plugin.
10+
11+
```bash
12+
yarn add @algolia/autocomplete-plugin-query-suggestions@alpha
13+
# or
14+
npm install @algolia/autocomplete-plugin-query-suggestions@alpha
15+
```
16+
17+
Then import it in your project:
18+
19+
```js
20+
import { createQuerySuggestionsPlugin } from '@algolia/autocomplete-plugin-query-suggestions';
21+
```
22+
23+
If you don't use a package manager, you can use a standalone endpoint:
24+
25+
```html
26+
<script src="https://cdn.jsdelivr.net/npm/@algolia/autocomplete-plugin-query-suggestions@alpha"></script>
27+
```
28+
529
## Example
630

7-
```ts
31+
This example uses the plugin within [`autocomplete-js`](autocomplete-js), along with the [`algoliasearch`](https://www.npmjs.com/package/algoliasearch) API client.
32+
33+
```js
834
import algoliasearch from 'algoliasearch/lite';
935
import { autocomplete } from '@algolia/autocomplete-js';
1036
import { createQuerySuggestionsPlugin } from '@algolia/autocomplete-plugin-query-suggestions';
@@ -24,9 +50,9 @@ autocomplete({
2450
});
2551
```
2652

27-
With [Recent Searches](createLocalStorageRecentSearchesPlugin):
53+
You can combine this plugin with the [Recent Searches](createLocalStorageRecentSearchesPlugin) plugin to leverage the empty screen with recent and popular queries.
2854

29-
```ts
55+
```js
3056
import algoliasearch from 'algoliasearch/lite';
3157
import { autocomplete } from '@algolia/autocomplete-js';
3258
import { createLocalStorageRecentSearchesPlugin } from '@algolia/autocomplete-plugin-recent-searches';
@@ -54,35 +80,39 @@ autocomplete({
5480
});
5581
```
5682

57-
## Import
83+
To see it in action, check [this demo on CodeSandbox](https://fzb4m.csb.app/).
5884

59-
```ts
60-
import { createQuerySuggestionsPlugin } from '@algolia/autocomplete-plugin-query-suggestions';
61-
```
62-
63-
## Params
85+
## Parameters
6486

6587
### `searchClient`
6688

6789
> `SearchClient` | required
6890
91+
The initialized Algolia search client.
92+
6993
### `indexName`
7094

7195
> `string` | required
7296
97+
The index name.
98+
7399
### `getSearchParams`
74100

75-
> [`() => SearchParameters`](https://www.algolia.com/doc/api-reference/search-api-parameters/)
101+
> `(params: { state: AutocompleteState }) => SearchParameters`
102+
103+
A function returning [Algolia search parameters](https://www.algolia.com/doc/api-reference/search-api-parameters/).
76104

77105
### `transformSource`
78106

79107
> `(params: { source: AutocompleteSource, onTapAhead: () => void })`
80108
81-
#### Example
109+
A function to transform the provided source.
110+
111+
#### Examples
82112

83113
Keeping the panel open on select:
84114

85-
```tsx
115+
```jsx
86116
const querySuggestionsPlugin = createQuerySuggestionsPlugin({
87117
searchClient,
88118
indexName: 'instant_search_demo_query_suggestions',
@@ -99,7 +129,7 @@ const querySuggestionsPlugin = createQuerySuggestionsPlugin({
99129

100130
Opening a link:
101131

102-
```tsx
132+
```jsx
103133
const querySuggestionsPlugin = createQuerySuggestionsPlugin({
104134
searchClient,
105135
indexName: 'instant_search_demo_query_suggestions',
@@ -127,3 +157,36 @@ const querySuggestionsPlugin = createQuerySuggestionsPlugin({
127157
},
128158
});
129159
```
160+
161+
### `categoryAttribute`
162+
163+
> `string | string[]`
164+
165+
The attribute or attribute path to display categories for.
166+
167+
#### Example
168+
169+
```js
170+
const querySuggestionsPlugin = createQuerySuggestionsPlugin({
171+
searchClient,
172+
indexName: 'instant_search_demo_query_suggestions',
173+
categoryAttribute: [
174+
'instant_search',
175+
'facets',
176+
'exact_matches',
177+
'hierarchicalCategories.lvl0',
178+
],
179+
});
180+
```
181+
182+
### `categoriesLimit`
183+
184+
> `number` | defaults to `1`
185+
186+
How many items to display categories for.
187+
188+
### `categoriesPerItem`
189+
190+
> `number` | defaults to `1`
191+
192+
The number of categories to display per item.

0 commit comments

Comments
 (0)