Developers

Search

Usage

client.search(query: String, options: Object);

Query

The query is the string you want to match to the results.

Options

Name Type Default  Description
filters Array<String | String[]> [] Filter the query with facets (facets are dynamic settings marked as \"Use as filter\").
Each string represents a filter on a given facet value. It must follow the syntax ${attributeName}:${value}.
If you specify multiple filters, they are interpreted as a conjunction (AND).
If you want to use a disjunction (OR), use a nested array.
sort String Controls the way results are sorted. Currently, results are sorted by matching weight.

* You may also specify further sorting criteria by passing a list of attributes and the sorting order.
  • asc(${attributeName}): sort by increasing value of the attribute.
  • desc(${attributeName}): sort by decreasing value of the attribute.
offset Integer 0 Offset of the first result to return (zero-based)
length Integer 3 Maximum number of results to return
attributes String | String[] * List of object attributes you want to retrieve. This can be used to minimize the size of the response. You can use * to retrieve all values.

Response data format

The response looks like this:

[
        {
            // ID of the content
            "id": integer,

            // Title of the content
            "title": string,

            // highlightedTitle of the content
            "highlightedTitle": string,

            // score of the content
            "score": integer,

            /**
            * All dynamic setting checked as visible but the title, which is received aside.
            * Note that some of them are mandatory as it is specified in the below structure.
            */
            "attributes": {
                // URL of the content
                "url": [ string ],

                // The different pieces of information that were indexed from the crawler. It has an option called "dynamic abstract" which shows the best piece of information related with the requested query.
                "paragraph": [ string ],

                // Alternative title that will show depending on the requested query.
                "alt2show": [ string ]
            },

            // All data needed to track the content events. See "*/tracking/events*" endpoint.
            "tracking": {
                // Code needed to track a `click` event.
                "clickCode": string,

                // Code needed to track a `rate` event.
                "rateCode": string
            }
        }
]

Example

client.search('cars', {
    filters: ['color:red', 'year:2017'],
    attributes: ['name', 'color', 'year']
  }).then(function (response) {
  console.log(response);
});