Keywords Filters
The Keywords Filters in Replyke allow developers to filter entities in an entity list based on keywords. This filtering mechanism provides a way to include or exclude entities whose keywords match specific criteria. Let’s dive into how it works and how you can utilize it effectively.Overview of Keywords Filters
ThekeywordsFilters
property can be passed to the fetchEntities
function as part of the filters object with the following structure:
includes
: Specifies keywords that must be present in an entity’s keywords array for it to be included in the list.doesNotInclude
: Specifies keywords that must not be present in an entity’s keywords array for it to be included in the list.
fetchEntities
function with the desired filter configuration.
Applying Keywords Filters
Developers can apply keywords filters by calling thefetchEntities
function with the desired filter configuration.
How Keywords Filters Work
When the entity list is queried, the keywords filters are applied as follows:- Includes: If the
includes
array contains keywords, only entities whosekeywords
property contains all these keywords will be included in the list. - Does Not Include: If the
doesNotInclude
array contains keywords, entities whosekeywords
property contains any of these keywords will be excluded from the list. - Combined: When both
includes
anddoesNotInclude
are specified, entities must satisfy both conditions—they must include all keywords fromincludes
and exclude all keywords fromdoesNotInclude
.
Example Use Cases
Passing Static Filters to the EntityListProvider
If you want to set static filters as a starting point for your list, you can pass them directly into theEntityListProvider
:
Dynamically Updating Filters Based on User Interaction
To dynamically change the filters, such as when a user clicks a keyword button, use thefetchEntities
function:
Important Notes
- The filter updates are applied immediately and reset the list to ensure that the updated filter conditions are reflected in the data.
- Invalid or empty keyword values are ignored.
- Combining
includes
anddoesNotInclude
provides a powerful mechanism for fine-tuning the list results.
Conclusion
The Keywords Filters offer a flexible way to include or exclude entities based on their associated keywords. By leveraging thekeywordsFilters
property and the updateKeywordsFilters
function, you can dynamically tailor the list to meet your application’s needs. Whether you’re building a blogging platform, an e-commerce site, or a custom app, this filter can help you surface the most relevant content for your users.