forked from meilisearch/meilisearch-js-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
72 lines (68 loc) · 1.99 KB
/
Copy pathapp.js
File metadata and controls
72 lines (68 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { instantMeiliSearch } from '../../../src/client/index'
import injectScript from 'scriptjs'
const GOOGLE_API = process.env.GOOGLE_API
injectScript(
`https://maps.googleapis.com/maps/api/js?v=quarterly&key=${GOOGLE_API}`,
() => {
const search = instantsearch({
indexName: 'world_cities',
searchClient: instantMeiliSearch(
'https://integration-demos.meilisearch.com',
'99d1e034ed32eb569f9edc27962cccf90b736e4c5a70f7f5e76b9fab54d6a185',
{
limitPerRequest: 20,
}
),
})
search.addWidgets([
instantsearch.widgets.sortBy({
container: '#sort-by',
items: [
{ value: 'world_cities', label: 'Relevant' },
{
value: 'world_cities:population:desc',
label: 'Most Populated',
},
{
value: 'world_cities:population:asc',
label: 'Least Populated',
},
],
}),
instantsearch.widgets.searchBox({
container: '#searchbox',
}),
instantsearch.widgets.configure({
hitsPerPage: 20,
}),
instantsearch.widgets.geoSearch({
container: '#maps',
googleReference: window.google,
initialZoom: 7,
initialPosition: {
lat: 50.655250871381355,
lng: 4.843585698860502,
},
}),
instantsearch.widgets.infiniteHits({
container: '#hits',
templates: {
item: `
<div>
<div class="hit-name">
City: {{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}
</div>
<div class="hit-name">
Country: {{#helpers.highlight}}{ "attribute": "country" }{{/helpers.highlight}}
</div>
<div class="hit-name">
Population: {{#helpers.highlight}}{ "attribute": "population" }{{/helpers.highlight}}
</div>
</div>
`,
},
}),
])
search.start()
}
)