# Search

## Search API

Use the Search API to query the indexed products. The Search API is also used to apply any sorts or filters.

<mark style="color:green;">`POST`</mark> `https://api.neuralens.ai/search/query`

### Request Headers

| Header                     | Value                       |
| -------------------------- | --------------------------- |
| X-Neuralens-API-Key        | Bearer YOUR\_API\_KEY\_HERE |
| X-Neuralens-Application-ID | YOUR\_APPLICATION\_ID       |

### Request Params

<table><thead><tr><th width="138">Param</th><th>Value</th></tr></thead><tbody><tr><td>partition</td><td>Partition field's value (required in case partitioning is done)</td></tr></tbody></table>

Let's say `partition` is enabled on field "continent", then when sending request for the continent "asia", partition will be `asia`

### Request Body&#x20;

```json
{
    "query": "shirt",
    "offset": 0,
    "limit": 20,
    "filters": [
        {
            "field": "brand",
            "values": ["H&M", "Lacoste", "Nike"]
        }
    ],
    "fields": ["id", "productUrl", "title", "images"],
    "sorts": [
        {
            "field": "inStock",
            "order": "desc"
        },
        {
            "field": "salePrice",
            "order": "asc"
        }
    ],
    "sortOrder": "desc",
    "analytics": {
        "userId": "8769"
    }
}
```

`query` The search query text

`offset, limit` For pagination. offset is the index at which the requested page starts, limit is the number of results required on the page

`filters` Filters to be applied on the results

`sorts` Sorts applied by the user, if there are are more than one sort, next sort will only be used in case of tiebreaker from previous ones

`fields` Fields required in the search response

`analytics` Metadat required for performance tuning and personalisation

### Response

```json
{
    "qid": "59f7e4d1-1364-4903-9f92-8691af26d7e2",
    "results": [    
        {
            "id": "AD176",
            "title": "Printed T-shirt",
            "images": ["https://cdn.example.com/123", "https://cdn.example.com/789"],
            "productUrl": "https://example.com/product/AD176"
        },
        {
            ...
        }
    ],
    "filters": [
        {
            "field": "size",
            "label": "Size",
            "values": [
                {"value": "S", "count": 10, "is_applied": false}, 
                {"value": "M", "count": 10, "is_applied": false}, 
                {"value": "L", "count": 10, "is_applied": false},  
            ],
        },
        ...
    ],
    "sorts": [
        {
            "field": "relevance",
            "order": "desc",
            "label": "Relevance",
            "is_applied": true
        },
        {
            "field": "price",
            "order": "asc",
            "label": "Price - Low to High",
            "is_applied": false
        },
        ...
    ]
    "pagination": {
        "total": 45,
        "current_offset": 0,
        "next_offset": 20
    }
}
```

`qid` Unique id of the query

`results` List of search results

`filters` List of applicable filters, and their values. `is_applied` tells whether the current filter is already applied.

`sorts` List of applicable sorts, and their values. `is_applied` tells whether the current sort is applied.
