Warning

This site is no longer being maintained. Visit the eDocs documentation portal for updated information.

Visit eDocs
Dismiss message

User and Query Context

Created by Pedro Ondiviela · last update June 5, 2020

What is this about?

Returns the user context information (top product attributes and the last visited products) and the query context (top product attributes and the top specific products) for a specific user and query. While the “userPreferences” are query agnostic, “userLastViewedProductsand the “queryContext” information are returned for the specific requested query.

The product attribute preferences are calculated based on user clicks, add-to-carts and purchases and the values are normalized using a linear function.

userLastViewedProducts” weight is calculated using the difference between the last time there was an interaction with the product and “now”. So, the more recent events will have more weight than others that happened long ago.

About this Endpoint

Structure for calling the endpoint.

Request URL example

GET https://api.empathybroker.com/contextsearch/v2/all/{instance_id}?{Input_Parameters}

Input Parameters

Parameter name Data Type
Required:  
user String
query String
lang String
Not required:  
session String
preferences.rows Integer
last_products.rows Integer
session.preferences.rows Integer
session.last_products.rows Integer
attributes.row Integer
products.rows Integer
events.min Integer
userAttributes String
maxTries Integer


Responses

Responses examples for successful and failing calls to the endpoint.

userPreferences” and “topAttributes” objects don’t have a fixed order and it may change in between requests. Nevertheless, “values” are sorted by “weight” in descending order.

topProducts” are sorted by “weight” in descending order.

Remember that your EB Contextualize configuration could use different fields for the preferences and topAttributes calculations, so the ones showing aside (“brand” and “gender”) are just examples.

200 400 404

Successful request

Type: application/json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{
  "userContext": {
    "userPreferences": [
      {
        "field": "brand",
        "values": [
          {"value": "brand1", "weight": 3},
          {"value": "brand2", "weight": 2.1}
        ]
      },
      {
        "field": "gender",
        "values": [
          {"value": "woman", "weight": 3}
        ]
      }
    ],
    "sessionPreferences": [
      {
        "field": "brand",
        "values": [
          {"value": "brand1", "weight": 3}
        ]
      },
      {
        "field": "gender",
        "values": [
          {"value": "woman", "weight": 3}
        ]
      }
    ],
    "userLastViewedProducts": [
      {"value":"213115", weight:"3"},
      {"value":"213149", weight:"1.3"}
    ],
    "sessionLastViewedProducts": [
      {"value":"213142", weight:"3"}
    ]
  },
  "queryContext": {
    "topAttributes": [
      {
        "field": "brand",
        "values": [
          {"value": "brand1", "weight": 3},
          {"value": "brand2", "weight": 1.8}
        ]
      },
      {
        "field": "category",
        "values": [
          {"value": "mobiles", "weight": 3}
        ]
      }
    ],
    "topProducts": [
      {"value":"213115", weight:"3"},
      {"value":"213149", weight:"1.3"}
    ]
  }
}