cat
This commit is contained in:
@@ -77,18 +77,27 @@ function shapeCategories(counts, byId) {
|
||||
return categories;
|
||||
}
|
||||
|
||||
/** Ensure every applied filter id appears in categories (count 0 if no hits). */
|
||||
function ensureFilterCategories(categories, filter, byId) {
|
||||
/**
|
||||
* Ensure every applied filter id and its ancestors appear in categories
|
||||
* (count 0 if no hits), so the frontend can render hierarchy via parent links.
|
||||
*/
|
||||
function ensureFilterCategories(categories, filter, byId, parentMap) {
|
||||
for (const id of filter) {
|
||||
if (id === '' || id === null || categories[id]) {
|
||||
if (id === '' || id === null) {
|
||||
continue;
|
||||
}
|
||||
const meta = byId[id] ?? {};
|
||||
categories[id] = {
|
||||
count: 0,
|
||||
name: meta.name ?? null,
|
||||
parent: meta.parent ?? null,
|
||||
};
|
||||
for (const ancestorId of getUpPath(id, parentMap)) {
|
||||
const key = String(ancestorId);
|
||||
if (categories[key]) {
|
||||
continue;
|
||||
}
|
||||
const meta = byId[ancestorId] ?? byId[key] ?? {};
|
||||
categories[key] = {
|
||||
count: 0,
|
||||
name: meta.name ?? null,
|
||||
parent: meta.parent ?? null,
|
||||
};
|
||||
}
|
||||
}
|
||||
return categories;
|
||||
}
|
||||
@@ -206,7 +215,8 @@ export async function searchArticles(target, filter = [''], offset = 0, maxCount
|
||||
categoryData.byId
|
||||
),
|
||||
filter,
|
||||
categoryData.byId
|
||||
categoryData.byId,
|
||||
categoryData.parentMap
|
||||
);
|
||||
const length = result.recordset.length;
|
||||
const recordset = result.recordset
|
||||
|
||||
Reference in New Issue
Block a user