Adaptive Search Queries: Smart Suggest

Smart Suggest provides the user with suggestions for their search results. An index is used to find the list of fields along with the valid values which are indexed for that field.

The response payload is a list of items similar to saved query serialized outputs, which the user can use to search in Adaptive Search with a transient preference or store the same. It has q expression for each field value pair or field values pair for range based fields.

Sample Request and Response for Filter

The request is as below.

POST  /crmRestApi/searchResources/11.13.18.05/custom-actions/queries?
HTTP/1.1 200 OK
Content-Type: application/json
Preference: recommend
{
    "suggestions": {
        "type": "filter",
        "keyword": ""
    },
    "entity": "Lead",
    "q": null,
    "keywords": "",
    "fields": [
        "CreationDate"
    ],
    "limit": 25,
    "offset": 0
}

The response payload is as below:

{
    "items": [
        {
            "_entity": "Lead",
            "count": 13,
            "q": {
                "op": "$wi",
                "attribute": "CreationDate",
                "value1": "now/d",
                "value2": "now/d+1d"
            },
            "field": "CreationDate",
            "localizedValue": "Today"
        },
        {
            "_entity": "Lead",
            "count": 11,
            "q": {
                "op": "$wi",
                "attribute": "CreationDate",
                "value1": "now/w-1w",
                "value2": "now/w"
            },
            "field": "CreationDate",
            "localizedValue": "Last Week"
        },
        {
            "_entity": "Lead",
            "count": 187,
            "q": {
                "op": "$wi",
                "attribute": "CreationDate",
                "value1": "now/M-1M",
                "value2": "now/M"
            },
            "field": "CreationDate",
            "localizedValue": "Last Month"
        },
        {
            "_entity": "Lead",
            "count": 209,
            "q": {
                "op": "$wi",
                "attribute": "CreationDate",
                "value1": "now/M-3M",
                "value2": "now/M"
            },
            "field": "CreationDate",
            "localizedValue": "Last Quarter"
        },
        {
            "_entity": "Lead",
            "count": 210,
            "q": {
                "op": "$wi",
                "attribute": "CreationDate",
                "value1": "now/y-1y",
                "value2": "now/y"
            },
            "field": "CreationDate",
            "localizedValue": "Last Year"
        }
    ],
    "count": 5,
    "hasMore": false,
    "limit": 25,
    "offset": 0,
    "totalResults": 5
}

Sample Request and Response for Field

The request is as below

POST  /crmRestApi/searchResources/11.13.18.05/custom-actions/queries?
HTTP/1.1 200 OK
Content-Type: application/json
Preference: recommend
{   "entity":"Account",
    "suggestions":{
        "type":"field",
        "keyword":"Primary"
    },
    "limit":3
}

The response payload is as below:

 
{
    "items": [
        {
            "_entity": "Account",
            "localizedValue": "Primary Address:: ",
            "field": "PrimaryAddress"
        },
        {
            "_entity": "Account",
            "localizedValue": "Primary Contact:: ",
            "field": "PrimaryContact"
        }
    ],
    "count": 2,
    "hasMore": true,
    "limit": 2,
    "offset": 0,
    "totalResults": 32
}