feat(search): show search result snippets with match highlighting (#219) #242
@@ -5,6 +5,7 @@ import type { components } from '$lib/generated/api';
|
||||
type IncompleteDocumentDTO = components['schemas']['IncompleteDocumentDTO'];
|
||||
type StatsDTO = components['schemas']['StatsDTO'];
|
||||
type Document = components['schemas']['Document'];
|
||||
type SearchMatchData = components['schemas']['SearchMatchData'];
|
||||
|
||||
export async function load({ url, fetch }) {
|
||||
const q = url.searchParams.get('q') || '';
|
||||
@@ -60,9 +61,14 @@ export async function load({ url, fetch }) {
|
||||
throw redirect(302, '/login');
|
||||
}
|
||||
|
||||
const searchResult = docsResult?.data as { documents?: Document[]; total?: number } | null;
|
||||
const searchResult = docsResult?.data as {
|
||||
documents?: Document[];
|
||||
total?: number;
|
||||
matchData?: Record<string, SearchMatchData>;
|
||||
} | null;
|
||||
const documents: Document[] = searchResult?.documents ?? [];
|
||||
const total: number = searchResult?.total ?? 0;
|
||||
const matchData: Record<string, SearchMatchData> = searchResult?.matchData ?? {};
|
||||
const allPersons = (personsResult.data ?? []) as {
|
||||
id: string;
|
||||
firstName: string;
|
||||
@@ -99,6 +105,7 @@ export async function load({ url, fetch }) {
|
||||
isDashboard,
|
||||
documents,
|
||||
total,
|
||||
matchData,
|
||||
stats,
|
||||
incompleteDocs,
|
||||
recentDocs,
|
||||
@@ -116,6 +123,7 @@ export async function load({ url, fetch }) {
|
||||
isDashboard,
|
||||
documents: [],
|
||||
total: 0,
|
||||
matchData: {} as Record<string, SearchMatchData>,
|
||||
stats: null,
|
||||
incompleteDocs: [],
|
||||
recentDocs: [],
|
||||
|
||||
@@ -140,6 +140,7 @@ const showRightColumn = $derived(data.canWrite || (data.incompleteDocs?.length ?
|
||||
total={data.total ?? 0}
|
||||
q={q}
|
||||
sort={sort}
|
||||
matchData={data.matchData ?? {}}
|
||||
/>
|
||||
{/if}
|
||||
</main>
|
||||
|
||||
@@ -22,8 +22,23 @@ const emptyData = {
|
||||
canWrite: true,
|
||||
canAnnotate: false,
|
||||
isDashboard: false,
|
||||
filters: { q: '', from: '', to: '', senderId: '', receiverId: '', tags: [] },
|
||||
filters: {
|
||||
q: '',
|
||||
from: '',
|
||||
to: '',
|
||||
senderId: '',
|
||||
receiverId: '',
|
||||
tags: [],
|
||||
sort: 'DATE' as const,
|
||||
dir: 'desc' as const,
|
||||
tagQ: ''
|
||||
},
|
||||
documents: [],
|
||||
total: 0,
|
||||
matchData: {} as Record<
|
||||
string,
|
||||
import('$lib/generated/api').components['schemas']['SearchMatchData']
|
||||
>,
|
||||
incompleteDocs: [],
|
||||
recentDocs: [],
|
||||
stats: null,
|
||||
|
||||
Reference in New Issue
Block a user