Recipe: Restrict Fixed Facets to Specific Endpoints

Note:
This recipe applies to all SPARQUE API Wrapper versions.

Problem

By default, all fixed facets defined in the SPARQUE configuration are returned for both the /search and /products endpoints. In some scenarios, certain fixed facets are only relevant to one of these endpoints. For example, a category facet may not be required in the response of the /products endpoint when the PWA uses data from the /categorytree endpoint to manage the displayed category facet. Without a way to control this, consumers receive facets that are irrelevant to the endpoint they called.

Solution

An optional attribute includeIn has been added to fixed facet definitions. It controls which endpoint(s) a fixed facet is included in. The allowed values are:

ValueMeaning
both (default)Facet is returned for both /search and /products endpoints
/searchFacet is only returned for the /search endpoint
/productsFacet is only returned for the /products endpoint

When includeIn is missing or set to both, the facet behavior remains unchanged. When set to /search or /products, the Wrapper excludes the facet from the response for the other endpoint.

Discussion

To configure the includeIn attribute for a fixed facet:

  1. Add the includeIn attribute to the fixed facet option in the fixed facet XML definition:

    <?xml version="1.0" encoding="UTF-8"?>
    <Fixedfacets>
      <option>
        <channel>ish</channel>
        <name>hotdeal</name>
        <attribute>
          <name>includeIn</name>
          <value>/search</value>
        </attribute>
        ...
  2. Add the following mapping for the fixed facets in the SPARQUE DataSet:

     <spinque:attribute
         subject="{$optionId}"
         attribute="includeIn"
         type="string"
         value="{attribute[name='includeIn']/value}" />
  3. Ensure the includeIn entry is present in the attributes array of the fixed facet result description:

    JSON example:

    {
      "class": "https://www.sparque.ai/fixedfacet",
      "level": 1,
      "mode": "full",
      "attributes": [
        {
          "name": "identifier",
          "type": "STRING",
          "aggr": "most_frequent",
          "splitLanguages": true
        },
        {
          "name": "title",
          "type": "STRING",
          "aggr": "most_frequent",
          "splitLanguages": true
        },
        {
          "name": "displayname",
          "type": "STRING",
          "aggr": "most_frequent"
        },
        {
          "name": "displayType",
          "type": "STRING",
          "aggr": "most_frequent",
          "splitLanguages": true
        },
        {
          "name": "selectionType",
          "type": "STRING",
          "aggr": "most_frequent",
          "splitLanguages": true
        },
        {
          "name": "limitCount",
          "type": "INTEGER",
          "aggr": "most_frequent"
        },
        {
          "name": "minCount",
          "type": "INTEGER",
          "aggr": "most_frequent"
        },
        {
          "name": "position",
          "type": "INTEGER",
          "aggr": "most_frequent"
        },
        {
          "name": "addOneVariantSnippet",
          "type": "STRING",
          "aggr": "most_frequent"
        },
        {
          "name": "includeIn",
          "type": "STRING",
          "aggr": "most_frequent"
        }
      ],
      "constants": [],
      "includes": []
    }

Behavior

includeIn value/search endpoint/products endpoint
missing or bothincludedincluded
/searchincludedexcluded
/productsexcludedincluded