Skip to content

Commit 8e51e9d

Browse files
committed
Add documentation getting started code-sample
1 parent 5d169b6 commit 8e51e9d

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)