How to Create a Redirect
Redirect is our new functionality for customizing Search.
It allows you to create a direct connection between a query or keyword and a specific url. When can you use it?
For example, you have a stand-alone product for one category, and you want to make it possible for your costumers to directly search for the product page from the search, without passing by the search page.
This guide will be divided into two sections. The first one is to show you how to create a Redirect for your store and the second part the additional steps you will have to follow if you have a custom API store.
How to Create a Redirect
To create a redirect you simply have to go to my.clerk.io and from there:
1. Go to Search -> Redirects -> Create new redirect.
2. Insert the URL of the product or web page you want your costumers to be sent to, once they press enter in the search bar of your store. Then click Create Redirect.
3. Add a new Query.
4. Select between Matches Exactly or Contains.
5. At this point you only have to write the Query your customers will use when they are looking for the product or the page which URL you wrote before. You can add as many queries as you need for the specific URL. Then click on Update Redirect.
If your Redirect does not work
Many scripts add functionality to your search field, so if your redirect does not work, there is a good chance that other script is overwriting the functionality.
If you add the below script to your Design, it will force the redirects to overwrite any existing functionality:
{% raw %}<script>
(function() {
input_selector = document.querySelector('#{{ content.id }}').dataset.instantSearch;
document.querySelectorAll(input_selector).forEach(input=>{
input.addEventListener('keyup', function(event){
{% if redirect %}
var currentRedirect = '{{ redirect }}';
{% else %}
var currentRedirect = undefined;
{% endif %}
if(event.which == 13 || event.which == 'Enter'){
if(currentRedirect != undefined){
event.preventDefault();
window.location.replace(currentRedirect);
}
}
});
});
})();
</script>{% endraw %}
Additional Steps for Your Custom API Store
If you own a Custom platform with an API solution you will need to follow the first part of the guide and then add these few steps to create the parameters you need to create the Redirect.
1. Create an API call by using our references you can find here: https://docs.clerk.io/reference#search-search
2. Insert the public and private API keys of your shop and use the query that you wrote in my.clerk.io. It should look something like this:
http://api.clerk.io/v2/search/search?key= INSERT_API_KEY_HERE&query=INSERT_QUERY&limit=10&debug=1
3. Copy your API call in the browser of your choice. In the API response you will find the parameter Redirect which you will need to implement the redirect functionality on your website.