You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This library is the search client that you should use to make [Meilisearch](https://github.com/meilisearch/meilisearch) work with [autocomplete](https://github.com/algolia/autocomplete). Autocomplete, an open-source project developed by Algolia, is a JavaScript library that lets you quickly build an autocomplete experiences.
Since `autocomplete.js` provides the possibility to use a custom `data source`, we are able to plug into it. Nonetheless, it has been created by Algolia and thus some of its components only works with Algolia.
36
29
37
30
@@ -40,10 +33,9 @@ Since `autocomplete.js` provides the possibility to use a custom `data source`,
40
33
-[📖 Documentation](#-documentation)
41
34
-[🔧 Installation](#-installation)
42
35
-[🎬 Usage](#-usage)
36
+
-[🎬 Getting started](#-getting-started)
43
37
-[💅 Customization](#-customization)
44
-
-[🪡 Example with InstantSearch](#-example-with-instantsearch)
45
-
-[🤖 Compatibility with Meilisearch and InstantSearch](#-compatibility-with-meilisearch-and-instantsearch)
46
-
-[📜 API Resources](#-api-resources)
38
+
-[🤖 Compatibility with Meilisearch and Autocomplete](#-compatibility-with-meilisearch-and-autocomplete)
47
39
-[⚙️ Development Workflow and Contributing](#️-development-workflow-and-contributing)
48
40
49
41
@@ -67,13 +59,19 @@ To be able to use both, you need to [install `autocomplete`](https://www.algolia
67
59
## 🎬 Usage
68
60
69
61
The Meilisearch Autocomplete client provides 2 methods:
70
-
-`meilisearchAutocompleteClient`: the search client.
71
-
-`getMeilisearchResults`: The data source handler.
62
+
-`meilisearchAutocompleteClient({ host, url, options? })`: The search client.
63
+
-`url`: The URL to your Meilisearch instance.
64
+
-`apiKey`: A valid API key with enough rights to search. ⚠️ Avoid using the admin key or master key
65
+
-`options`: Additional options. See [this section](#-customization)
66
+
-`getMeilisearchResults(searchClient, queries)`: The data source handler.
67
+
-`searchClient`: The client created with `meilisearchAutocompleteClient`
68
+
-`queries`: An array of queries. See [this documentation](https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/getAlgoliaResults/#param-queries-2) on what `queries` accepts.
72
69
73
-
## Getting started
74
70
75
-
In the following
71
+
## 🎬 Getting started
76
72
73
+
To make `autocomplete` work with meilisearch, create the `autocompleteSearchClient` and provide it to the `getMeilisearchResults` method as the searchClient.
74
+
The following code provides a basic working code example.
The `options` field in the `meilisearchAutocompleteClient` function provides the possibility to alter the default behavior of the search.
125
+
126
+
-[`placeholderSearch`](#placeholder-search): Enable or disable placeholder search (default: `true`).
127
+
-[`primaryKey`](#primary-key): Specify the primary key of your documents (default `undefined`).
128
+
-[`keepZeroFacets`](#keep-zero-facets): Show the facets value even when they have 0 matches (default `false`).
129
+
-[`matchingStrategy`](#matching-strategy): Determine the search strategy on words matching (default `last`).
130
+
-[`requestConfig`](#request-config): Use custom request configurations.
131
+
-['httpClient'](#custom-http-client): Use a custom HTTP client.
132
+
133
+
```js
134
+
constclient=meilisearchAutocompleteClient({
135
+
url:'http://localhost:7700',
136
+
apiKey:'searchKey',
137
+
options: {
138
+
placeholderSearch:false,
139
+
},
140
+
})
141
+
142
+
```
143
+
144
+
### Placeholder Search
145
+
146
+
Placeholders search means showing results even when the search query is empty. By default it is `true`.
147
+
When placeholder search is set to `false`, no results appears when the search box is empty.
148
+
149
+
```js
150
+
{ placeholderSearch :true } // default true
151
+
```
152
+
153
+
### Primary key
154
+
155
+
Specify the field in your documents containing the [unique identifier](https://docs.meilisearch.com/learn/core_concepts/documents.html#primary-field) (`undefined` by default). By adding this option, we avoid errors that are thrown in some environments. For example, In `React` particularly, this option removes the `Each child in a list should have a unique "key" prop` error.
156
+
157
+
```js
158
+
{ primaryKey :'id' } // default: undefined
159
+
```
160
+
161
+
### Keep zero facets
162
+
163
+
`keepZeroFacets` set to `true` keeps the facets even when they have 0 matching documents (default `false`).
164
+
165
+
If in your autocomplete implementation you are showing the facet values distribution, same values may completely disapear when they have no matching documents in the current filtering state.
166
+
167
+
by setting this option to `true`, the facet values do not disapear and instead are given the distribution `0`.
168
+
169
+
With `keepZeroFacets` set to `true`:
170
+
171
+
genres:
172
+
-[x] horror (2000)
173
+
-[x] thriller (214)
174
+
-[ ] comedy (0)
175
+
176
+
With `keepZeroFacets` set to `false`, `comedy` disapears:
177
+
178
+
genres:
179
+
-[x] horror (2000)
180
+
-[x] thriller (214)
181
+
182
+
```js
183
+
{ keepZeroFacets :true } // default: false
184
+
```
185
+
186
+
### Matching strategy
187
+
188
+
`matchingStrategy` gives you the possibility to choose how Meilisearch should handle the presence of multiple query words, see [documentation](https://docs.meilisearch.com/reference/api/search.html#matching-strategy).
189
+
190
+
For example, if your query is `hello world` by default Meilisearch returns documents containing either both `hello` and `world` or documents that only contain `hello`. This is the `last` strategy, where words are stripped from the right.
191
+
The other strategy is `all`, where both `hello` and `world`**must** be present in a document for it to be returned.
192
+
193
+
194
+
```js
195
+
{
196
+
matchingStrategy:'all'// default last
197
+
}
198
+
```
199
+
200
+
### Request Config
201
+
202
+
You can provide a custom request configuration. Available field can be [found here](https://fetch.spec.whatwg.org/#requestinit).
203
+
204
+
for example, with custom headers.
205
+
206
+
```ts
207
+
{
208
+
requestConfig: {
209
+
headers: {
210
+
Authorization: AUTH_TOKEN
211
+
},
212
+
credentials: 'include'
213
+
}
214
+
}
215
+
```
216
+
217
+
218
+
### Custom HTTP client
219
+
220
+
You can use your own HTTP client, for example, with [`axios`](https://github.com/axios/axios).
- The open-source `autocomplete` library is widely used and well documented in the [Algolia documentation](https://www.algolia.com/doc/ui-libraries/autocomplete/introduction/what-is-autocomplete/). It provides all the necessery information to set up your autocomplete experience.
239
+
- The [Meilisearch documentation](https://docs.meilisearch.com/).
240
+
241
+
## 🤖 Compatibility with Meilisearch and Autocomplete
242
+
243
+
**Supported autocomplete versions**:
244
+
245
+
This package only guarantees the compatibility with the [version v1.x.x of Autocomplete](https://github.com/algolia/autocomplete). It may work with older or newer versions, but these are not tested nor officially supported at this time.
246
+
247
+
**API compatibility with `autocomplete`**
248
+
Some `autocomplete` parameters are not working using the meilisearch autocomplete client.
249
+
250
+
- The autocomplete [insights] parameters (https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-insights)
251
+
- The [autocomplete-plugin-algolia-insights](https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-algolia-insights/) plugin
252
+
253
+
**Supported Meilisearch versions**:
254
+
255
+
This package only guarantees the compatibility with the [version v1.0.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v1.0.0).
256
+
257
+
**Node / NPM versions**:
258
+
259
+
- NodeJS >= 14 <= 18
260
+
261
+
## ⚙️ Development Workflow and Contributing
262
+
263
+
Any new contribution is more than welcome in this project!
264
+
265
+
If you want to know more about the development workflow or want to contribute, please visit our [contributing guidelines](../../CONTRIBUTING.md) for detailed instructions!
266
+
267
+
<hr>
268
+
269
+
**Meilisearch** provides and maintains many **SDKs and Integration tools** like this one. We want to provide everyone with an **amazing search experience for any kind of project**. If you want to contribute, make suggestions, or just know what's going on right now, visit us in the [integration-guides](https://github.com/meilisearch/integration-guides) repository.
0 commit comments