Content Filters
The Content Filters in Replyke allow developers to filter entities based on the content of theircontent
property. This functionality is versatile and can be used to include or exclude entities with specific content characteristics. Let’s explore how Content Filters work and how to use them effectively.
Overview of Content Filters
ThecontentFilters
property can be passed to the fetchEntities
function as part of the filters object with the following structure:
hasContent
: A boolean flag to include entities based on whether they have content (true
) or not (false
).includes
: A string or array of strings. Entities whosecontent
contains any of these strings will be included.doesNotInclude
: A string or array of strings. Entities whosecontent
contains any of these strings will be excluded.
Applying Content Filters
Developers can apply content filters by calling thefetchEntities
function with the desired filter configuration.
How Content Filters Work
Content Filters are applied on the backend when querying entities. They allow for:- Existence Filtering: Using the
hasContent
flag, you can include only entities that have content (true
) or exclude entities without content (false
). - Text Matching:
includes
: Filters entities to include those whose content contains any of the specified strings.doesNotInclude
: Filters entities to exclude those whose content contains any of the specified strings.
- Combined Conditions: Developers can combine these conditions to achieve granular control over the results.
Example Use Cases
1. Passing Static Filters to the EntityListProvider
To set static filters for content at the initialization of the feed, pass them directly to theEntityListProvider
:
2. Dynamically Updating Filters Based on User Interaction
You can also dynamically adjust the content filters based on user actions, such as clicking a button:Important Notes
- Content Filters are case-insensitive, making them flexible for user-defined queries.
- Filters are applied immediately, and the feed resets to reflect the updated conditions.
- Passing
null
tocontentFilters
infetchEntities
clears all content-based filtering.