Add entry facets and links
Surface alias/origin facets, SSR facets on entries page, fix facet query ambiguity, and document clickable links. Signed-off-by: codex@lucy.xalior.com
This commit is contained in:
@@ -97,6 +97,10 @@ export interface EntryFacets {
|
||||
genres: FacetItem<number>[];
|
||||
languages: FacetItem<string>[];
|
||||
machinetypes: FacetItem<number>[];
|
||||
flags: {
|
||||
hasAliases: number;
|
||||
hasOrigins: number;
|
||||
};
|
||||
}
|
||||
|
||||
function buildEntrySearchUnion(pattern: string, scope: EntrySearchScope) {
|
||||
@@ -1582,12 +1586,12 @@ export async function getEntryFacets(params: SearchParams): Promise<EntryFacets>
|
||||
if (scope !== "title") {
|
||||
try {
|
||||
const union = buildEntrySearchUnion(pattern, scope);
|
||||
whereParts.push(sql`id in (select entry_id from (${union}) as matches)`);
|
||||
whereParts.push(sql`e.id in (select entry_id from (${union}) as matches)`);
|
||||
} catch {
|
||||
whereParts.push(sql`id in (select entry_id from ${searchByTitles} where ${searchByTitles.entryTitle} like ${pattern})`);
|
||||
whereParts.push(sql`e.id in (select entry_id from ${searchByTitles} where ${searchByTitles.entryTitle} like ${pattern})`);
|
||||
}
|
||||
} else {
|
||||
whereParts.push(sql`id in (select entry_id from ${searchByTitles} where ${searchByTitles.entryTitle} like ${pattern})`);
|
||||
whereParts.push(sql`e.id in (select entry_id from ${searchByTitles} where ${searchByTitles.entryTitle} like ${pattern})`);
|
||||
}
|
||||
}
|
||||
if (params.genreId) whereParts.push(sql`${entries.genretypeId} = ${params.genreId}`);
|
||||
@@ -1626,6 +1630,22 @@ export async function getEntryFacets(params: SearchParams): Promise<EntryFacets>
|
||||
order by count desc, name asc
|
||||
`);
|
||||
|
||||
let hasAliases = 0;
|
||||
let hasOrigins = 0;
|
||||
try {
|
||||
const rows = await db.execute(sql`
|
||||
select
|
||||
sum(e.id in (select ${searchByAliases.entryId} from ${searchByAliases})) as hasAliases,
|
||||
sum(e.id in (select ${searchByOrigins.entryId} from ${searchByOrigins})) as hasOrigins
|
||||
from ${entries} as e
|
||||
${whereSql}
|
||||
`);
|
||||
type FlagRow = { hasAliases: number | string | null; hasOrigins: number | string | null };
|
||||
const row = (rows as unknown as FlagRow[])[0];
|
||||
hasAliases = Number(row?.hasAliases ?? 0);
|
||||
hasOrigins = Number(row?.hasOrigins ?? 0);
|
||||
} catch {}
|
||||
|
||||
type FacetRow = { id: number | string | null; name: string | null; count: number | string };
|
||||
return {
|
||||
genres: (genresRows as unknown as FacetRow[])
|
||||
@@ -1637,6 +1657,10 @@ export async function getEntryFacets(params: SearchParams): Promise<EntryFacets>
|
||||
machinetypes: (mtRows as unknown as FacetRow[])
|
||||
.map((r) => ({ id: Number(r.id), name: r.name ?? "(none)", count: Number(r.count) }))
|
||||
.filter((r) => !!r.id),
|
||||
flags: {
|
||||
hasAliases,
|
||||
hasOrigins,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user