Redirects

Redirects are a feature whereby specific queries behave differently than an ordinary search. Instead of sending clients to a search results screen, redirects enable you to send the client to an alternative destination. Where a redirect sends the client depends on the configuration of the redirect and the client implementation. The most common implementation is that redirects will send the client to a targeted URL.

Here is a quick example:

{ // Redirect object shape
  "condition": "q = 'shoes'"
  "target": "/curated/shoes",
  "token": "eyJkafe81bkajaloafkeaj"
}

With this redirect configured, when someone searches for ‘shoes’, instead of sending that person to the search results page with the query ‘shoes' the client would redirect to a curated shoes page. Using this capability, a brand might choose to create curated landing pages built to show off their most important products or categories then redirect relevant queries to those pages.

Creating and managing Redirects

Fundamentally, redirects are a discrete piece of configuration data associated with a collection. They can be created and managed via the Redirects API or in the Search.io console. Further details can be found here.

How Redirects are returned

Most important to understand for search client integration is that redirects are returned when querying the autocomplete pipeline associated with a collection. All collections have an associated autocomplete pipeline and when you submit a query to that pipeline, any redirects which are relevant to the query are returned. The response to an autocomplete query contains redirects data along-side its usual content (example below).

{
  searchResponse: {…};
  tokens: […];
  values: {…};
  activePromotions: […];
  // Redirect data
  redirects: Array<{
    'search string': {
      id: number,
      target: string,
      token: 
    }
  }>;
}

Further details for customers using the JS SDK or the React SDK.

Redirecting in custom client implementations

The choice of how to handle redirects is up to the developer(s) implementing the custom client. Redirects for any query can be easily fetched by submitting a query to the autocomplete pipeline. This means that integration can be implemented as either a server or client-side feature. A server implementation might respond with a 302 http status code while a frontend client would likely redirect using window.location.

Autocomplete

Note that all redirects which match the current query substring are returned. This is important for autocomplete search clients where the client may present a list of autocomplete options which may consist of suggested search terms, spell corrections and redirects.

An autocomplete query for the string is "sho" could result in a redirects array containing {"shoe": {…}, "shoes": {…}} being returned.

Tracking

Redirects contain two potential redirect locations. The ‘target’ string is exactly what is configured for that redirect object. The ‘token’ is a Search.io generated token URL which will log tracking information for the query, then send the user to the target destination. Using ‘token’ allows Search.io and you to better understand how often redirects are being used.

Mobile integration

The target field of a redirect object does not need to be a URL. It can be any string value. While URLs are a common means of communicating resource locations, it is not necessarily the preferred format for all clients. This should enable mobile-first brands to manage redirects using the same resource location data format that they use for the rest of the client.

Last updated