---
url: /reference/concerns/searchable.md
---
# Trek::Searchable

Accent-insensitive full-text search on a record's page title, using PostgreSQL's `unaccent` extension.

## What it adds

* A `search(query)` scope — joins to the associated page and matches the title with an unaccented `ILIKE`; returns everything when the query is blank

## Usage

```ruby
class Article < ApplicationRecord
  include Trek::Pageable
  include Trek::Searchable
end

Article.search("élève") # matches "eleve", "Élève"…
```

## Controller side

The `Trek::Search` concern wires this into an admin controller's index, as the generated fragments controller does. It's opt-in: include it and call `search_in_objects!` after loading `@objects`:

```ruby
class Admin::ArticlesController < Trek::ResourceController
  include Trek::Search

  def index
    super
    search_in_objects!
  end
end
```

`search_in_objects!` filters `@objects` by `params[:search]` when it's present, and raises `Trek::Search::ModelNotSearchable` when the model has no `search` scope.
