From e76b3d083f4d7a21be01a0314b40e7ffb59514ec Mon Sep 17 00:00:00 2001 From: Mika Munterud Date: Thu, 12 Dec 2024 22:06:42 +0100 Subject: [PATCH 1/2] DIGG-446: Fixing special filter checkboxes and adding access fee to organisation search --- features/search/search-filters/index.tsx | 391 +++--------------- .../search-active-filters/index.tsx | 203 ++++----- features/search/search-form/index.tsx | 7 +- features/search/search-hit/index.tsx | 2 +- .../search/search-page-selector/index.tsx | 2 +- .../search-page/search-page-content/index.tsx | 19 +- .../search-page-entryscape/index.tsx | 9 +- .../search-page-provider-settings.ts | 45 +- features/search/search-results/index.tsx | 32 +- locales/en/common.json | 1 + locales/en/resources.json | 7 +- locales/sv/common.json | 1 + locales/sv/resources.json | 7 +- providers/search-provider/index.tsx | 155 +------ types/entrystore-core.ts | 21 +- types/search.d.ts | 7 + utilities/entryscape/blocks/datasets.ts | 20 +- utilities/entryscape/blocks/global.ts | 8 +- utilities/entrystore/entrystore.service.ts | 53 ++- utilities/scroll-helper.ts | 17 + 20 files changed, 339 insertions(+), 668 deletions(-) create mode 100644 utilities/scroll-helper.ts diff --git a/features/search/search-filters/index.tsx b/features/search/search-filters/index.tsx index 93bfd77e0..2ca0c4cc9 100644 --- a/features/search/search-filters/index.tsx +++ b/features/search/search-filters/index.tsx @@ -21,12 +21,9 @@ import { TextInput } from "@/components/form/text-input"; import { SearchFilter } from "@/features/search/search-filters/search-filter"; import { SearchContextData } from "@/providers/search-provider"; import { SettingsContext } from "@/providers/settings-provider"; -import { - checkBoxFilterConfigs, - ESRdfType, - ESType, -} from "@/types/entrystore-core"; +import { ESRdfType } from "@/types/entrystore-core"; import { SearchFacet, SearchFacetValue } from "@/types/search"; +import { clearCurrentScrollPos } from "@/utilities/scroll-helper"; import { SearchActiveFilters } from "./search-active-filters"; import { @@ -43,12 +40,6 @@ interface SearchFilterProps { showTip?: boolean; } -interface MarkAllProps { - search: SearchContextData; - toggleKey: string; - title: string; -} - interface FilterSearchProps { filterKey: string; filter: InputFilter; @@ -75,12 +66,6 @@ const FilterSearch: FC = ({ }) => { const { t } = useTranslation("pages"); - const clearCurrentScrollPos = () => { - if (typeof localStorage != "undefined" && typeof location != "undefined") { - localStorage.setItem(`ScrollposY_${location.search}`, "0"); - } - }; - return (
= ({ ); }; -const MarkAll: FC = ({ search, toggleKey, title }) => { - return ( -
- -
- ); -}; - const FindFilters = ( categoryFilters: SearchFacetValue[], checkedFilters: SearchFacetValue[] | undefined, @@ -213,12 +154,6 @@ export const SearchFilters: FC = ({ }; }, [showFilter]); - const clearCurrentScrollPos = () => { - if (typeof localStorage != "undefined" && typeof location != "undefined") { - localStorage.setItem(`ScrollposY_${location.search}`, "0"); - } - }; - const selected = (key: string, facetValue: SearchFacetValue) => { return search.facetSelected(key, facetValue.resource); }; @@ -228,19 +163,6 @@ export const SearchFilters: FC = ({ await search.toggleFacet(facetValue); - if (search.facetSelected(key, "*")) { - const wildcardFacet: SearchFacetValue = { - count: -1, - facet: key, - facetType: ESType.wildcard, - related: false, - facetValueString: "", - resource: "*", - title: t(`filters|allchecktext$${key}`), - }; - await search.toggleFacet(wildcardFacet); - } - await search.doSearch(false, true, false); if (selected(key, facetValue)) { @@ -284,134 +206,6 @@ export const SearchFilters: FC = ({ return grouped; }, [searchMode, search.allFacets]); - const hvd = "http://data.europa.eu/r5r/applicableLegislation"; - const national_data = "http://purl.org/dc/terms/subject"; - const specifications = "http://purl.org/dc/terms/conformsTo"; - - const activeCheckboxFilters = useMemo(() => { - const filters = []; - - // HVD filter - if ( - search.request.facetValues?.some( - (t: SearchFacetValue) => t.title === ESRdfType.hvd, - ) - ) { - filters.push({ - id: "hvd_only", - label: t(`resources|${hvd}`), - facetValue: search.request.facetValues.find( - (t: SearchFacetValue) => t.title === ESRdfType.hvd, - ), - }); - } - - // National filter - if ( - search.request.facetValues?.some( - (t: SearchFacetValue) => t.facet === ESRdfType.national_data, - ) - ) { - filters.push({ - id: "national_only", - label: t(`resources|${national_data}`), - facetValue: search.request.facetValues.find( - (t: SearchFacetValue) => t.facet === ESRdfType.national_data, - ), - }); - } - - // Specification filter - if ( - search.request.facetValues?.some( - (t: SearchFacetValue) => t.facet === ESRdfType.spec, - ) - ) { - filters.push({ - id: "spec_only", - label: t(`resources|${specifications}`), - facetValue: search.request.facetValues.find( - (t) => t.facet === ESRdfType.spec, - ), - }); - } - - // Dataset series filter - if ( - searchMode === "datasets" && - search.request.esRdfTypes?.length === 1 && - search.request.esRdfTypes[0] === ESRdfType.dataset_series - ) { - filters.push({ - id: "dataset_series_only", - label: t(`resources|dataset-series`), - isSpecialFilter: true, - }); - } - - // API only filter - if ( - searchMode === "datasets" && - search.request.esRdfTypes?.some( - (t: ESRdfType) => t === ESRdfType.served_by_data_service, - ) && - search.request.esRdfTypes?.some( - (t: ESRdfType) => t === ESRdfType.data_service, - ) && - !search.request.esRdfTypes?.some( - (t: ESRdfType) => t === ESRdfType.dataset, - ) - ) { - filters.push({ - id: "api_only", - label: t(`resources|api`), - isSpecialFilter: true, - }); - } - - return filters; - }, [search.request.facetValues, search.request.esRdfTypes, searchMode]); - - const handleFilterChange = ( - isApiFilter: boolean, - isChecked: boolean, - currentTypes: ESRdfType[], - ) => { - // Remove all relevant types first - const baseTypes = currentTypes.filter( - (type) => - ![ - ESRdfType.dataset, - ESRdfType.data_service, - ESRdfType.served_by_data_service, - ESRdfType.dataset_series, - ].includes(type), - ); - - // Check which filters are active - const hasApiFilter = isApiFilter - ? !isChecked - : activeCheckboxFilters.some((f) => f.id === "api_only"); - const hasSeriesFilter = !isApiFilter - ? !isChecked - : activeCheckboxFilters.some((f) => f.id === "dataset_series_only"); - - // Build new types array based on filter states - const newTypes = [...baseTypes]; - - if (hasApiFilter) { - newTypes.push(ESRdfType.data_service, ESRdfType.served_by_data_service); - } - if (hasSeriesFilter) { - newTypes.push(ESRdfType.dataset_series); - } - if (!hasApiFilter && !hasSeriesFilter) { - newTypes.push(ESRdfType.dataset); - } - - return newTypes; - }; - return (
= ({ {Object.entries(groupFacets) .sort((a, b) => (a[1].indexOrder > b[1].indexOrder ? 1 : -1)) .map(([key, value], idx: number) => { - const isLicense = false; const shouldFetchMore = value.show <= value.count; const show = (value && value.show) || 20; const facetValues = inputFilter[key] @@ -482,11 +275,7 @@ export const SearchFilters: FC = ({ ) : value?.facetValues.slice(0, show); - if ( - key !== hvd && - key !== national_data && - key !== specifications - ) { + if (!value.specialFilter && !value.specialSearch) { return (
  • = ({ )} >
    - {(searchMode == "datasets" || - searchMode == "specifications" || - searchMode == "organisations") && ( - //only render on searchpage - <> - {isLicense ? ( - - ) : ( - - shouldFetchMore && - search.fetchMoreFacets(key) - } - /> - )} - - )} + + shouldFetchMore && search.fetchMoreFacets(key) + } + /> + {/* List of filter options within this category */}
      {facetValues @@ -605,108 +379,59 @@ export const SearchFilters: FC = ({ ); } else { - const filterConfig = checkBoxFilterConfigs[key]; return ( filter.id === filterConfig.id, - )} - onChange={() => doSearch(key, facetValues[0])} + id={value.predicate} + name={value.title} + checked={ + value.specialFilter + ? search.facetSelected( + key, + value?.specialFilter || "", + ) + : value.specialSearch?.length === + search.request.esRdfTypes?.length && + value.specialSearch?.every( + (type) => + search.request.esRdfTypes?.includes(type), + ) + } + onChange={() => { + if (value.specialSearch) { + clearCurrentScrollPos(); + if ( + value.specialSearch !== + search.request.esRdfTypes + ) { + search + .set({ + esRdfTypes: value.specialSearch, + query, + }) + .then(() => search.doSearch()); + } else { + search + .set({ + esRdfTypes: [ + ESRdfType.dataset, + ESRdfType.data_service, + ESRdfType.dataset_series, + ], + query, + }) + .then(() => search.doSearch()); + } + } else { + doSearch(key, facetValues[0]); + } + }} label={t(`resources|${key}`)} iconSize={iconSize} /> ); } })} - - {searchMode == "datasets" && groupName == "distribution" && ( - <> - filter.id === "api_only", - )} - onChange={() => { - clearCurrentScrollPos(); - if ( - activeCheckboxFilters.some( - (filter) => filter.id === "api_only", - ) - ) { - const newTypes = handleFilterChange( - true, - activeCheckboxFilters.some( - (filter) => filter.id === "api_only", - ), - search.request.esRdfTypes || [], - ); - search - .set({ - esRdfTypes: newTypes, - query: query, - }) - .then(() => search.doSearch()); - } else { - search - .set({ - esRdfTypes: [ - ESRdfType.data_service, - ESRdfType.served_by_data_service, - ], - query: query, - }) - .then(() => search.doSearch()); - } - }} - label={t(`resources|api`)} - iconSize={iconSize} - /> - filter.id === "dataset_series_only", - )} - onChange={() => { - clearCurrentScrollPos(); - if ( - activeCheckboxFilters.some( - (filter) => filter.id === "dataset_series_only", - ) - ) { - const newTypes = handleFilterChange( - false, - activeCheckboxFilters.some( - (filter) => filter.id === "dataset_series_only", - ), - search.request.esRdfTypes || [], - ); - search - .set({ - esRdfTypes: newTypes, - query: query, - }) - .then(() => search.doSearch()); - } else { - search - .set({ - esRdfTypes: [ESRdfType.dataset_series], - query: query, - }) - .then(() => search.doSearch()); - } - }} - label={t(`resources|dataset-series`)} - iconSize={iconSize} - /> - - )}
    ))} @@ -716,7 +441,6 @@ export const SearchFilters: FC = ({ search={search} query={query} searchMode={searchMode} - activeCheckboxFilters={activeCheckboxFilters} />
  • @@ -727,7 +451,6 @@ export const SearchFilters: FC = ({ search={search} query={query} searchMode={searchMode} - activeCheckboxFilters={activeCheckboxFilters} />
    ); diff --git a/features/search/search-filters/search-active-filters/index.tsx b/features/search/search-filters/search-active-filters/index.tsx index 3d511f95b..f94565a4f 100644 --- a/features/search/search-filters/search-active-filters/index.tsx +++ b/features/search/search-filters/search-active-filters/index.tsx @@ -8,6 +8,7 @@ import { SearchContextData } from "@/providers/search-provider"; import { SettingsContext } from "@/providers/settings-provider"; import { ESRdfType } from "@/types/entrystore-core"; import { SearchFacetValue } from "@/types/search"; +import { clearCurrentScrollPos } from "@/utilities/scroll-helper"; import { SearchMode } from "../index"; @@ -15,37 +16,40 @@ interface SearchActiveFiltersProps { search: SearchContextData; query: string; searchMode: SearchMode; - activeCheckboxFilters: Array<{ - id: string; - label: string; - facetValue?: SearchFacetValue; - isSpecialFilter?: boolean; - }>; } export function SearchActiveFilters({ search, query, searchMode, - activeCheckboxFilters, }: SearchActiveFiltersProps) { const { t } = useTranslation(); const { iconSize } = useContext(SettingsContext); - const clearCurrentScrollPos = () => { - if (typeof localStorage != "undefined" && typeof location != "undefined") { - localStorage.setItem(`ScrollposY_${location.search}`, "0"); - } - }; + // Create an array of active special search filters + const activeSpecialSearchFilters = Object.entries(search.allFacets || {}) + .filter( + // eslint-disable-next-line @typescript-eslint/no-unused-vars + ([_, facet]) => + facet.specialSearch && + facet.specialSearch.length === search.request.esRdfTypes?.length && + facet.specialSearch.every( + (type) => search.request.esRdfTypes?.includes(type), + ), + ) + .map(([key, facet]) => ({ + facet: key, + title: facet.title, + specialSearch: facet.specialSearch, + })); - const hasActiveFilters = () => { - return ( - (search.request.facetValues && search.request.facetValues.length > 0) || - activeCheckboxFilters.length > 0 - ); - }; + const hasActiveFilters = + (search.request.facetValues && search.request.facetValues.length > 0) || + activeSpecialSearchFilters.length > 0; - if (!hasActiveFilters()) return null; + if (!hasActiveFilters) { + return null; + } return (
    @@ -54,95 +58,110 @@ export function SearchActiveFilters({
    {search.request.facetValues?.map( - (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" && ( -
    - - {((search.request.facetValues && - search.request.facetValues.length >= 2) || - activeCheckboxFilters.length >= 2) && ( -
    -
    - )} + ))} + + {search.request.facetValues && + search.request.facetValues.length >= 2 && ( +
    ); } diff --git a/features/search/search-form/index.tsx b/features/search/search-form/index.tsx index 0a96db94c..b29fafba6 100644 --- a/features/search/search-form/index.tsx +++ b/features/search/search-form/index.tsx @@ -4,6 +4,7 @@ import { Dispatch, SetStateAction, FC } from "react"; import { SearchMode } from "@/features/search/search-filters"; import { SearchInput } from "@/features/search/search-input"; import { SearchContextData } from "@/providers/search-provider"; +import { clearCurrentScrollPos } from "@/utilities/scroll-helper"; interface SearchFormProps { search: SearchContextData; @@ -28,12 +29,6 @@ export const SearchForm: FC = ({ const placeholder = t(`pages|${searchMode}$search`); - const clearCurrentScrollPos = () => { - if (typeof localStorage != "undefined" && typeof location != "undefined") { - localStorage.setItem(`ScrollposY_${location.search}`, "0"); - } - }; - const submitSearch = (newQuery: string) => { search .set({ diff --git a/features/search/search-hit/index.tsx b/features/search/search-hit/index.tsx index f5c981a84..e9184b15c 100644 --- a/features/search/search-hit/index.tsx +++ b/features/search/search-hit/index.tsx @@ -40,7 +40,7 @@ export const SearchHit: FC = ({ = () => { setLoading(false); }; - const clearCurrentScrollPos = () => { - if (typeof localStorage != "undefined" && typeof location != "undefined") { - localStorage.setItem(`ScrollposY_${location.search}`, "0"); - } - }; - - const saveCurrentScrollPos = () => { - if (typeof localStorage != "undefined" && typeof location != "undefined") { - localStorage.setItem( - `ScrollposY_${location.search}`, - JSON.stringify(window.scrollY), - ); - } - }; - const highlightWords = (text: string) => { if (!text) return; diff --git a/features/search/search-page/search-page-entryscape/index.tsx b/features/search/search-page/search-page-entryscape/index.tsx index b60b592ca..34e4a67c4 100644 --- a/features/search/search-page/search-page-entryscape/index.tsx +++ b/features/search/search-page/search-page-entryscape/index.tsx @@ -15,6 +15,7 @@ import { SearchTips } from "@/features/search/search-tips"; import SearchProvider, { SearchContext } from "@/providers/search-provider"; import { SettingsContext } from "@/providers/settings-provider"; import { linkBase } from "@/utilities"; +import { clearCurrentScrollPos } from "@/utilities/scroll-helper"; import { createSearchProviderSettings } from "./search-page-provider-settings"; @@ -25,19 +26,13 @@ interface SearchProps { export const SearchPageEntryscape: FC = ({ searchType }) => { const { env, setBreadcrumb } = useContext(SettingsContext); - const { pathname, query: routerQuery } = useRouter() || {}; + const { pathname } = useRouter() || {}; const { t, lang } = useTranslation(); const [query, setQuery] = useState(""); const [showFilter, setShowFilter] = useState(false); const [showTip, setShowTip] = useState(false); const router = useRouter(); - const clearCurrentScrollPos = () => { - if (typeof localStorage != "undefined") { - localStorage.setItem(`ScrollposY_${routerQuery}`, "0"); - } - }; - useEffect(() => { if (typeof window === "undefined") return; 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 d15a70278..7cf76fad3 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 @@ -13,6 +13,8 @@ interface FacetConfig { dcatId?: string; related?: boolean; maschineName?: string; + specialFilter?: string; // Special case for special filters with checkbox + specialSearch?: ESRdfType[]; // Special case for special filters with search } interface HitSpecification { @@ -32,7 +34,7 @@ interface SearchProviderConfig { language: string; takeFacets: number; sortOrder?: SearchSortOrder; - // Values to exclude from search + // Values to exclude or include from search filters?: { exclude?: { key: string; @@ -119,7 +121,7 @@ export function createSearchProviderSettings(env: EnvSettings, lang: string) { }, { resource: "http://purl.org/dc/terms/accrualPeriodicity", - dcatId: "dcat:dcterms:accrualPeriodicity_da", + dcatId: "dcat:dcterms:accrualPeriodicity", type: ESType.uri, dcatProperty: "dcterms:accrualPeriodicity", dcatType: "choice", @@ -135,6 +137,7 @@ export function createSearchProviderSettings(env: EnvSettings, lang: string) { dcatFilterEnabled: false, indexOrder: 6, group: "type", + specialFilter: "http://data.europa.eu/eli/reg_impl/2023/138/oj", }, { resource: "http://purl.org/dc/terms/subject", @@ -142,6 +145,8 @@ export function createSearchProviderSettings(env: EnvSettings, lang: string) { dcatProperty: "dcterms:subject", indexOrder: 7, group: "type", + specialFilter: + "http://inspire.ec.europa.eu/metadata-codelist/TopicCategory/*", }, { resource: "http://purl.org/dc/terms/conformsTo", @@ -151,6 +156,30 @@ export function createSearchProviderSettings(env: EnvSettings, lang: string) { dcatFilterEnabled: false, indexOrder: 8, group: "type", + specialFilter: "*", + }, + { + resource: "http://www.w3.org/ns/dcat#DataService", + type: ESType.uri, + dcatProperty: "dcat:DataService", + dcatType: "choice", + dcatFilterEnabled: false, + indexOrder: 8, + group: "distribution", + specialSearch: [ + ESRdfType.data_service, + ESRdfType.served_by_data_service, + ], + }, + { + resource: "http://www.w3.org/ns/dcat#DatasetSeries", + type: ESType.uri, + dcatProperty: "dcat:DatasetSeries", + dcatType: "choice", + dcatFilterEnabled: false, + indexOrder: 9, + group: "distribution", + specialSearch: [ESRdfType.dataset_series], }, ], }, @@ -278,13 +307,21 @@ export function createSearchProviderSettings(env: EnvSettings, lang: string) { type: ESType.uri, dcatType: "choice", indexOrder: 1, - maschineName: "publishertype", group: "default", }, + { + resource: "https://www.w3.org/ns/org#classification", + dcatProperty: "org:classification", + type: ESType.uri, + indexOrder: 2, + group: "default", + specialFilter: + "https://dataportal.se/concepts/orgAspects/feeFinanzing", + }, ], }, initRequest: { - esRdfTypes: [ESRdfType.agent], + esRdfTypes: [ESRdfType.organisation], language: lang, takeFacets: 30, filters: { diff --git a/features/search/search-results/index.tsx b/features/search/search-results/index.tsx index 65eb11931..cd59d38f6 100644 --- a/features/search/search-results/index.tsx +++ b/features/search/search-results/index.tsx @@ -21,6 +21,11 @@ import { SearchContextData, } from "@/providers/search-provider"; import { SettingsContext } from "@/providers/settings-provider"; +import { + clearCurrentScrollPos, + getScrollKey, + saveCurrentScrollPos, +} from "@/utilities/scroll-helper"; interface SearchResultsProps { search: SearchContextData; @@ -44,24 +49,6 @@ const searchFocus = () => { } }; -const SCROLL_POS_PREFIX = "ScrollPosY_" as const; - -function getScrollKey(search: string): string { - return `${SCROLL_POS_PREFIX}${search}`; -} - -function saveCurrentScrollPos(): void { - if (typeof window === "undefined") return; - const key = getScrollKey(window.location.search); - localStorage.setItem(key, window.scrollY.toString()); -} - -function clearCurrentScrollPos(): void { - if (typeof window === "undefined") return; - const key = getScrollKey(window.location.search); - localStorage.removeItem(key); -} - /** * Adds sorting options to the search-results * @@ -76,11 +63,6 @@ const SortingOptions: FC<{ const { t } = useTranslation(); const { iconSize } = useContext(SettingsContext); - const toggleCompact = () => { - clearCurrentScrollPos(); - setCompact(!isCompact); - }; - return (
    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 7cf76fad3..0ce9c7fac 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 @@ -13,8 +13,9 @@ interface FacetConfig { dcatId?: string; related?: boolean; maschineName?: string; - specialFilter?: string; // Special case for special filters with checkbox - specialSearch?: ESRdfType[]; // Special case for special filters with search + showInSearchResult?: boolean; + customFilter?: string; // Special case for special filters with checkbox + customSearch?: ESRdfType[]; // Special case for special filters with search } interface HitSpecification { @@ -137,7 +138,8 @@ export function createSearchProviderSettings(env: EnvSettings, lang: string) { dcatFilterEnabled: false, indexOrder: 6, group: "type", - specialFilter: "http://data.europa.eu/eli/reg_impl/2023/138/oj", + customFilter: "http://data.europa.eu/eli/reg_impl/2023/138/oj", + showInSearchResult: true, }, { resource: "http://purl.org/dc/terms/subject", @@ -145,8 +147,9 @@ export function createSearchProviderSettings(env: EnvSettings, lang: string) { dcatProperty: "dcterms:subject", indexOrder: 7, group: "type", - specialFilter: + customFilter: "http://inspire.ec.europa.eu/metadata-codelist/TopicCategory/*", + showInSearchResult: true, }, { resource: "http://purl.org/dc/terms/conformsTo", @@ -156,7 +159,7 @@ export function createSearchProviderSettings(env: EnvSettings, lang: string) { dcatFilterEnabled: false, indexOrder: 8, group: "type", - specialFilter: "*", + customFilter: "*", }, { resource: "http://www.w3.org/ns/dcat#DataService", @@ -166,7 +169,7 @@ export function createSearchProviderSettings(env: EnvSettings, lang: string) { dcatFilterEnabled: false, indexOrder: 8, group: "distribution", - specialSearch: [ + customSearch: [ ESRdfType.data_service, ESRdfType.served_by_data_service, ], @@ -179,7 +182,7 @@ export function createSearchProviderSettings(env: EnvSettings, lang: string) { dcatFilterEnabled: false, indexOrder: 9, group: "distribution", - specialSearch: [ESRdfType.dataset_series], + customSearch: [ESRdfType.dataset_series], }, ], }, @@ -315,7 +318,7 @@ export function createSearchProviderSettings(env: EnvSettings, lang: string) { type: ESType.uri, indexOrder: 2, group: "default", - specialFilter: + customFilter: "https://dataportal.se/concepts/orgAspects/feeFinanzing", }, ], diff --git a/providers/search-provider/index.tsx b/providers/search-provider/index.tsx index e26c7cbb7..a6d058e82 100644 --- a/providers/search-provider/index.tsx +++ b/providers/search-provider/index.tsx @@ -454,7 +454,7 @@ class SearchProvider extends Component { return facetValues.some( (facetValue) => facetValue.facet === key && - (facetValue.resource === value || facetValue.specialFilter === value), + (facetValue.resource === value || facetValue.customFilter === value), ); }; @@ -572,8 +572,8 @@ class SearchProvider extends Component { v.facet == facetValue.facet && v.resource == facetValue.resource && v.related == facetValue.related && - v.specialFilter == facetValue.specialFilter && - v.specialSearch == facetValue.specialSearch, + v.customFilter == facetValue.customFilter && + v.customSearch == facetValue.customSearch, ); let newFacetValues: SearchFacetValue[]; @@ -699,9 +699,9 @@ class SearchProvider extends Component { related: facetstring[2] === "true", resource: facetstring[1], title: facetstring[5], - specialFilter: + customFilter: facetstring[6] !== "undefined" ? facetstring[6] : undefined, - specialSearch: + customSearch: facetstring[7] && facetstring[7] !== "undefined" ? JSON.parse(facetstring[7]) : undefined, diff --git a/types/search.d.ts b/types/search.d.ts index 3a69eb9d6..e42e51c1c 100644 --- a/types/search.d.ts +++ b/types/search.d.ts @@ -42,8 +42,9 @@ export interface FacetSpecificationItem { dcatId?: string; dcatType?: string; dcatFilterEnabled?: boolean; - specialFilter?: string; - specialSearch?: ESRdfType[]; + customFilter?: string; + customSearch?: ESRdfType[]; + showInSearchResult?: boolean; } export interface SearchResult { @@ -78,8 +79,8 @@ interface SearchFacet { group: string; indexOrder: number; resource?: string; - specialFilter?: string; - specialSearch?: ESRdfType[]; + customFilter?: string; + customSearch?: ESRdfType[]; } export interface SearchFacetValue { @@ -90,8 +91,8 @@ export interface SearchFacetValue { count: number; facetValueString: string; related: boolean; - specialFilter?: string; - specialSearch?: ESRdfType[]; + customFilter?: string; + customSearch?: ESRdfType[]; } export interface SearchRequest { diff --git a/utilities/entrystore/entrystore.service.ts b/utilities/entrystore/entrystore.service.ts index 3a3c48693..e4cfd55b8 100644 --- a/utilities/entrystore/entrystore.service.ts +++ b/utilities/entrystore/entrystore.service.ts @@ -214,14 +214,14 @@ export class EntrystoreService { case ESType.literal: case ESType.literal_s: // Special case for special filters with search checkbox - if (fvalue[0].specialSearch) { + if (fvalue[0].customSearch) { break; } // Special case for special filters with regular checkbox - if (fvalue[0].specialFilter) { + if (fvalue[0].customFilter) { esQuery.literalProperty( key, - fvalue[0].specialFilter, + fvalue[0].customFilter, null, "string", fvalue[0].related, @@ -239,14 +239,14 @@ export class EntrystoreService { case ESType.uri: case ESType.wildcard: // Special case for special filters with search checkbox - if (fvalue[0].specialSearch) { + if (fvalue[0].customSearch) { break; } // Special case for special filters with regular checkbox - if (fvalue[0].specialFilter) { + if (fvalue[0].customFilter) { esQuery.uriProperty( key, - fvalue[0].specialFilter, + fvalue[0].customFilter, null, fvalue[0].related, ); @@ -445,8 +445,8 @@ export class EntrystoreService { count: f.valueCount, show: 25, group: facetSpec.group, - specialFilter: facetSpec.specialFilter, - specialSearch: facetSpec.specialSearch, + customFilter: facetSpec.customFilter, + customSearch: facetSpec.customSearch, facetValues: f.values .filter((value: ESFacetFieldValue) => { if (!value.name || value.name.trim() === "") return false; @@ -487,17 +487,17 @@ export class EntrystoreService { facetValueString: `${f.predicate}||${value.name}||${ facetSpec.related || false }||${f.type}||${this.t(f.predicate)}||${displayName}||${ - facetSpec.specialFilter + facetSpec.customFilter }||${ - facetSpec.specialSearch - ? JSON.stringify(facetSpec.specialSearch) + facetSpec.customSearch + ? JSON.stringify(facetSpec.customSearch) : undefined }`, related: facetSpec.related || false, resource: value.name, title: displayName, - specialFilter: facetSpec.specialFilter, - specialSearch: facetSpec.specialSearch, + customFilter: facetSpec.customFilter, + customSearch: facetSpec.customSearch, }; }), }; @@ -527,8 +527,8 @@ export class EntrystoreService { count: f.valueCount, show: 25, group: facetSpec.group, - specialFilter: facetSpec.specialFilter, - specialSearch: facetSpec.specialSearch, + customFilter: facetSpec.customFilter, + customSearch: facetSpec.customSearch, facetValues: f.values .filter((value: ESFacetFieldValue) => { if (!value.name || value.name.trim() === "") return false; @@ -569,17 +569,17 @@ export class EntrystoreService { facetValueString: `${f.predicate}||${value.name}||${ facetSpec.related || false }||${f.type}||${this.t(f.predicate)}||${displayName}||${ - facetSpec.specialFilter || null + facetSpec.customFilter || null }||${ - facetSpec.specialSearch - ? JSON.stringify(facetSpec.specialSearch) + facetSpec.customSearch + ? JSON.stringify(facetSpec.customSearch) : undefined }`, related: facetSpec.related || false, resource: value.name, title: displayName, - specialFilter: facetSpec.specialFilter, - specialSearch: facetSpec.specialSearch, + customFilter: facetSpec.customFilter, + customSearch: facetSpec.customSearch, }; }), }; @@ -665,6 +665,35 @@ export class EntrystoreService { .map((f: any) => this.t(f.getValue())); } + // Adding custom facets with showInSearchResult true to format_literal if they are present in the metadata + const customFacets = this.facetSpecification?.facets?.filter( + (spec) => spec.showInSearchResult, + ); + + if (customFacets && customFacets.length > 0) { + for (const facet of customFacets) { + const hasResource = metadata + .find(entry.getResourceURI(), facet.resource) + .some((f: any) => + f + .getValue() + .startsWith( + facet?.customFilter?.endsWith("*") + ? facet?.customFilter?.slice(0, -1) + : facet?.customFilter, + ), + ); + + if (hasResource) { + // Add the translated resource URI to format_literal array + values["format_literal"] = [ + ...(values["format_literal"] || []), + this.t(`resources|${facet.resource}`), + ]; + } + } + } + const inSchemeUris = metadata.findFirstValue( null, "http://www.w3.org/2004/02/skos/core#inScheme",