Using Search

This tutorial will show how to search for SKUs, starting from a simple search request and expanding it to include more and more functionality.

The most basic search just requires a segment and a scope.

1
2
3
4
{
    "segmentId": "b2c-en-test",
    "scopeId": "browse"
}

This will return the number of results defined by the browse scope. It is possible to override this on request.

1
2
3
4
5
{
    "segmentId": "b2c-en-test",
    "scopeId": "browse",
    "numberOfResults": 2
}

In order to do pagination, simply provide an offset.

1
2
3
4
5
6
{
    "segmentId": "b2c-en-test",
    "scopeId": "browse",
    "numberOfResults": 2,
    "offset": 10
}

This is effective when browsing, but when searching, a phrase should be provided.

1
2
3
4
5
6
{
    "segmentId": "b2c-en-test",
    "scopeId": "browse",
    "numberOfResults": 2,
    "phrase": "wood"
}

A user often wants to sort the results. To do that, there are different sorting options.

{
    "segmentId": "b2c-en-test",
    "scopeId": "browse",
    "numberOfResults": 2,
    "phrase": "wood",
    "sort": [
        {
            "key": "price",
            "order": "desc"
        }
    ]
}

Note

The search request takes a list of sorting keys, so it is possible to tiebreak by score, even when sorting by price.

Of course, it is also possible to add filters to the search request.

{
    "segmentId": "b2c-en-test",
    "scopeId": "browse",
    "numberOfResults": 2,
    "phrase": "wood",
    "sort": [
        {
            "key": "price",
            "order": "desc"
        }
    ],
    "filters": {
        "color": {
            "values": [ "red" ],
            "match": "any"
        }
    }
}

It is also possible to filter by range, such as price.

{
    "segmentId": "b2c-en-test",
    "scopeId": "browse",
    "numberOfResults": 2,
    "phrase": "wood",
    "sort": [
        {
            "key": "price",
            "order": "desc"
        }
    ],
    "filters": {
        "price": {
            "from": 400,
            "to": 800
        }
    }
}