Skip to content
This repository was archived by the owner on Aug 20, 2023. It is now read-only.

Commit 1f9afdf

Browse files
authored
Update README.md
1 parent d68655f commit 1f9afdf

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,105 @@ php please meili-search:documents help
6060
php please meili-search:documents update
6161
```
6262

63+
## Searching
64+
Searching is best done with JavaScript talking to MeiliSearch directly. This will give you the most peformant real time searches. Here is a simple example of how you could do this with [AlpineJS](https://github.com/alpinejs/alpine) and [TailwindCCS](https://tailwindcss.com).
65+
66+
***Note:** These steps assume you already have AlpineJS and Tailwind CCS already set up and working in your project.*
67+
68+
### Install the MeiliSearch NPM module
69+
```bash
70+
npm install meilisearch
71+
```
72+
or
73+
```bash
74+
yarn add meilisearch
75+
```
76+
77+
### Import and set up MeiliSearch
78+
```js
79+
import MeiliSearch from 'meilisearch';
80+
81+
window.client = new MeiliSearch({
82+
host: 'http(s)://Your MeiliSearch address & port',
83+
apiKey: 'Your MeiliSearch PUBLIC Key',
84+
});
85+
```
86+
87+
### Customize your Search Component
88+
Here is a basic autocomplete using AlpineJS and Tailwind CCS, feel free copy it, customize it, or just use it as insperation to do something completly diffrent.
89+
```html
90+
<div
91+
x-data="{
92+
searchString: '',
93+
results: {
94+
hits: [],
95+
},
96+
index: window.client.getIndex('Your Index UID Goes Here'),
97+
async search() {
98+
this.state = 'searching';
99+
this.results = await this.index.search(this.searchString);
100+
}
101+
}"
102+
class="relative"
103+
>
104+
<label
105+
class="sr-only"
106+
>
107+
Search
108+
</label>
109+
<input
110+
x-model="searchString"
111+
x-on:input="search()"
112+
type="search"
113+
class="
114+
px-2 py-1
115+
border-2 border-solid border-gray-300 rounded
116+
focus:outline-none focus:shadow-outline
117+
"
118+
/>
119+
<div
120+
x-cloak
121+
x-show="searchString.length > 0"
122+
class="
123+
absolute left-0
124+
w-full
125+
mt-1 py-1
126+
bg-white
127+
border-2 border-solid border-grey-200 rounded
128+
"
129+
>
130+
<p
131+
x-show='results.hits.length < 1'
132+
>
133+
No results
134+
</p>
135+
<ul
136+
x-show='results.hits.length > 0'
137+
>
138+
<template
139+
x-for='result in results.hits'
140+
:key="result.id"
141+
>
142+
<li>
143+
<a
144+
:href="result.uri"
145+
class="
146+
px-2 py-1
147+
hover:bg-gray-300 focus:bg-gray-300
148+
transition-colors duration-100 ease-in-out delay-75
149+
focus:outline-none focus:shadow-outline
150+
"
151+
>
152+
<h2
153+
x-text="result.title"
154+
></h2>
155+
</a>
156+
</li>
157+
</template>
158+
</ul>
159+
</div>
160+
</div>
161+
```
63162

64163
## Changelog
65164
Please see the [Release Notes](https://statamic.com/addons/jrc9designstudio/meili-search/release-notes) for more information what has changed recently.

0 commit comments

Comments
 (0)