# Override filtering behavior

{% hint style="success" %}
This is the official documentation of the `agent_ruby` Ruby agent.
{% endhint %}

You may want to read about the following topics before using those features:

### Disabling operators

{% hint style="info" %}
Disabling filtering can be made without any code [in the field settings](https://docs.forestadmin.com/user-guide/collections/customize-your-fields#basic-settings).
{% endhint %}

### Substitution

Operation substitution can be used for two motives:

* Performance: provide a more efficient way to perform a given filtering operation
* Capabilities: enable filtering on a computed field or other non-filterable fields

#### Traditional Syntax

Using full context methods with `customize_collection`:

```ruby
include ForestAdmin::Types

@create_agent.customize_collection('customer') do |collection|
  collection.replace_field_operator('fullName', Operators::EQUAL) do |value|
    first_name, *last_names = value.split(' ')

    ConditionTreeBranch.new(
      'And',
      [
        ConditionTreeLeaf.new('firstName', Operators::EQUAL, first_name),
        ConditionTreeLeaf.new('lastName', Operators::EQUAL, last_names.join(' ')),
      ]
    )
  end
end
```

#### DSL Syntax

Using simplified DSL with `collection`:

```ruby
@create_agent.collection :customer do |collection|
  collection.replace_operator :fullName, :equal do |value|
    first_name, *last_names = value.split(' ')

    {
      aggregator: 'And',
      conditions: [
        { field: 'firstName', operator: 'Equal', value: first_name },
        { field: 'lastName', operator: 'Equal', value: last_names.join(' ') }
      ]
    }
  end
end
```

### Operators to support to enable the search

| Column Type | Operator to support            |
| ----------- | ------------------------------ |
| Number      | Equal                          |
| Enum        | Equal                          |
| String      | IContains OR Contains OR Equal |
| Uuid        | Equal                          |

You can use the [replaceFieldOperator](#substitution) method to unlock the operators.

### Emulation

Filtering emulation allows making fields filterable automatically. It is a convenient way to get things working quickly for Collections that have a low number of records (in the thousands at most).

{% hint style="warning" %}
This emulation forces the Agent to retrieve all the Collection records and compute the field values for each one of them. As a consequence, filtering emulation performance cost is **linear** with the number of records in the Collection, so **activate it sparingly and with great care**.
{% endhint %}

#### Traditional Syntax

Using full context methods with `customize_collection`:

```ruby
include ForestAdmin::Types

@create_agent.customize_collection('customer') do |collection|
  # Add support for all operators
  collection.emulate_field_filtering('fullName')

  # Add support for a single operator
  collection.emulate_field_operator('fullName', Operators::EQUAL)
end
```

#### DSL Syntax

Using simplified DSL with `collection`:

```ruby
@create_agent.collection :customer do |collection|
  # Add support for all operators
  collection.emulate_filtering :fullName

  # Add support for a single operator
  collection.emulate_operator :fullName, :equal
end
```
