Defining Fixed Facets in a List or Search Result Page
The Wrapper uses the SPARQUE Desk fixedFacets endpoint to determine which fixed facets are available. For each fixed facet, a corresponding endpoint must be defined in SPARQUE Desk to enable filtering. This guide uses brand as an example. If you do not require any fixed facets, refer to Settings Through SPARQUE Hub.
Note:
Facets allow you to filter search results. With fixed facets you can “pin” these facets to the top of the facet lists of search and products calls. Fixed facets are typically created for product attribute relations which are present on product objects in SPARQUE Desk.
Data Source
First, define the data source to specify which fixed facets are available. The example below includes brand
as a facet. The code
element is used for localization, and the title
provides a user-friendly, localized name that the application can use. The optional attributes selectionType
, displayType
, position
, minCount
, limitCount
and enabled
define the rendering of the facet.
<?xml version="1.0" encoding="UTF-8"?>
<Fixedfacets>
<option>
<channel>ish</channel>
<name>brand</name>
<attribute>
<name>selectionType</name>
<value>multiple/and</value>
</attribute>
<attribute>
<name>position</name>
<value>1</value>
</attribute>
<attribute>
<name>displayType</name>
<value>checkbox</value>
</attribute>
<label>
<code>nl-NL</code>
<title>Merk</title>
</label>
<label>
<code>nl-BE</code>
<title>Merk</title>
</label>
<label>
<code>en-GB</code>
<title>Brand</title>
</label>
<label>
<code>fr-FR</code>
<title>Marque</title>
</label>
<label>
<code>de-DE</code>
<title>Marke</title>
</label>
<label>
<code>se-SE</code>
<title>Varumärke</title>
</label>
<label>
<code>en-US</code>
<title>Brand</title>
</label>
<label>
<code>en-NZ</code>
<title>Brand</title>
</label>
</option>
</Fixedfacets>
Mapping
A mapping is also necessary for the data:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:su="com.spinque.tools.importStream.Utils" xmlns:spinque="com.spinque.tools.importStream.EmitterWrapper" xmlns:wf="com.spinque.tools.extraction.generic.XSLTWrappedFunctions" extension-element-prefixes="spinque">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:variable name="rdfstype">http://www.w3.org/1999/02/22-rdf-syntax-ns#type</xsl:variable>
<xsl:variable name="prefix">https://www.sparque.ai/</xsl:variable>
<xsl:template match="option">
<xsl:variable name="channel" select="channel"/>
<xsl:variable name="optionId" select="su:uri($prefix, 'fixedfacet', $channel, name)"/>
<spinque:relation subject="{$optionId}" predicate="{$rdfstype}" object="{concat($prefix, 'fixedfacet')}"/>
<spinque:attribute subject="{$optionId}" attribute="identifier" type="string" value="{name}"/>
<xsl:for-each select="label">
<spinque:attribute subject="{$optionId}" lang="{code}" attribute="title" type="string" value="{title}"/>
</xsl:for-each>
<spinque:attribute subject="{$optionId}" attribute="displayType" type="string" value="{attribute[name='displayType']/value}"/>
<spinque:attribute subject="{$optionId}" attribute="selectionType" type="string" value="{attribute[name='selectionType']/value}"/>
<spinque:attribute subject="{$optionId}" attribute="limitCount" type="integer" value="{attribute[name='limitCount']/value}"/>
<spinque:attribute subject="{$optionId}" attribute="minCount" type="integer" value="{attribute[name='minCount']/value}"/>
<spinque:attribute subject="{$optionId}" attribute="position" type="integer" value="{attribute[name='position']/value}"/>
<spinque:attribute subject="{$optionId}" attribute="enabled" type="string" value="{attribute[name='enabled']/value}"/>
<!-- relation to channel -->
<xsl:variable name="channelobject" select="su:uri($prefix, 'channel', $channel)"/>
<spinque:relation subject="{$optionId}" predicate="fixedfacet-channel" object="{$channelobject}"/>
</xsl:template>
</xsl:stylesheet>

API Endpoints
Endpoint fixedFacets
The fixedFacets endpoint should output all fixed facet objects. Note that identifier
and title
are required attributes. Each fixed facet must have a corresponding stacked endpoint in the API with the same name, to provide the facet options. Additionally, a {name}:FILTER stacked endpoint is needed to filter results based on the selected value(s).
SPARQUE Desk endpoint example:
fixedFacets/p/channel/{STRING} -> OBJ
Sample output from the SPARQUE Desk API:
{
"offset": 0,
"count": 10,
"type": [
"OBJ"
],
"items": [
{
"rank": 1,
"probability": 1.0,
"tuple": [
{
"id": "https://www.sparque.ai/fixedfacet/ish/brand",
"class": [
"https://www.sparque.ai/fixedfacet"
],
"attributes": {
"identifier": "brand",
"title": {
"de-DE": "Marke",
"en-US": "Brand",
[...]
}
}
}
]
}
]
}
Endpoint brand
The brand endpoint should output all available brands based on the incoming product objects. This endpoint expects products as input and needs to be configured as [STRING,DOUBLE]
for the output, where the string is the brand name and the double is the count of product objects for this brand.
SPARQUE Desk endpoint example:
OBJ -> brand/p/user/{STRING} -> STRING, DOUBLE
Endpoint brand:filter
The brand:FILTER endpoint should output all products after one or more brand values have been applied as a facet. This endpoint requires a /value/ as a parameter (tuple list). The input is all products from a search or lister page.
SPARQUE Desk endpoint example:
OBJ -> brand:FILTER/p/value/{TUPLE_LIST} -> OBJ