Faceting

Faceting is a powerful tool for E-commerce website, find below how you can configure it with XO Search

This feature is only available for the Search API

Parameters

The faceting parameters allows the developer to enable/disable faceting results, and to filter search results using specific facets values.

Name

Type

Is Required ?

Default value

facets

array

✖

empty array

facets

If specified, perform a search using the selected facets and values. This parameter must be an array of JSON objects. Each object should have the following properties:

Property
Type
Description

id

string

ID of the facet to select

values

array of string

Items should have at least one

of these values for the selected facet

"facets": [
    {
        "id": "facet-name",
        "values": ["string-value", ...]
    },
    ...
]

Notes

  • Unknown facets values will lead to empty responses.

Response

All responses from XO Search uses the same format. Check API Reference page for a more detailed description of this format.

API Reference

Usage examples

Filter results based on facets values

  • Retrieve only items with the facet size set to one of the [46, 48, 50] values

NodeJS / NPM example

import { search } from '@attraqt/search';

const query = 'T-shirt';

search.init({ token: SEARCH_API_TOKEN });

const response = await search.query(query, {
  facets: [
    {
      id: 'size',
      values: ['46', '48', '50']
    }
  ]
});

console.log(response);

HTML example

<script type="text/javascript">
    xo.init({
        search: {
            token: SEARCH_API_TOKEN
        }
    });

    xo.search.query('T-Shirt', {
        facets: [
            {
                id: 'size',
                values: ['46', '48', '50']
            }
        ]
    }).then((response) => {
        console.log(response);
    });
</script>
  • Retrieve only items with the facet size set to 46 and the facet color set to one of [23, 26] values

NodeJS / NPM example

import { search } from '@attraqt/search';

const query = 'T-shirt';

search.init({ token: SEARCH_API_TOKEN });

const response = await search.query(query, {
  facets: [
    {
      id: 'size',
      values: ['46'] 
    },
    {
      id: 'color',
      values: ['23', '26'] 
    }
  ]
});

console.log(response);

HTML example

<script type="text/javascript">
    xo.init({
        search: {
            token: SEARCH_API_TOKEN
        }
    });

    xo.search.query('T-Shirt', {
        facets: [
            {
                id: 'size',
                values: ['46'] 
            },
            {
                id: 'color',
                values: ['23', '26'] 
            }
        ]
    }).then((response) => {
        console.log(response);
    });
</script>

Last updated