Skip to content

Commit

Permalink
feat(search): add extra facets
Browse files Browse the repository at this point in the history
- Damage
- Repository
  • Loading branch information
jmiguelv committed Dec 10, 2024
1 parent c9f515d commit e7374e8
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions frontend/src/lib/components/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ export const searchConfig = {
size: 200,
sort: 'key'
},
damage: {
title: 'Damage',
hide_zero_doc_count: true,
size: 100,
sort: 'key'
},
repository: {
title: 'Repository',
hide_zero_doc_count: true,
size: 200,
sort: 'key'
},
status: {
title: 'Status',
hide_zero_doc_count: true,
Expand Down Expand Up @@ -127,7 +139,9 @@ export function load({ sortAggregationsBy = 'key' } = {}) {
objectType: getHierarchicalValues(item.objectType?.ana),
material: getHierarchicalValues(item.material?.ana),
technique: getHierarchicalValues(technique),
pigment: getHierarchicalValues(pigment)
pigment: getHierarchicalValues(pigment),
damage: getHierarchicalValues(item.layoutDesc?.layout?.damage?.ana ?? undefined, false),
repository: item.repository?._?.trim() ?? undefined
};
});

Expand All @@ -147,21 +161,21 @@ export function load({ sortAggregationsBy = 'key' } = {}) {
* @param {string | null} leaf
* @returns {string[] | undefined}
*/
function getHierarchicalValues(value, leaf = null) {
function getHierarchicalValues(value, discardRoot = true) {
if (!value) return undefined;

let parts = value
.replaceAll('#', '')
.split('.')
.slice(1)
.map((v) => v.trim())
.map((v) => v.replaceAll('_', ' '));

if (parts.length === 1) {
return [parts[0]];
if (discardRoot) {
parts = parts.slice(1);
}

if (leaf) {
parts[parts.length - 1] = leaf.trim();
if (parts.length === 1) {
return [parts[0]];
}

const hierarchicalValues = [];
Expand Down

0 comments on commit e7374e8

Please # to comment.