Skip to content

Commit

Permalink
DIGG:446: Updating filter search for organisation classification
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaMunterud committed Dec 18, 2024
1 parent f4d75c7 commit 94987ab
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 78 deletions.
4 changes: 2 additions & 2 deletions features/entryscape/organisation-page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export const OrganisationPage: FC = () => {
</Heading>
{entry.contact && entry.contact.email ? (
<CustomLink
className="text-green-600 hover:no-underline"
className="text-sm text-green-600 hover:no-underline"
href={entry.contact.email}
>
{entry.contact.name}
Expand Down Expand Up @@ -263,7 +263,7 @@ export const OrganisationPage: FC = () => {
>
{t("pages|organisation_page$org-no")}
</Heading>
<p>{entry.organisationData?.orgClassification}</p>
<p>{entry.organisationData.orgNumber}</p>
</div>
)}

Expand Down
4 changes: 2 additions & 2 deletions features/search/search-filters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const FilterSearch: FC<FilterSearchProps> = ({
);
};

const FindFilters = (
const findFilters = (
categoryFilters: SearchFacetValue[],
checkedFilters: SearchFacetValue[] | undefined,
) => {
Expand Down Expand Up @@ -307,7 +307,7 @@ export const SearchFilters: FC<SearchFilterProps> = ({
>
<SearchFilter
title={value.title}
usedFilters={FindFilters(
usedFilters={findFilters(
value.facetValues,
search.request.facetValues,
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,8 @@ export function createSearchProviderSettings(env: EnvSettings, lang: string) {
indexOrder: 7,
group: "type",
showInSearchResult: true,
customProperties: [
"http://inspire.ec.europa.eu/metadata-codelist/TopicCategory/",
],
customFilter:
"http://inspire.ec.europa.eu/metadata-codelist/TopicCategory/*",
},
{
resource: "http://purl.org/dc/terms/conformsTo",
Expand Down
2 changes: 1 addition & 1 deletion providers/search-provider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ class SearchProvider extends Component<SearchProviderProps, SearchContextData> {
if (!f.includes("||")) return;

const facetstring = f.split("||");
if (facetstring.length !== 9) return;
if (facetstring.length < 6) return;

let facetType = ESType.unknown;
switch (facetstring[3]) {
Expand Down
155 changes: 85 additions & 70 deletions utilities/entrystore/entrystore.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,76 +456,91 @@ export class EntrystoreService {
customFilter: f.customFilter,
customLabel: f.customLabel,
customSearch: f.customSearch,
facetValues: metaFacet.values
.filter((value: ESFacetFieldValue) => {
if (f.customProperties && f.customProperties.length > 0) {
return f.customProperties.some((property) =>
value.name.startsWith(property),
);
}
if (!value.name || value.name.trim() === "") return false;
if (!f?.dcatFilterEnabled) return true;

const choices: Choice[] = getTemplateChoices(
dcat,
f.dcatProperty,
f.dcatId,
);
return choices.some(
(choice: Choice) => choice.value === value.name,
);
})

.map((value: ESFacetFieldValue) => {
let displayName = value.name;
if (f?.dcatType === "choice") {
const choices = getTemplateChoices(
dcat,
f.dcatProperty,
f.dcatId,
);
const choice = choices.find(
(c: Choice) => c.value === value.name,
);
if (choice) {
displayName = getLocalizedChoiceLabel(choice, this.lang);
}
} else {
displayName = entryCache.getValue(value.name) || value.name;
if (
displayName.startsWith("http") &&
f.customProperties &&
f.customProperties.length > 0
) {
// Find the matching custom property that the displayName starts with
const matchingProperty = f.customProperties.find((property) =>
displayName.startsWith(property),
);
// Replace only if a matching property was found
if (matchingProperty) {
displayName = displayName.replace(matchingProperty, "");
}
}
}
return {
count: value.count,
facet: metaFacet.predicate,
facetType: metaFacet.type,
facetValueString: `${metaFacet.predicate}||${value.name}||${
f.related || false
}||${metaFacet.type}||${this.t(
metaFacet.predicate,
)}||${displayName}||${f.customFilter}||${
f.customSearch ? JSON.stringify(f.customSearch) : undefined
}||${f.customLabel}`,
related: f.related || false,
resource: value.name,
title: displayName,
customFilter: f.customFilter,
customLabel: f.customLabel,
customSearch: f.customSearch,
};
}),
facetValues:
metaFacet.values.length > 0
? metaFacet.values
.filter((value: ESFacetFieldValue) => {
if (f.customProperties && f.customProperties.length > 0) {
return f.customProperties.some((property) =>
value.name.startsWith(property),
);
}
if (!value.name || value.name.trim() === "") return false;
if (!f?.dcatFilterEnabled) return true;

const choices: Choice[] = getTemplateChoices(
dcat,
f.dcatProperty,
f.dcatId,
);
return choices.some(
(choice: Choice) => choice.value === value.name,
);
})
.map((value: ESFacetFieldValue) => {
let displayName = value.name;
if (f?.dcatType === "choice") {
const choices = getTemplateChoices(
dcat,
f.dcatProperty,
f.dcatId,
);
const choice = choices.find(
(c: Choice) => c.value === value.name,
);
if (choice) {
displayName = getLocalizedChoiceLabel(
choice,
this.lang,
);
}
} else {
displayName =
entryCache.getValue(value.name) || value.name;
}
return {
count: value.count,
facet: metaFacet.predicate,
facetType: metaFacet.type,
facetValueString: `${metaFacet.predicate}||${
value.name
}||${f.related || false}||${metaFacet.type}||${this.t(
metaFacet.predicate,
)}||${displayName}||${f.customFilter}||${
f.customSearch
? JSON.stringify(f.customSearch)
: undefined
}||${f.customLabel}`,
related: f.related || false,
resource: value.name,
title: displayName,
customFilter: f.customFilter,
customLabel: f.customLabel,
customSearch: f.customSearch,
};
})
: [
{
count: 0,
facet: metaFacet.predicate,
facetType: metaFacet.type,
facetValueString: `${metaFacet.predicate}||${
f.customFilter
}||${f.related || false}||${metaFacet.type}||${this.t(
metaFacet.predicate,
)}||${f.customFilter}||${f.customFilter}||${
f.customSearch
? JSON.stringify(f.customSearch)
: undefined
}||${f.customLabel}`,
related: false,
resource: "",
title: "",
customFilter: f.customFilter,
customSearch: f.customSearch,
customLabel: f.customLabel,
},
],
};
}
}
Expand Down

0 comments on commit 94987ab

Please sign in to comment.