Skip to content

Commit 24f3c3d

Browse files
committed
Add search section
1 parent 63688a9 commit 24f3c3d

File tree

1 file changed

+77
-1
lines changed

1 file changed

+77
-1
lines changed

README.md

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,62 @@ Once you have a collection containing documents indexed in MeiliSearch, you can
138138

139139
Using the above credentials the following code shows how to search on one of your collections:
140140

141+
To search in MeiliSearch, you can use the [instant-meilisearch](https://github.com/meilisearch/instant-meilisearch) SDK that integrates a whole search interface, or our library [meilisearch-js](https://github.com/meilisearch/meilisearch-js).
142+
143+
#### ⚡️ Using Instant meiliSearch
144+
145+
146+
In Instant MeiliSearch you only have to provide your credentials and your index name (`restaurant` is the index name in our example).
147+
148+
You can have a quick preview the following code in a HTML file
149+
```html
150+
<!DOCTYPE html>
151+
<html lang="en">
152+
<head>
153+
<meta charset="utf-8" />
154+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@meilisearch/instant-meilisearch/templates/basic_search.css" />
155+
</head>
156+
<body>
157+
<div class="wrapper">
158+
<div id="searchbox" focus></div>
159+
<div id="hits"></div>
160+
</div>
161+
<script src="https://cdn.jsdelivr.net/npm/@meilisearch/instant-meilisearch/dist/instant-meilisearch.umd.min.js"></script>
162+
<script src="https://cdn.jsdelivr.net/npm/instantsearch.js@4"></script>
163+
<script>
164+
const search = instantsearch({
165+
indexName: "movies",
166+
searchClient: instantMeiliSearch(
167+
"http://localhost:7700"
168+
)
169+
});
170+
171+
search.addWidgets([
172+
instantsearch.widgets.searchBox({
173+
container: "#searchbox"
174+
}),
175+
instantsearch.widgets.configure({ hitsPerPage: 8 }),
176+
instantsearch.widgets.hits({
177+
container: "#hits",
178+
templates: {
179+
item: `
180+
<div>
181+
<div class="hit-name">
182+
{{#helpers.highlight}}{ "attribute": "title" }{{/helpers.highlight}}
183+
</div>
184+
</div>
185+
`
186+
}
187+
})
188+
]);
189+
search.start();
190+
</script>
191+
</body>
192+
</html>
193+
```
194+
195+
196+
141197
```javascript
142198
import { MeiliSearch } from 'meilisearch'
143199

@@ -148,10 +204,30 @@ import { MeiliSearch } from 'meilisearch'
148204
})
149205

150206
// An index is where the documents are stored.
151-
const index = client.index('movies').search('')
207+
const response = client.index('movies').search('biscoute')
152208
})()
153209
```
154210

211+
**response content**:
212+
```json
213+
{
214+
"hits": [
215+
{
216+
"id": 3,
217+
"name": "Biscotte Restaurant",
218+
"description": "Welcome to Biscotte restaurant! Restaurant Biscotte offers a cuisine based on fresh, quality products, often local, organic when possible, and always produced by passionate producers.",
219+
"categories": []
220+
}
221+
],
222+
"offset": 0,
223+
"limit": 20,
224+
"nbHits": 1,
225+
"exhaustiveNbHits": false,
226+
"processingTimeMs": 1,
227+
"query": "biscoutte"
228+
}
229+
```
230+
155231
## 💡 Learn More
156232

157233
If you don't have a running Strapi app, you can still try this plugin using either of one of the following options:

0 commit comments

Comments
 (0)