How to replace users' queries with alternative text
This is a Query pipeline step
Sometimes you may find that users are employing a particular language when performing searches on your site that you haven’t accounted for in your record copy.
For example, you may be a jeans retailer that sells jeans using the measurement ‘inches'. The user could be performing searches such as ‘32 inch jeans’, but in your product copy, instead of the word ‘inches’ you have used the inch symbol
" . To solve this, instead of having to manually write synonyms, you can intercept the user’s search query and transform 'inches' into
" before the query is sent to Search.io.
To do this you can use the
string-replace step in the relevance pipeline. First navigate to Relevance > Advanced and paste the following code into the top of the file.
- id: string-replace params: outText: bind: q replace: constant: inch:" text: bind: q
We want the code to be at the top of the file as we want to intercept the query before any other steps run.
The code above takes the term ‘inch’ in any search query and transform it to the inch symbol
" . We are performing the replace on the
q (query), which is why we have written
text: bind: q. For example the query ‘32 inch jeans’ will now instead be sent to Search.io as ‘32” jeans’.