Defining Sorting Options in a List or Search Result Page

The Wrapper uses the SPARQUE Desk endpoint sortings to determine the available sorting options. To ensure that the Wrapper can perform the sorting operation, a corresponding SPARQUE Desk endpoint must be defined for each sorting option. This document uses nameup as an example.

Data Source

First, define the data source to specify the available sorting options. Below is an example where nameup is set as a sorting option. The code is used for localization, and the title provides a user-friendly, localized name that the application can use.

<option>
    <channel>ish</channel>
	<name>nameup</name>
	<label>
		<code>en-US</code>
		<title>Name A-Z</title>
	</label>
</option>

Mapping

<?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, 'sortingoption', $channel, name)"/>
		<spinque:relation subject="{$optionId}" predicate="{$rdfstype}" object="{concat($prefix, 'sortingoption')}"/>
		<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>
        <!-- relation to channel -->
        <xsl:variable name="channelobject" select="su:uri($prefix, 'channel', $channel)"/>
        <spinque:relation subject="{$optionId}" predicate="sorting-channel" object="{$channelobject}"/>
	</xsl:template> 
</xsl:stylesheet>

Mapping result in SPARQUE Desk

API Endpoints

Endpoint sortings

This endpoint returns all available sorting options. The Wrapper queries this endpoint when /config/ is requested. It requires a locale parameter of type string to provide localized, user-friendly names for the sorting options. Each sorting option must have its own dedicated stacked endpoint.

Sample output from the SPARQUE Desk endpoint:

{
    "offset": 0,
    "count": 10,
    "type": [
        "OBJ",
        "STRING"
    ],
    "items": [
        {
            "rank": 1,
            "probability": 1.0,
            "tuple": [
                {
                    "id": "https://www.sparque.ai/sortingoption/ish/nameup",
                    "class": [
                        "https://www.sparque.ai/sortingoption"
                    ],
                    "attributes": {
                        "identifier": "nameup",
                        "title": {
                            "de-DE": "Name A-Z",
                            [...]
                            "en-US": "Name A-Z"
                        }
                    }
                },
                "Name A-Z"
            ]
        }
    ]
}

Endpoint nameup

A dedicated nameup endpoint must be created in SPARQUE Desk. Since sorting methods can be reused across multiple Wrapper endpoints, the endpoint should be stacked to allow layering on top of existing logic. The stacked endpoint should accept [OBJ] as input and output. The sorting logic is defined within the SPARQUE Desk endpoint strategy.

SPARQUE Desk endpoint example:

OBJ -> nameup -> OBJ

SPARQUE Desk strategy example: SPARQUE Desk endpoint example

How it Works

Sorting can be applied to the Wrapper endpoints /search/, /products/ and /recommendation/. For example, a search request might look like this:

/api/v2/search?Keyword=searchterm&Sorting=nameup&UserId=myUserId&WorkspaceName=myWorkspace&ApiName=myApi&ChannelId=myChannel&Locale=en-US&Config=production&Count=20&Offset=0

Including the Sorting=nameup parameter ensures that the Wrapper will stack the nameup endpoint to the SPARQUE Desk endpoint, so the results are sorted accordingly.

An example call to SPARQUE Desk:

1/myWorkspace/api/myApi/c/UserId/myUserId/c/locale/en-US/c/channel/myChannel/c/keyword/searchterm/e/search/q/nameup/e/user_product_catalog/e/oneVariant/results,count?config=production&count=20&offset=0