Context

Add contextual information to your queries

Parameters

To add contextual information to you queries, you can use the following parameters:

ParameterTypeIs Required?

variables

object

variables

The variables that you want to make available to your custom triggers. The object is composed of a key/value pair.

Supported types are:

  • String

  • Long (int64)

  • Double (float64)

  • Date (as a String with ISO-8601 format. Such as 2023-01-01T00:00:00+01:00)

  • Boolean

  • Array of String

System variables

XO Search uses some variables internally, that are available to your custom triggers. You can use them to customize your search results. You cannot set variables with these names in your context.

Variable nameTypeDescription

$SEARCH_QUERY

string

The query that was used to perform the search.

$SEARCH_FACET_*

array

The facets that were used to perform the search.

$SEARCH_TAGS_FACET_*

array

The facets that were used to perform the search.

$SEARCH_DATE_TIME

date

The date and time of the search.

$SEARCH_HOUR

long

The hour of the search. (Server time!) Range: 0-23

Configure your own variables!

To configure your variables please visit the XO Console.

In the side menu expand the "Developer" section and click on "Variables".

Here you can create and modify your own variables.

(As of this moment system variables are not editable.)

Usage example

SDK - JS

NodeJS / NPM example

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

const query = '';

search.init({ token: SEARCH_API_TOKEN });

const requestOptions = {}

const context = {
  variables: {
    '$my-variable': 'my-value'
  }
};

const response = await search.query(query, requestOptions, context);
console.log(response);

HTML example

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

    const context = {
      variables: {
        '$my-variable': 'my-value'
      }
    };
    
    xo.search.query('', requestOptions, context).then((response) => {
        console.log(response);
    });
</script>

Last updated