> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sublay.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Content Filters

### Content Filters

The **Content Filters** in Replyke allow developers to filter entities based on the content of their `content` 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**

The `contentFilters` property can be passed to the `fetchEntities` function as part of the filters object with the following structure:

```typescript theme={null}
export interface ContentFilters {
  hasContent?: boolean;
  includes?: string | string[];
  doesNotInclude?: string | string[];
}
```

* **`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 whose `content` contains any of these strings will be included.
* **`doesNotInclude`**: A string or array of strings. Entities whose `content` contains any of these strings will be excluded.

#### **Applying Content Filters**

Developers can apply content filters by calling the `fetchEntities` function with the desired filter configuration.

```tsx theme={null}
const entityList = useEntityList({ listId: "filtered-feed" });

// Apply content filters
entityList.fetchEntities({
  sortBy: "hot",
  contentFilters: { includes: "JavaScript", doesNotInclude: "PHP" }
});

// Reset content filters
entityList.fetchEntities({
  sortBy: "hot",
  contentFilters: null
});
```

#### **How Content Filters Work**

Content Filters are applied on the backend when querying entities. They allow for:

1. **Existence Filtering**: Using the `hasContent` flag, you can include only entities that have content (`true`) or exclude entities without content (`false`).
2. **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.
3. **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 the `EntityListProvider`:

```tsx theme={null}
<EntityListProvider
  contentFilters={{ hasContent: true, includes: ["JavaScript", "React"], doesNotInclude: "PHP" }}
>
  <MyFeedComponent />
</EntityListProvider>
```

This setup ensures that only entities with content are included, and that content must contain either "JavaScript" or "React" while excluding "PHP."

##### **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:

```tsx theme={null}
const entityList = useEntityList({ listId: "filtered-feed" });

const handleFilterUpdate = (newIncludes: string[], newExcludes: string[]) => {
  entityList.fetchEntities({
    sortBy: "hot",
    contentFilters: { includes: newIncludes, doesNotInclude: newExcludes }
  });
};

const clearFilters = () => {
  entityList.fetchEntities({
    sortBy: "hot",
    contentFilters: null
  });
};

return (
  <div>
    <h1>Filtered Content</h1>
    <div>
      <button onClick={() => handleFilterUpdate(["JavaScript"], ["PHP"])}>
        Show JavaScript, Exclude PHP
      </button>
      <button onClick={clearFilters}>Clear Filters</button>
    </div>
    <ul>
      {entityList.entities.map((entity) => (
        <li key={entity.id}>
          <h2>{entity.title}</h2>
          <p>{entity.content}</p>
        </li>
      ))}
    </ul>
    <button onClick={entityList.loadMore}>Load More</button>
  </div>
);
```

In this example, clicking the button updates the content filters dynamically, allowing users to customize the feed results.

#### **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` to `contentFilters` in `fetchEntities` clears all content-based filtering.

#### **Conclusion**

Content Filters provide developers with powerful tools to fine-tune feed results based on the content of entity properties. Whether setting static filters at initialization or dynamically updating them based on user input, Content Filters ensure your feed presents the most relevant content. With options to filter by existence, inclusion, and exclusion, you can cater to diverse application needs effortlessly.
