Skip to content

Commit

Permalink
fix: Theme filtering needs to happen in HAVING part of the query
Browse files Browse the repository at this point in the history
  • Loading branch information
bprusinowski committed Oct 31, 2023
1 parent 67c6bdc commit 056c640
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions app/rdf/query-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const searchCubes = async ({
?.filter((x) => x.type === "DataCubeOrganization")
.map((v) => v.value) ?? [];

const scoresQuery = SELECT`
let scoresQuery = SELECT`
?iri ?title ?status ?datePublished ?description ?publisher ?creatorIri ?creatorLabel
(GROUP_CONCAT(DISTINCT ?themeIri; SEPARATOR="${GROUP_SEPARATOR}") AS ?themeIris) (GROUP_CONCAT(DISTINCT ?themeLabel; SEPARATOR="${GROUP_SEPARATOR}") AS ?themeLabels)
(GROUP_CONCAT(DISTINCT ?subthemeIri; SEPARATOR="${GROUP_SEPARATOR}") AS ?subthemeIris) (GROUP_CONCAT(DISTINCT ?subthemeLabel; SEPARATOR="${GROUP_SEPARATOR}") AS ?subthemeLabels)
Expand Down Expand Up @@ -152,7 +152,7 @@ export const searchCubes = async ({
)}
}
}
${makeInFilter("creatorIri", creatorValues)}
${creatorValues.length ? makeInFilter("creatorIri", creatorValues) : ""}
OPTIONAL {
?iri ${ns.dcat.theme} ?themeIri .
Expand All @@ -166,7 +166,6 @@ export const searchCubes = async ({
})}
}
}
${makeInFilter("themeIri", themeValues)}
# Add more subtheme termsets here when they are available
${
Expand Down Expand Up @@ -238,11 +237,16 @@ export const searchCubes = async ({
)`
: ""
}
`.GROUP().BY`?iri`.THEN.BY`?title`.THEN.BY`?status`.THEN.BY`?datePublished`
.THEN.BY`?description`.THEN.BY`?publisher`.THEN.BY`?creatorIri`.THEN
.BY`?creatorLabel`.prologue`${pragmas}`;

if (themeValues.length) {
scoresQuery = scoresQuery.HAVING`${themeValues
.map((iri) => `CONTAINS(LCASE(?themeIris), LCASE("${iri}"))`)
.join(" || ")}` as any;
}

const scoreResults = await scoresQuery.execute(sparqlClient.query, {
operation: "postUrlencoded",
});
Expand Down

0 comments on commit 056c640

Please sign in to comment.