-
-
Notifications
You must be signed in to change notification settings - Fork 749
Expand file tree
/
Copy pathExampleFulltextMiniSearch.vue
More file actions
51 lines (47 loc) · 1.28 KB
/
ExampleFulltextMiniSearch.vue
File metadata and controls
51 lines (47 loc) · 1.28 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
<script setup lang="ts">
import MiniSearch from 'minisearch'
const query = ref('')
const { data } = await useAsyncData('search-data', (_nuxtApp, { signal }) => queryCollectionSearchSections('docs', { signal }))
const miniSearch = new MiniSearch({
fields: ['title', 'content'],
storeFields: ['title', 'content'],
searchOptions: {
prefix: true,
fuzzy: 0.2,
},
})
// Add data to the MiniSearch instance
miniSearch.addAll(toValue(data.value || []))
const result = computed(() => miniSearch.search(toValue(query)).slice(0, 10))
</script>
<template>
<UContainer class="p-4">
<UCard>
<UInput
v-model="query"
placeholder="Search..."
class="w-full"
/>
<ul>
<li
v-for="link of result"
:key="link.id"
class="mt-2"
>
<UButton
variant="ghost"
class="w-full"
:to="link.id"
>
<div class="flex flex-col">
<span class="text-black dark:text-white font-semibold">{{ link.title }}</span>
<span class="text-gray-500 text-xs truncate">
{{ link.content?.slice(0, 100) }}...
</span>
</div>
</UButton>
</li>
</ul>
</UCard>
</UContainer>
</template>