mirror of
https://github.com/open-webui/open-webui
synced 2024-11-07 00:59:52 +00:00
refac: knowledge fuzzy search
This commit is contained in:
parent
4aca1e86ad
commit
9c4b55c86a
@ -1,4 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import Fuse from 'fuse.js';
|
||||||
|
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import relativeTime from 'dayjs/plugin/relativeTime';
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
||||||
dayjs.extend(relativeTime);
|
dayjs.extend(relativeTime);
|
||||||
@ -24,8 +26,16 @@
|
|||||||
let selectedItem = null;
|
let selectedItem = null;
|
||||||
let showDeleteConfirm = false;
|
let showDeleteConfirm = false;
|
||||||
|
|
||||||
let filteredItems;
|
let fuse = null;
|
||||||
$: filteredItems = $knowledge.filter((item) => query === '' || item.name.includes(query));
|
|
||||||
|
let filteredItems = [];
|
||||||
|
$: if (fuse) {
|
||||||
|
filteredItems = query
|
||||||
|
? fuse.search(query).map((e) => {
|
||||||
|
return e.item;
|
||||||
|
})
|
||||||
|
: $knowledge;
|
||||||
|
}
|
||||||
|
|
||||||
const deleteHandler = async (item) => {
|
const deleteHandler = async (item) => {
|
||||||
const res = await deleteKnowledgeById(localStorage.token, item.id).catch((e) => {
|
const res = await deleteKnowledgeById(localStorage.token, item.id).catch((e) => {
|
||||||
@ -40,6 +50,12 @@
|
|||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
knowledge.set(await getKnowledgeItems(localStorage.token));
|
knowledge.set(await getKnowledgeItems(localStorage.token));
|
||||||
|
|
||||||
|
knowledge.subscribe((value) => {
|
||||||
|
fuse = new Fuse(value, {
|
||||||
|
keys: ['name', 'description']
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user