Metadata Filters
The Metadata Filters in Replyke allow developers to filter entities based on theirmetadata
property, which is flexible and can store unstructured data. This filter is highly versatile, enabling fine-grained control over the entity list by matching key-value pairs, verifying key existence, and excluding unwanted metadata.
Overview of Metadata Filters
ThemetadataFilters
property can be passed to the fetchEntities
function as part of the filters object with the following structure:
includes
: Specifies key-value pairs that must exist in the entity’smetadata
. Entities must include all specified key-value pairs.doesNotInclude
: Specifies key-value pairs that must not exist in the entity’smetadata
. If any specified key-value pair exists, the entity is excluded.exists
: An array of keys that must exist in the entity’smetadata
, regardless of their value.doesNotExist
: An array of keys that must not exist in the entity’smetadata
.
Applying Metadata Filters
Developers can apply metadata filters by calling thefetchEntities
function with the desired filter configuration.
How Metadata Filters Work
Metadata Filters allow for complex queries that include:- Key-Value Matching:
includes
: Filters entities to include those whosemetadata
contains all specified key-value pairs.doesNotInclude
: Filters entities to exclude those whosemetadata
contains any specified key-value pairs.
- Key Existence:
exists
: Ensures entities include the specified keys in theirmetadata
.doesNotExist
: Ensures entities do not include the specified keys in theirmetadata
.
- Combined Conditions: Developers can combine these conditions to create sophisticated filtering logic.
Example Use Cases
Developers can allow users to refine the entity list dynamically using thefetchEntities
function:
author
key in their metadata.
Important Notes
- Metadata Filters are powerful for working with unstructured data, allowing highly customized entity lists.
- Filters are applied immediately, and the entity list resets to reflect the updated conditions.
- Passing
null
tometadataFilters
infetchEntities
clears all metadata-based filtering.
Conclusion
Metadata Filters provide a robust mechanism to filter entities based on themetadata
property. With support for key-value matching, key existence validation, and exclusion conditions, these filters allow developers to implement advanced and highly specific entity list customization. Whether setting static filters at initialization or dynamically adjusting them based on user input, Metadata Filters make it easy to tailor the entity list for diverse application needs.