Skip to content

Commit d8b97e7

Browse files
Merge #826
826: Add documentation getting started code-sample r=bidoubiwa a=bidoubiwa Add the code-sample of instant-meilisearch directly in this repo instead of in the documentation repo. This means we now need to maintain this code sample as well as the code sample present in the landing page. Co-authored-by: Charlotte Vermandel <[email protected]>
2 parents 5d169b6 + 8e51e9d commit d8b97e7

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

.code-samples.meilisearch.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,56 @@ landing_getting_started_1: |-
3636
search.start()
3737
</script>
3838
</body>
39+
getting_started_front_end_integration_md: |-
40+
The following code sample uses plain [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript).
41+
42+
```html
43+
<!DOCTYPE html>
44+
<html lang="en">
45+
<head>
46+
<meta charset="utf-8" />
47+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@meilisearch/instant-meilisearch/templates/basic_search.css" />
48+
</head>
49+
<body>
50+
<div class="wrapper">
51+
<div id="searchbox" focus></div>
52+
<div id="hits"></div>
53+
</div>
54+
</body>
55+
<script src="https://cdn.jsdelivr.net/npm/@meilisearch/instant-meilisearch/dist/instant-meilisearch.umd.min.js"></script>
56+
<script src="https://cdn.jsdelivr.net/npm/instantsearch.js@4"></script>
57+
<script>
58+
const search = instantsearch({
59+
indexName: "movies",
60+
searchClient: instantMeiliSearch(
61+
"http://localhost:7700"
62+
)
63+
});
64+
search.addWidgets([
65+
instantsearch.widgets.searchBox({
66+
container: "#searchbox"
67+
}),
68+
instantsearch.widgets.configure({ hitsPerPage: 8 }),
69+
instantsearch.widgets.hits({
70+
container: "#hits",
71+
templates: {
72+
item: `
73+
<div>
74+
<div class="hit-name">
75+
{{#helpers.highlight}}{ "attribute": "title" }{{/helpers.highlight}}
76+
</div>
77+
</div>
78+
`
79+
}
80+
})
81+
]);
82+
search.start();
83+
</script>
84+
</html>
85+
```
86+
87+
Here's what's happening:
88+
89+
- The first four lines of the `<body>` add two container elements: `#searchbox` and `#hits`. `instant-meilisearch` creates the search bar inside `#searchbox` and lists search results in `#hits`
90+
- The first two`<script src="…">` tags import libraries needed to run `instant-meilisearch`
91+
- The third and final `<script>` tag is where you customize `instant-meilisearch`

0 commit comments

Comments
 (0)