Guides / Building Search UI / UI & UX patterns

Redirects in InstantSearch Android

Redirects can enhance the search experience. For example:

  • Searching for “help” redirects users to a support page
  • Searching for a category, such as, “TV” redirects users to a category page
  • Searching for a specific product or brand redirects users to a seasonal promotional page for it
  • Searching for specific keywords related to an ongoing event, such as, “masks”, redirects users to a more specific landing page

This guide explains how to add redirects to InstantSearch through Rules and using custom data.

Configure a rule

To set up a rule that returns custom data whenever the query matches specific keywords, see Create a rule for returning custom data.

Configure the rule custom data widget

After setting up a rule that returns the custom redirect data, you can use the QueryRuleCustomData widget to update the page location when userData contains a redirect.

1
2
3
4
5
6
7
8
9
10
11
12
13
@Serializable
data class Redirect(val url: String)

val searcher = HitsSearcher(
    applicationID = ApplicationID("YourApplicationID"),
    apiKey = APIKey("YourSearchOnlyAPIKey"),
    indexName = IndexName("YourIndexName")
)
QueryRuleCustomDataConnector<Redirect>(searcher) { redirect ->
    redirect?.url?.let {
        // perform redirect with URL
    }
}
Did you find this page helpful?