# Pipelines & Fieldtypes

Dexter makes some assumptions how it indexes  content. For example, some fieldtypes such as an Asset field will index it's data in the following format. In this example the field's short name is "headshot", which will contain the URL to the file. All additional properties will be added to a "headshot\_meta" object. If multiple assets added to the field, only the first asset's URL will be added to the field's property name, all additional assets will be added to the "\_meta" object as an array.

```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"
    },
}
```

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
'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
'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;

    /**
     * @param ChannelEntry $channelEntry
     * @param Config $config
     */
    public function __construct(
       private IndexableInterface $indexable,
       private ConfigInterface $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'] = /* Do something special here */

        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-craft/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.
