Skip to content

Commit

Permalink
Merge pull request #527 from diggsweden/DIGG-472
Browse files Browse the repository at this point in the history
Digg 472: Follow specification facet
  • Loading branch information
AlessandroGasperini authored Dec 9, 2024
2 parents d91e35e + 1a11bf0 commit 6b3c434
Show file tree
Hide file tree
Showing 8 changed files with 2,920 additions and 3,675 deletions.
45 changes: 15 additions & 30 deletions features/search/search-filters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { SearchFilter } from "@/features/search/search-filters/search-filter";
import { SearchContextData } from "@/providers/search-provider";
import { SettingsContext } from "@/providers/settings-provider";
import { SearchFacet, SearchFacetValue } from "@/types/search";
import { ESRdfType, ESType } from "@/utilities/entryscape/entryscape";
import { ESRdfType, ESType, checkBoxFilterConfigs } from "@/utilities/entryscape/entryscape";

import { SearchActiveFilters } from "./search-active-filters";
import {
Expand Down Expand Up @@ -151,7 +151,7 @@ const FindFilters = (
) => {
if (!checkedFilters) return "";

const allTitles = categoryFilters.map((item) => item.title);
const allTitles = categoryFilters.map((item) => item.title);
const checkedTitles = checkedFilters.map((item) => item.title);
const union = allTitles.filter((x) => checkedTitles.includes(x));

Expand Down Expand Up @@ -280,7 +280,7 @@ export const SearchFilters: FC<SearchFilterProps> = ({
}, [search.allFacets]);

const hvd = "http://data.europa.eu/r5r/applicableLegislation";
const national = "http://purl.org/dc/terms/subject";
const spec = "http://purl.org/dc/terms/conformsTo";

const activeCheckboxFilters = useMemo(() => {
const filters = [];
Expand All @@ -300,17 +300,15 @@ export const SearchFilters: FC<SearchFilterProps> = ({
});
}

// National filter
// Specification filter
if (
search.request.facetValues?.some(
(t: SearchFacetValue) => t.facet === ESRdfType.national_data,
)
search.request.facetValues?.some((t: SearchFacetValue) => t.facet === ESRdfType.spec)
) {
filters.push({
id: "national_only",
label: t(`resources|${national}`),
id: "spec_only",
label: t(`resources|${spec}`),
facetValue: search.request.facetValues.find(
(t: SearchFacetValue) => t.facet === ESRdfType.national_data,
(t) => t.facet === ESRdfType.spec,
),
});
}
Expand Down Expand Up @@ -409,7 +407,7 @@ export const SearchFilters: FC<SearchFilterProps> = ({
)
: value?.facetValues.slice(0, show);

if (key !== hvd && key !== national) {
if (key !== hvd && key !== spec) {
return (
<li
key={`${value.title}-${idx}`}
Expand Down Expand Up @@ -448,7 +446,7 @@ export const SearchFilters: FC<SearchFilterProps> = ({
/>
)}
</>
)}
)}
{/* List of filter options within this category */}
<ul role="listbox" aria-multiselectable="true">
{facetValues
Expand Down Expand Up @@ -527,28 +525,15 @@ export const SearchFilters: FC<SearchFilterProps> = ({
</SearchFilter>
</li>
);
} else if (key === hvd) {
return (
<SearchCheckboxFilter
key={key}
id="hvd_only"
name="hvd"
checked={activeCheckboxFilters.some(
(filter) => filter.id === "hvd_only",
)}
onChange={() => doSearch(key, facetValues[0])}
label={t(`resources|${key}`)}
iconSize={iconSize}
/>
);
} else if (key === national) {
} else {
const filterConfig = checkBoxFilterConfigs[key];
return (
<SearchCheckboxFilter
key={key}
id="national_only"
name="National"
id={filterConfig.id}
name={filterConfig.name}
checked={activeCheckboxFilters.some(
(filter) => filter.id === "national_only",
(filter) => filter.id === filterConfig.id,
)}
onChange={() => doSearch(key, facetValues[0])}
label={t(`resources|${key}`)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function SearchActiveFilters({
(facetValue: SearchFacetValue, index: number) =>
facetValue.facet !==
"http://data.europa.eu/r5r/applicableLegislation" &&
facetValue.facet !== "http://purl.org/dc/terms/subject" && (
facetValue.facet !== "http://purl.org/dc/terms/conformsTo" && (
<Button
variant="filter"
size="xs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,16 @@ export function createSearchProviderSettings(env: EnvSettings, lang: string) {
resource: "http://purl.org/dc/terms/subject",
type: ESType.uri,
dcatProperty: "dcterms:subject",
indexOrder: 7,
group: "type",
},
{
resource: "http://purl.org/dc/terms/conformsTo",
type: ESType.uri,
dcatProperty: "dcterms:conformsTo",
dcatType: "choice",
dcatFilterEnabled: false,
indexOrder: 7,
indexOrder: 8,
group: "type",
},
],
Expand Down
1 change: 1 addition & 0 deletions locales/en/resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"http://publications.europa.eu/resource/authority/data-theme/TRAN": "Transport",
"http://purl.org/dc/terms/accessRights": "Access",
"http://purl.org/dc/terms/accrualPeriodicity": "Update frequency",
"http://purl.org/dc/terms/conformsTo": "Follows specification",
"http://purl.org/dc/terms/format": "Format",
"http://purl.org/dc/terms/license": "License",
"http://purl.org/dc/terms/publisher": "Organisation",
Expand Down
1 change: 1 addition & 0 deletions locales/sv/resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"http://publications.europa.eu/resource/authority/data-theme/TRAN": "Transport",
"http://purl.org/dc/terms/accessRights": "Åtkomsträttigheter",
"http://purl.org/dc/terms/accrualPeriodicity": "Uppdateringsfrekvens",
"http://purl.org/dc/terms/conformsTo": "Följer specifikation",
"http://purl.org/dc/terms/format": "Format",
"http://purl.org/dc/terms/license": "Licens",
"http://purl.org/dc/terms/publisher": "Organisation",
Expand Down
41 changes: 30 additions & 11 deletions utilities/entryscape/entryscape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,23 @@ export enum ESRdfType {
esterms_ServedByDataService = "esterms:ServedByDataService",
hvd = "http://data.europa.eu/eli/reg_impl/2023/138/oj",
agent = "http://xmlns.com/foaf/0.1/Agent",
national_data = "http://purl.org/dc/terms/subject",
spec = "http://purl.org/dc/terms/conformsTo",
}

export const checkBoxFilterConfigs: Record<
string,
{ id: string; name: string }
> = {
"http://data.europa.eu/r5r/applicableLegislation": {
id: "hvd_only",
name: "hvd",
},
"http://purl.org/dc/terms/conformsTo": {
id: "spec_only",
name: "Specification",
},
};

/* eslint-enable no-unused-vars */

export interface ESEntryField {
Expand Down Expand Up @@ -162,6 +176,13 @@ export class Entryscape {
group: facetSpec.group,
facetValues: f.values
.filter((value: ESFacetFieldValue) => {
if (
facetSpec.resource === "http://purl.org/dc/terms/subject" &&
value.name.startsWith(
"http://inspire.ec.europa.eu/metadata-codelist/TopicCategory/",
)
)
return true;
if (!value.name || value.name.trim() === "") return false;
if (!facetSpec?.dcatFilterEnabled) return true;

Expand Down Expand Up @@ -469,15 +490,6 @@ export class Entryscape {
case ESType.uri:
case ESType.wildcard:
// Special case for National basic data because all subjects might not be National basic data
if (fvalue[0].facet === "http://purl.org/dc/terms/subject") {
esQuery.uriProperty(
key,
"http://inspire.ec.europa.eu/metadata-codelist/TopicCategory/*",
null,
fvalue[0].related,
);
break;
}

esQuery.uriProperty(
key,
Expand Down Expand Up @@ -533,7 +545,14 @@ export class Entryscape {
const facetSpec = this.facetSpecification?.facets?.find(
(spec) => spec.resource === fg.predicate,
);

if (facetSpec?.resource === "http://purl.org/dc/terms/subject") {
fg.values = fg.values.filter(
(v: SearchFacet) =>
v.name?.startsWith(
"http://inspire.ec.europa.eu/metadata-codelist/TopicCategory",
),
);
}
if (facetSpec && facetSpec.dcatType !== "choice") {
await getUriNames(
fg.values
Expand Down
2 changes: 2 additions & 0 deletions utilities/entrystore-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export const getUriNames = async (
// TODO: This is not efficient, we need to find another way in handling this
// Process all entries at once
entries.forEach((entry: any) => {
console.log(entry);

if (entry) {
const metadata = entry.getMetadata();
const uri = entry.getResourceURI();
Expand Down
Loading

0 comments on commit 6b3c434

Please sign in to comment.