Filters are a great tools for hiding results that you don't want your users to see.
There are a few different ways to add a filter to your search. The best method to use will depend on why you are adding the filter as each method has different pros and cons:
Option 1 - With a rule:
How to do it: We have a guide for this here
- It's very easy to create a rule with a filter
- No need to do any coding to apply the filter, all you need is the rule
- Theoretically a user can turn rules off so filters added with rules should not be used for “secret” data that you need to hide for security/privacy reasons
Option 2 - With your API key:
How to do it: We have details on this here
- The user cannot change the filter
- You need to make sure that you always use this secured key in their frond end,
- less flexible as all searches with the key will have the filter regardless of what index they are searching
- If you want to remove the filter you will need to make a new key without it.
Option 3 - By adding the filter to the Search Parameters
How to do it: For back end search you can add the filter to the search as a search parameter. If you use InstantSearch on the front end you can use the configure widget
- Very flexible, you can apply the filter just on the searches you need it on
- Requires a code change (wherever you make the search you need to add the filter)
- Users can search without the filter if the filter is not being bound to the API key so this should not be used to hide data that needs to be kept secret for security/privacy reasons.
Article is closed for comments.