I am testing performance for PostgreSQL full text search (using pg_search gem) and solr (sunspot_solr gem).
For 4 million records I am getting 13456 ms for
This expression:
to_tsvector('simple', (COALESCE(title::TEXT), ''))
is not sargable against your index.
You should declare the index on the exactly that expression which is used in the query:
CREATE INDEX products_gin_title
ON products
USING GIN(to_tsvector('simple', COALESCE(title::TEXT,'')))
(or make ruby generate the expression which is used in the index).
If you want multiple columns to be indexed, just concatenate them:
CREATE INDEX products_gin_title
ON products
USING GIN(to_tsvector('simple', title || ' ' || product_type || ' ' || platform_id))
but again, Ruby should be filtering on exactly same expression for the index to be of use.