I'm working to add search to my PostgreSQL 9.1 rails app. Here is the setup:
class Comment < ActiveRecord::Base
include PgSearch
pg_search_scope :search_by_content, :against => :content
Rails C, command:
Comment.where(:commentable_id => 33).search_by_content('pgsql').count
Rails Log:
(348.1ms) SELECT COUNT(*) FROM "comments" WHERE "comments"."commentable_id" = 33 AND (((to_tsvector('simple', coalesce("comments"."content"::text, ''))) @@ (to_tsquery('simple', ''' ' || 'pgsql' || ' '''))))
After install the gem, and setting up the comment model, the instructions mentioned nothing about adding a db index to optimize performance. Given the query is already taking 348.1ms locally, I'm curious can this be optimized to be more performant?
Thanks