Querying content
Use the following objects to query content:
-
query- specifies the string for each type of query. -
content- specifies the content type that thequeryapplies to. The default content type is product.
To specify the total number of items per page in the response, use the optional key, n_item.
The following sections show some examples of basic content queries. See advanced use cases for more examples.
Querying product content
The following code shows a request to query product content type. You want three product results (n_item = 3) and use the keyphrase red.
If you do not define any content type, Discover uses the default value.
The following code shows the corresponding response:
The response returns any product that contains red in any attribute.
In the example, there are two pages of results. You can query the next pages as shown in Retrieving a specific page of the search results.
Each response returns a default set of attributes for an item. For simplicity in this example, we only use a few attributes. You can get a different subset of attributes in the response as shown in Getting a subset of content value attributes.
Querying with an incomplete keyphrase
The following code shows a request with a query that uses an incomplete keyphrase, shor.
If the query keyphrase gives no results, Discover looks for results that match a suggested keyphrase. You must include a suggestion parameter in your request to get results for a suggested keyphrase. You can also use a request_for parameter in your request to return your query.
The following code shows the corresponding response:
Recommendation for one widget
The following code shows a request for a recommendation for one widget. You select the widget with rfkid equal to rfkid_1.
The following code shows the corresponding response:
Recommendation for two widgets
The following code shows a request for a recommendation for two widgets. You specify two rfkids: rfkid_1 and rfkid_2. The request overrides the first widget in the batch object.
The following code shows the corresponding response:
Recommendation with a product context widget
The following code shows a request for a recommendation with a product context widget.
The following code shows the corresponding response:
Getting all possible product fields
The following code shows a request for all possible product fields using the get_fields flag within content.
The following code shows the corresponding response: