From 9e55febc8992b916b74aca9a3f0940fad48da1d0 Mon Sep 17 00:00:00 2001 From: Mika Munterud Date: Wed, 8 Jan 2025 14:34:49 +0100 Subject: [PATCH] DIGG-508: Updating filter for high value dataset --- .../search-page-provider-settings.ts | 14 +++++++---- locales/en/resources.json | 8 ++++++- locales/sv/resources.json | 8 ++++++- utilities/entrystore/entrystore-helpers.ts | 10 ++++++++ utilities/entrystore/entrystore.service.ts | 24 ++++++++++++------- 5 files changed, 50 insertions(+), 14 deletions(-) diff --git a/features/search/search-page/search-page-entryscape/search-page-provider-settings.ts b/features/search/search-page/search-page-entryscape/search-page-provider-settings.ts index 6a1d202a9..0b9e733c9 100644 --- a/features/search/search-page/search-page-entryscape/search-page-provider-settings.ts +++ b/features/search/search-page/search-page-entryscape/search-page-provider-settings.ts @@ -135,14 +135,20 @@ export function createSearchProviderSettings(env: EnvSettings, lang: string) { group: "distribution", }, { - resource: "http://data.europa.eu/r5r/applicableLegislation", + resource: "http://data.europa.eu/r5r/hvdCategory", type: ESType.uri, - dcatProperty: "dcatap:applicableLegislation", - dcatType: "choice", + dcatProperty: "dcatap:hvdCategory", dcatFilterEnabled: false, indexOrder: 6, group: "type", - customFilter: "http://data.europa.eu/eli/reg_impl/2023/138/oj", + customProperties: [ + "http://data.europa.eu/bna/c_ac64a52d", + "http://data.europa.eu/bna/c_dd313021", + "http://data.europa.eu/bna/c_164e0bf5", + "http://data.europa.eu/bna/c_e1da4e07", + "http://data.europa.eu/bna/c_a9135398", + "http://data.europa.eu/bna/c_b79e35eb", + ], showInSearchResult: true, }, { diff --git a/locales/en/resources.json b/locales/en/resources.json index 6f23b0f45..8fc630fe3 100644 --- a/locales/en/resources.json +++ b/locales/en/resources.json @@ -1,5 +1,11 @@ { - "http://data.europa.eu/r5r/applicableLegislation": "High-value dataset", + "http://data.europa.eu/bna/c_164e0bf5": "Meteorological data", + "http://data.europa.eu/bna/c_a9135398": "Companies and company ownership", + "http://data.europa.eu/bna/c_ac64a52d": "Geospatial data", + "http://data.europa.eu/bna/c_b79e35eb": "Mobility", + "http://data.europa.eu/bna/c_dd313021": "Earth observation and environment", + "http://data.europa.eu/bna/c_e1da4e07": "Statistics", + "http://data.europa.eu/r5r/hvdCategory": "High-value dataset", "http://publications.europa.eu/resource/authority/data-theme/AGRI": "Agriculture, fisheries, forestry and food", "http://publications.europa.eu/resource/authority/data-theme/ECON": "Economy and finance ", "http://publications.europa.eu/resource/authority/data-theme/EDUC": "Education, culture and sport", diff --git a/locales/sv/resources.json b/locales/sv/resources.json index a8ba4d923..498aa4f7a 100644 --- a/locales/sv/resources.json +++ b/locales/sv/resources.json @@ -1,5 +1,11 @@ { - "http://data.europa.eu/r5r/applicableLegislation": "Värdefulla datamängder", + "http://data.europa.eu/bna/c_164e0bf5": "Meteorologiska data", + "http://data.europa.eu/bna/c_a9135398": "Företag och företagsägande", + "http://data.europa.eu/bna/c_ac64a52d": "Geospatiala data", + "http://data.europa.eu/bna/c_b79e35eb": "Rörlighet", + "http://data.europa.eu/bna/c_dd313021": "Jordobservation och miljö", + "http://data.europa.eu/bna/c_e1da4e07": "Statistik", + "http://data.europa.eu/r5r/hvdCategory": "Värdefulla datamängder", "http://publications.europa.eu/resource/authority/data-theme/AGRI": "Jordbruk, fiske, skogsbruk och livsmedel", "http://publications.europa.eu/resource/authority/data-theme/ECON": "Ekonomi och finans", "http://publications.europa.eu/resource/authority/data-theme/EDUC": "Utbildning, kultur och sport", diff --git a/utilities/entrystore/entrystore-helpers.ts b/utilities/entrystore/entrystore-helpers.ts index c8ebca841..f6ed25b01 100644 --- a/utilities/entrystore/entrystore-helpers.ts +++ b/utilities/entrystore/entrystore-helpers.ts @@ -7,6 +7,7 @@ import { } from "@entryscape/entrystore-js"; // @ts-expect-error no types import lucene from "lucene"; +import { Translate } from "next-translate"; import { SettingsUtil } from "@/env"; import { Settings_Sandbox } from "@/env/settings.sandbox"; @@ -81,7 +82,9 @@ export const getEntryLang = (metadataGraph: any, prop: any, lang: string) => { export const getUriNames = async ( facetValues: string[], esu: EntryStoreUtil, + t: Translate, property?: string, + hasCustomProperties?: boolean, ) => { const cache = entryCache.get(); // Filter out null values and already cached URIs @@ -93,6 +96,13 @@ export const getUriNames = async ( return cache; } + if (hasCustomProperties) { + uniqueUris.forEach((uri) => { + cache.set(uri, t(`resources|${uri}`)); + }); + return cache; + } + try { // Load all entries in one batch with a single request const entries = await esu.loadEntriesByResourceURIs( diff --git a/utilities/entrystore/entrystore.service.ts b/utilities/entrystore/entrystore.service.ts index 340a57cc2..03cccff62 100644 --- a/utilities/entrystore/entrystore.service.ts +++ b/utilities/entrystore/entrystore.service.ts @@ -328,7 +328,10 @@ export class EntrystoreService { }) .map((v: SearchFacet) => v.name), this.entryStoreUtil, + this.t, facetSpec?.dcatProperty, + facetSpec.customProperties && + facetSpec.customProperties.length > 0, ); } } @@ -725,21 +728,26 @@ export class EntrystoreService { for (const facet of customFacets) { const hasResource = metadata .find(entry.getResourceURI(), facet.resource) - .some((f: any) => - f - .getValue() - .startsWith( + .some((f: any) => { + const value = f.getValue(); + + return ( + value.startsWith( facet?.customFilter?.endsWith("*") ? facet?.customFilter?.slice(0, -1) : facet?.customFilter || facet?.customProperties?.[0], - ), - ); + ) || facet?.customProperties?.includes(value) + ); + }); if (hasResource) { + // Initialize the array if it doesn't exist + values["custom_facet_literal"] = + values["custom_facet_literal"] || []; // Add the translated resource URI to custom_facet_literal array - values["custom_facet_literal"] = [ + values["custom_facet_literal"].push( this.t(`resources|${facet.resource}`), - ]; + ); } } }