Skip to content

Commit 492da42

Browse files
bors[bot]bidoubiwacurquiza
authored
Merge #828
828: Update example to movies r=bidoubiwa a=bidoubiwa see: meilisearch/integration-guides#103 see: meilisearch/integration-guides#102 Co-authored-by: Charlotte Vermandel <[email protected]> Co-authored-by: cvermand <[email protected]> Co-authored-by: Clémentine Urquizar <[email protected]>
2 parents df142d9 + 2fe880e commit 492da42

File tree

2 files changed

+87
-37
lines changed

2 files changed

+87
-37
lines changed

README.md

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const client = new MeiliSearch({
9090
Usage in an HTML (or alike) file:
9191

9292
```html
93-
<script src="https://cdn.jsdelivr.net/npm/meilisearch@latest/dist/bundles/meilisearch.umd.js"></script>
93+
<script src='https://cdn.jsdelivr.net/npm/meilisearch@latest/dist/bundles/meilisearch.umd.js'></script>
9494
<script>
9595
const client = new MeiliSearch({
9696
host: 'http://127.0.0.1:7700',
@@ -132,18 +132,18 @@ import { MeiliSearch } from 'meilisearch'
132132
})
133133

134134
// An index is where the documents are stored.
135-
const index = client.index('books') // If your index exists
135+
const index = client.index('movies')
136136

137137
const documents = [
138-
{ book_id: 123, title: 'Pride and Prejudice', genres: ['drama', 'romance'] },
139-
{ book_id: 456, title: 'Le Petit Prince', genres: ['poetic'] },
140-
{ book_id: 1, title: 'Alice In Wonderland', genres: ['conceptual'] },
141-
{ book_id: 1344, title: 'The Hobbit' },
142-
{ book_id: 4, title: 'Harry Potter and the Half-Blood Prince', genres: ['fantasy'] },
143-
{ book_id: 42, title: "The Hitchhiker's Guide to the Galaxy", genres: ['fantasy'] }
138+
{ id: 1, title: 'Carol', genres: ['Romance', 'Drama'] },
139+
{ id: 2, title: 'Wonder Woman', genres: ['Action', 'Adventure'] },
140+
{ id: 3, title: 'Life of Pi', genres: ['Adventure', 'Drama'] },
141+
{ id: 4, title: 'Mad Max: Fury Road', genres: ['Adventure', 'Science Fiction'] },
142+
{ id: 5, title: 'Moana', genres: ['Fantasy', 'Action']},
143+
{ id: 6, title: 'Philadelphia', genres: ['Drama'] },
144144
]
145145

146-
// If the index 'books' does not exist, MeiliSearch creates it when you first add the documents.
146+
// If the index 'movies' does not exist, MeiliSearch creates it when you first add the documents.
147147
let response = await index.addDocuments(documents)
148148

149149
console.log(response) // => { "updateId": 0 }
@@ -156,7 +156,7 @@ With the `updateId`, you can check the status (`enqueued`, `processed` or `faile
156156

157157
```javascript
158158
// MeiliSearch is typo-tolerant:
159-
const search = await index.search('harry pottre')
159+
const search = await index.search('philoudelphia')
160160
console.log(search)
161161
```
162162

@@ -166,17 +166,16 @@ Output:
166166
{
167167
"hits": [
168168
{
169-
"book_id": 4,
170-
"title": "Harry Potter and the Half-Blood Prince",
171-
"genres": ["fantasy"]
169+
"id": "6",
170+
"title": "Philadelphia",
171+
"genres": ["Drama"]
172172
}
173173
],
174174
"offset": 0,
175175
"limit": 20,
176176
"nbHits": 1,
177-
"exhaustiveNbHits": false,
178177
"processingTimeMs": 1,
179-
"query": "harry pottre"
178+
"query": "philoudelphia"
180179
}
181180
```
182181

@@ -186,10 +185,10 @@ All the supported options are described in the [search parameters](https://docs.
186185

187186
```javascript
188187
await index.search(
189-
'prince',
188+
'wonder',
190189
{
191190
attributesToHighlight: ['*'],
192-
filters: 'book_id > 10'
191+
filters: 'id >= 1'
193192
}
194193
)
195194
```
@@ -198,28 +197,27 @@ await index.search(
198197
{
199198
"hits": [
200199
{
201-
"book_id": 456,
202-
"title": "Le Petit Prince",
203-
"genres": ["poetic"],
200+
"id": 2,
201+
"title": "Wonder Woman",
202+
"genres": ["Action", "Adventure"],
204203
"_formatted": {
205-
"book_id": 456,
206-
"title": "Le Petit <em>Prince</em>",
207-
"genres": ["poetic"]
204+
"id": 2,
205+
"title": "<em>Wonder</em> Woman",
206+
"genres": ["Action", "Adventure"]
208207
}
209208
}
210209
],
211210
"offset": 0,
212211
"limit": 20,
213212
"nbHits": 1,
214-
"exhaustiveNbHits": false,
215213
"processingTimeMs": 0,
216-
"query": "prince"
214+
"query": "wonder"
217215
}
218216
```
219217

220218
#### Placeholder Search <!-- omit in toc -->
221219

222-
Placeholder search makes it possible to receive hits based on your parameters without having any query (`q`).
220+
Placeholder search makes it possible to receive hits based on your parameters without having any query (`q`). To enable faceted search on your dataset you need to add `genres` in the [settings](https://docs.meilisearch.com/reference/features/faceted_search.html#setting-up-facets).
223221

224222
```javascript
225223
await index.search(
@@ -235,25 +233,31 @@ await index.search(
235233
{
236234
"hits": [
237235
{
238-
"id": 4,
239-
"title": "Harry Potter and the Half-Blood Prince",
240-
"genres": ["fantasy"]
236+
"id": 2,
237+
"title": "Wonder Woman",
238+
"genres": ["Action","Adventure"]
241239
},
242240
{
243-
"id": 42,
244-
"title": "The Hitchhiker's Guide to the Galaxy",
245-
"genres": ["fantasy"]
241+
"id": 5,
242+
"title": "Moana",
243+
"genres": ["Fantasy","Action"]
246244
}
247245
],
248246
"offset": 0,
249247
"limit": 20,
250248
"nbHits": 2,
251-
"exhaustiveNbHits": false,
252249
"processingTimeMs": 0,
253250
"query": "",
254-
"facetsDistribution": { "genres": { "fantasy": 2 } },
255-
"exhaustiveFacetsCount": true
256-
}
251+
"facetsDistribution": {
252+
"genres": {
253+
"Drama": 0,
254+
"Action": 2,
255+
"Science Fiction": 0,
256+
"Fantasy": 1,
257+
"Romance": 0,
258+
"Adventure": 1
259+
}
260+
}
257261
```
258262

259263
#### Abortable Search <!-- omit in toc -->
@@ -264,7 +268,7 @@ You can abort a pending search request by providing an [AbortSignal](https://dev
264268
const controller = new AbortController()
265269

266270
index
267-
.search('prince', {}, 'POST', {
271+
.search('wonder', {}, 'POST', {
268272
signal: controller.signal,
269273
})
270274
.then((response) => {

examples/node/getting_started.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const { MeiliSearch } = require('../../dist/bundles/meilisearch.umd.js')
2+
3+
;(async () => {
4+
const client = new MeiliSearch({
5+
host: 'http://127.0.0.1:7700',
6+
apiKey: 'masterKey',
7+
})
8+
9+
// An index is where the documents are stored.
10+
const index = client.index('movies')
11+
12+
const dataset = [
13+
{ id: 1, title: 'Carol', genres: ['Romance', 'Drama'] },
14+
{ id: 2, title: 'Wonder Woman', genres: ['Action', 'Adventure'] },
15+
{ id: 3, title: 'Life of Pi', genres: ['Adventure', 'Drama'] },
16+
{ id: 4, title: 'Mad Max: Fury Road', genres: ['Adventure', 'Science Fiction'] },
17+
{ id: 5, title: 'Moana', genres: ['Fantasy', 'Action']},
18+
{ id: 6, title: 'Philadelphia', genres: ['Drama'] },
19+
]
20+
21+
// If the index 'movies' does not exist, MeiliSearch creates it when you first add the documents.
22+
await index.updateAttributesForFaceting([
23+
'director',
24+
'genres'
25+
])
26+
27+
let response = await index.addDocuments(dataset)
28+
29+
console.log(response) // => { "updateId": 0 }
30+
31+
const search = await index.search('philoudelphia')
32+
console.log({ search, hit: search.hits })
33+
const filteredSearch = await index.search('Wonder', {
34+
attributesToHighlight: ['*'],
35+
filters: 'id >= 1'
36+
})
37+
console.log({ filteredSearch, hit: filteredSearch.hits[0] })
38+
const facetedSearch = await index.search(
39+
'',
40+
{
41+
facetFilters: ['genres:action'],
42+
facetsDistribution: ['genres']
43+
}
44+
)
45+
console.log(JSON.stringify(facetedSearch))
46+
})()

0 commit comments

Comments
 (0)