Skip to content
Snippets Groups Projects
Commit e9a6017c authored by esikkala's avatar esikkala
Browse files

Literal facet: fix selected values

parent 0795b9aa
No related branches found
No related tags found
No related merge requests found
...@@ -93,7 +93,7 @@ export const getFacet = async ({ ...@@ -93,7 +93,7 @@ export const getFacet = async ({
/* if this facet has previous selections (exluding <http://ldf.fi/MISSING_VALUE>), /* if this facet has previous selections (exluding <http://ldf.fi/MISSING_VALUE>),
they need to be binded as selected */ they need to be binded as selected */
if (currentSelectionsWithoutUnknown.length > 0 && hasPreviousSelections) { if (currentSelectionsWithoutUnknown.length > 0 && hasPreviousSelections) {
selectedBlock = generateSelectedBlock({ currentSelectionsWithoutUnknown }) selectedBlock = generateSelectedBlock({ currentSelectionsWithoutUnknown, literal: facetConfig.literal })
} }
/* if there is previous selections in this facet AND in some other facet, we need an /* if there is previous selections in this facet AND in some other facet, we need an
additional block for facet values that return 0 hits */ additional block for facet values that return 0 hits */
...@@ -104,7 +104,8 @@ export const getFacet = async ({ ...@@ -104,7 +104,8 @@ export const getFacet = async ({
facetID, facetID,
constraints, constraints,
// no defaultConstraint here // no defaultConstraint here
currentSelectionsWithoutUnknown currentSelectionsWithoutUnknown,
literal: facetConfig.literal
}) })
} }
} }
...@@ -181,11 +182,13 @@ export const getFacet = async ({ ...@@ -181,11 +182,13 @@ export const getFacet = async ({
} }
const generateSelectedBlock = ({ const generateSelectedBlock = ({
currentSelectionsWithoutUnknown currentSelectionsWithoutUnknown,
literal
}) => { }) => {
const selectedFilter = generateSelectedFilter({ const selectedFilter = generateSelectedFilter({
currentSelectionsWithoutUnknown, currentSelectionsWithoutUnknown,
inverse: false inverse: false,
literal
}) })
return ` return `
OPTIONAL { OPTIONAL {
...@@ -200,7 +203,8 @@ const generateSelectedNoHitsBlock = ({ ...@@ -200,7 +203,8 @@ const generateSelectedNoHitsBlock = ({
facetClass, facetClass,
facetID, facetID,
constraints, constraints,
currentSelectionsWithoutUnknown currentSelectionsWithoutUnknown,
literal
}) => { }) => {
const noHitsFilter = generateConstraintsBlock({ const noHitsFilter = generateConstraintsBlock({
backendSearchConfig, backendSearchConfig,
...@@ -210,11 +214,12 @@ const generateSelectedNoHitsBlock = ({ ...@@ -210,11 +214,12 @@ const generateSelectedNoHitsBlock = ({
facetID: facetID, facetID: facetID,
inverse: true inverse: true
}) })
const selections = literal ? `'${currentSelectionsWithoutUnknown.join(', ')}'` : `<${currentSelectionsWithoutUnknown.join('>, <')}>`
return ` return `
UNION UNION
# facet values that have been selected but return no results # facet values that have been selected but return no results
{ {
VALUES ?id { <${currentSelectionsWithoutUnknown.join('> <')}> } VALUES ?id { ${selections} }
${noHitsFilter} ${noHitsFilter}
BIND(true AS ?selected_) BIND(true AS ?selected_)
} }
...@@ -299,9 +304,11 @@ const getUriFilters = (constraints, facetID) => { ...@@ -299,9 +304,11 @@ const getUriFilters = (constraints, facetID) => {
export const generateSelectedFilter = ({ export const generateSelectedFilter = ({
currentSelectionsWithoutUnknown, currentSelectionsWithoutUnknown,
inverse inverse,
literal
}) => { }) => {
const selections = literal ? `'${currentSelectionsWithoutUnknown.join(', ')}'` : `<${currentSelectionsWithoutUnknown.join('>, <')}>`
return (` return (`
FILTER(?id ${inverse ? 'NOT' : ''} IN ( <${currentSelectionsWithoutUnknown.join('>, <')}> )) FILTER(?id ${inverse ? 'NOT' : ''} IN ( ${selections} ))
`) `)
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment