1. Search experiences

Context

Version:

When creating a widget request, you can configure it by specifying the search context using the Context class. Search context is a set of contextual information about a site visitor's search request, such as locale, location, device, and web browser. Sitecore Search uses this data for personalizing search results.

For example, you can configure the search request to contain results relevant to audiences who browse the English version of your site in the United States:

import { SearchWidgetItem, Context } from "@sitecore-cloudsdk/search/browser";

// Configure the search request:
const widgetRequest = new SearchWidgetItem("product", "rfkid_7"); // Create a new widget request for the "Product" entity
widgetRequest.content = {}; // Request all attributes for the entity
widgetRequest.limit = 10; // Limit the number of results to 10

// Add context:
const context = new Context({
  locale: { language: "en", country: "us" }
});

// Call the `getWidgetData` function to request the data for the specified search context:
const response = await getWidgetData(
  new WidgetRequestData([widgetRequest], context),
);
If you have suggestions for improving this article, let us know!