I have several topic specific subpages on a website. For users that start their search on one of these subpages I’d like to only show results that are relevant for the target group / related to the topic rather than all results.
Is there a way to filter search results down to a subset of entities based on where the user started the search? And if yes, how can I set this up?
Hey ,yes, there are multiple ways of setting this up, but the easiest way would be a query rule that gets triggered for a specific referrer URL (or multiple URLs).The referrerUrl parameter will be added to all search results pages the user gets directed to after submitting their search.
This could look similar to this:
In this example the user came from the search bar on the website’s homepage.The solution:
- Create a saved filter and make sure only the relevant ones show up. We’ll need the filter’s ID later for the query rule (Knowledge Graph > Configuration > Saved Filters).2. Create a query rule within your Search experience
Criteria: Referrer Page URL Regex
Add a Regex if you’d like to include more pages with a search bar that are relevant for filtering down subfolders (e.g. ^http.www.brand.com.$ to include all subfolders and pages of the website).Action:
“$eq”: “[saved filter ID]”
}Test if the query rule is working:
Add the referrerUrl parameter and URL value to your URL and press enter.
As you start on the results page it might look like this
https://www.brand.com/results/?query=random+search+query&referrerUrl= so you’d just add one of the URLs that are covered in the Query Rule regex, for example https://www.brand.comLook at the number of entities that show up in a specific vertical tab you filtered down and check if it matches your defined subset.
Remove the referrerUrl parameter from the url to see all entities (the query rule doesn’t get triggered).The search bar functionality can only be tested in an environment with a live search bar integration.
If you want to test this on a staging environment, you’d have to setup an additional query rule with the page url the search bar is live on e.g. https://staging.brand.comFYI: This setup can be done with custom fields instead of the referrer URL, but in this case you’d have to modify the integration code of your search bar to provide context.Hope this helps! Let me know if you have any questions!
Amazing, Filtering results down using the query rule works perfectly! Thanks Asaki!