> ## Documentation Index
> Fetch the complete documentation index at: https://nestjs-query.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Filtering

Every property decorated with `@FilterableField` becomes an optional equality query parameter. Multiple parameters are combined with `AND`.

```ts title="todo-item.dto.ts" theme={null}
import { FilterableField, IDField } from '@ptc-org/nestjs-query-rest'

export class TodoItemDTO {

  @IDField()
  id!: number

  @FilterableField()
  title!: string

  @FilterableField()
  completed!: boolean
}
```

```http theme={null}
GET /todo-items?title=Write%20docs&completed=false
```

This produces the service filter equivalent to:

```ts theme={null}
{
  title: { eq: 'Write docs' },
  completed: { eq: false }
}
```

The field type controls query-string conversion and validation. For example, `completed=false` becomes the boolean `false`, and a numeric field is converted to a number.

## Required and filter-only fields

```ts theme={null}
export class TodoItemDTO {

  @FilterableField({ filterRequired: true })
  tenantId!: string

  @FilterableField({ filterOnly: true })
  ownerId!: string
}
```

`tenantId` must be supplied to endpoints that use this generated filter. `ownerId` can be used in a query but is excluded from response serialization.

## Defaults and disabling filters

Set a filter on `@QueryOptions` or the endpoint definition to scope every collection request:

```ts theme={null}
@QueryOptions({ defaultFilter: { archived: { eq: false } } })
export class TodoItemDTO {}
```

```ts theme={null}
{
  DTOClass: TodoItemDTO,
  EntityClass: TodoItemEntity,
  disableFilter: true
}
```

`disableFilter` removes generated filter query parameters from the read collection endpoint. The CSV export endpoint still exposes its filter parameters, and authorization filters are still applied by the server.

## Search terms

Set `enableSearch: true` to expose a free-form `query` parameter. The core query service does not interpret this value automatically; use a `BeforeQueryMany` hook or a custom service to translate it into a data-source filter.

```http theme={null}
GET /todo-items?query=documentation
```

See [hooks](../hooks) for a complete query hook example.
