Searches

searches

Using the searches method, you can send multiple requests at once. The client creates a single, optimized request from this batch.

Usage

client.searches(requests: RequestOptions[]);

RequestOptions

Name Type Default  Description
query String "" The query is the string you want to match to the results.
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:

[
   {
       "results": [
           {
               // 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
               }
           }
       ],

       // Total number of results that matched the query.
       "numberOfResults": integer,

       // Number of contents that matched each facet.
       "facets": {},

       // All the event data needed to track the search events
       "tracking": {
           // Code needed to track a `search` event.
           "searchCode": string,

           // Code needed to track a `search_rate` event.
           "searchRateCode": string
       }
   }
]

Example

client.searches([
    {
        query: 'cars',
        filters: ['color:red'],
        attributes: ['name', 'color']
    },
    {
        query: 'cars',
        filters: ['color:blue'],
        attributes: ['name', 'color']
    }
]).then(function (results) {
  console.log('red cars', results[0]);
  console.log('blue cars', results[1]);
});

Note: The 'results' object is an array of API responses, one for each request object.