# Pipelines & Fieldtypes

Dexter makes some assumptions how it indexes  content. For example, some fieldtypes such as File fields will index it's data in the following format. In this example the field's short name is "headshot", and there are two image manipulations, "small" and "large".

```json
{
    "headshot": "http://site.com/path/to/file.jpg",
    "headshot_meta": {
        "file_id":2381
        "site_id":1
        "file_name":"file.jpg"
        "file_size":139836
        "description":"This is a description..."
        "credit":"Chuck Close",
        "location":"New York",
        "upload_date":1738859068
        "modified_date":1738859068
        "url": "http://site.com/path/to/file.jpg"
        "__full_text":"file.jpg This is a description... Chuck Close New York"
    },
    "headshot_small": "http://site.com/path/to/_small/file.jpg",
    "headshot_large": "http://site.com/path/to/_large/file.jpg",
}
```

While Dexter does handle a lot of stuff out of the box, if you are in need of some custom behaviors, or modification of data that is indexed, such as the file format above, making a new pipeline is the answer. For this you will need some PHP knowledge. *Pipelines must be namespaced classes*. You can include additional pipelines by adding them to your config file:

```php
$config['dexter'] = [
    'pipelines' => [
        \BoldMinded\DexterPipelines\Pipeline\ExamplePipeline::class,
        \Acme\Something\MyPipeline::class,
    ]
];
```

To make it easier to include custom pipelines the `dexter_pipelines` add-on is included with Dexter. Since you will be adding files unique to your site to this add-on, do not update it when you update Dexter with a new version.

There may be some pipelines available in Dexter that are not enabled by default, such as the CommentsPipeline. You can view a list of all the available pipelines in the `Service/Pipeline` folder. To enable the CommentsPipeline or any other one simply add it to the `$config` array.

```php
$config['dexter'] = [
    'pipelines' => [
        \BoldMinded\Dexter\Pipeline\CommentsPipeline::class,
    ]
];
```

Dexter uses the [League\Pipeline](https://pipeline.thephpleague.com/) package, and as such all pipelines need to follow the same structure and method signatures. Below is an example of the CategoryPipeline from Dexter's codebase. The basic concept is a item or collection of data is passed through a series of classes, each one manipulating the data if necessary. The order in which the pipes are declared matters. In Dexter's case, we have a simple array of entry data. Some pipes append new data to the array, and others might manipuate existing data. At the end of the pipeline we end up with an array that ends up getting encoded into json and indexed in Algolia or Meilisearch.

```php
<?php

namespace BoldMinded\Dexter\Service\Pipeline;

use BoldMinded\Dexter\Service\Config;
use ExpressionEngine\Model\Category\Category;
use ExpressionEngine\Model\Channel\ChannelEntry;

class CategoryPipeline
{
    /**
     * @var ChannelEntry
     */
    private $channelEntry;

    /**
     * @var Config
     */
    private $config;

    private IndexableInterface $indexable;
    private ConfigInterface $config;

    public function __construct(
        IndexableInterface $indexable,
        ConfigInterface $config
    ) {
        $this->indexable = $indexable;
        $this->config = $config;
    }

    /**
     * @param array $values
     * @return array
     */
    public function __invoke(array $values): array
    {
        if (empty($values)) {
            return [];
        }

        $categories = $this->config->get('categories');

        if (empty($categories)) {
            return $values;
        }

        $values['categories'] = $this->channelEntry->Categories
            ->filter('group_id', 'IN', $categories)
            ->pluck('cat_name');

        return $values;
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.boldminded.com/dexter/docs/pipelines-and-fieldtypes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
