Casecommons/pg_search — pull request #141 by stevenharman (2013-11-19 18:26:43+00:00)
Title: Normalize trigram query and document as Arel nodes

When trying to use `ingnoring: :accents` with `using: :trigrams` my searches were not returning expected results. After inspecting the generated SQL I found this was to due to incorrect escaping of the trigram terms.

We need to normalize the Trigram's query and document, making sure they are Arel nodes, not strings so that the `Arel::Nodes::InfixOperation.new` correctly puts them together with the `'%'` operator. Without this change, they are incorrectly escaped as:

```sql
(
('unaccent(coalesce("pg_search_documents"."content"::text, ''''))')
%
'unaccent(Cambonator Doppelbock)'
)
```

The correct escaping is:

```sql
(
(unaccent(coalesce("pg_search_documents"."content"::text, '')))
%
unaccent('Cambonator Doppelbock')
)

```