Create a request to get search page data
This topic shows you how to make a call to the Sitecore Discover Search and Recommendation API to get a search page widget in the following scenario:
-
You want to show one result on each search result page (
n_item= 1).NoteFor brevity, this example shows a request with one result per search page. You can change the value of
n_itemto, say, 12, and use the rest of the code. -
You want to make a call to get data for the first page of the search page widget (
page_number=1). -
The user searches for the keyword sanda, a misspelling of sandal. You want to show the user one corrected suggestion.
-
The user must be able to sort products by customer ratings.
Use the API explorer to try out requests and see sample responses.
To create a request to get search page data:
-
In the header, add cookies and, if required, authentication details.
-
In the request body, add page context and user context. For page context, include the page
uriand locale information (if applicable). For user context, include either theuuidor theuser_ID.RequestResponse{ "context": { "page": { "uri": "/search" }, "user": { "uuid": "sampleUUID" } } } -
Add widget information. Use the
rfkidof the search page widget.RequestResponse{ "widget": { "rfkid": "rfkid_7" }, } -
Add pagination information. Specify the number of items (
n_item) you want to see in one page of search results. Also, specify the page for which (page_number) you are making the call.RequestResponse{ "n_item": 1, "page_number": 1, } -
Add query information, that is, the keywords that the user searches for.
RequestResponse{ "query": { "keyphrase": { "value": [ "sanda" ] } } } -
Add suggestion information to tell Discover how many suggestions you want to display if the user mistypes a keyword.
RequestResponse{ "suggestion": { "keyphrase": { "max": 1 }, } } -
Request information about the suggested keyword used if the user misspells something. To do this, use the
request_forkey. For details, see Related keyRequestResponse{ "request_for": [ "query" ] }NoteIn the
request_forresponse object,orig_keyphrasecontains the original keyword andkeyphraseis suggested by Discover. -
Add facet information to tell Discover how many facets you want.
RequestResponse{ "facet": { "all": true }, } -
Add sort information to tell Discover how you want to sort.
RequestResponse{ "sort": { "value": [ { "name": "rating", "order": "desc" } ] } } -
Request product content. Here, we want the entire product.
RequestResponse{ "content": { "product": {} }, }
You can see the complete request with all objects put together and the corresponding response in the sample section.