feat : add fuzzy matching for searching
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
"use client";
|
||||
|
||||
import { searchItems } from "@/lib/search";
|
||||
import { SearchNotice } from "@/components/search-notice";
|
||||
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
@@ -88,12 +91,10 @@ export function StructuredDashboard({
|
||||
);
|
||||
const syncJobId = syncJob?.id;
|
||||
const syncJobStatus = syncJob?.status;
|
||||
const normalizedQuery = query.trim().toLowerCase();
|
||||
const filteredGuides = guides.filter((guide) =>
|
||||
`${guide.name} ${guide.characterKey} ${guide.overview}`
|
||||
.toLowerCase()
|
||||
.includes(normalizedQuery),
|
||||
);
|
||||
const search = searchItems(guides, query,
|
||||
(guide) => `${guide.name} ${guide.characterKey} ${guide.overview}`,
|
||||
(guide) => [guide.name]);
|
||||
const filteredGuides = search.items;
|
||||
|
||||
useEffect(() => {
|
||||
if (!syncJobId || !syncJobStatus || ["completed", "unchanged", "cancelled", "error"].includes(syncJobStatus)) return;
|
||||
@@ -212,6 +213,7 @@ export function StructuredDashboard({
|
||||
/>
|
||||
</InputGroup>
|
||||
) : null}
|
||||
<SearchNotice fuzzy={search.fuzzy} />
|
||||
{filteredGuides.length ? (
|
||||
<div className="grid gap-5 md:grid-cols-2 xl:grid-cols-3">
|
||||
{filteredGuides.map((guide) => (
|
||||
|
||||
Reference in New Issue
Block a user