How to add a result to all queries

Hi,

I’d like to add a result to all queries, irrespective of the search. Can I use a query rule for that?
Use case to offer our “contact us for further products” product at the end of all results.

regards
Alex

Hi Alex,

Yes, you can use a query rule for this use-case. You’ll need a ‘conditionless’ rule which applies to All Queries: https://www.algolia.com/doc/guides/managing-results/rules/rules-overview/#conditionless-rules

You can add one of these rules through the Manual Editor on the dashboard.

When creating the condition for the rule, make sure to select ‘All queries’ from the dropdown. You can then select ‘Return Custom Data’ for the consequence. Here you can add custom JSON data - in your case something like: {“contact_us”: “Contact us for further products”} - see screenshot below:

You can then check the search response for userData, which will contain any custom data being returned with a rule, and manually modify the results however you would like (e.g. you could push this ‘Contact us’ product to the end of your array of results to display when the custom data is present).

Hope that helps! Let us know if you have any more questions or need further clarification.