I am implmenting postgresql text search into my application. When I search for a specific item i get the error.
SELECT COUNT(*) FROM "documents" INNER JOIN (SELECT "documents"."id" AS pg_search_id, (ts_rank((to_tsvector('english', coalesce("documents"."title"::text, '')) || to_tsvector('english', coalesce("documents"."content"::text, ''))), (to_tsquery('english', ''' ' || 'coffee' || ' ''')), 0)) AS rank FROM "documents" WHERE (((to_tsvector('english', coalesce("documents"."title"::text, '')) || to_tsvector('english', coalesce("documents"."content"::text, ''))) @@ (to_tsquery('english', ''' ' || 'coffee' || ' '''))))) pg_search_documents ON "documents"."id" = pg_search_documents.pg_search_id
in my document model
include PgSearch
pg_search_scope :search, :against => [:title, :content],
:using => {tsearch: {dictionary: "english"}}
def self.text_search(query)
if query.present?
search(query)
else
all
end
end
in my document controller
def load_documents
@documents = documents_scope.all.text_search(params[:query])
end
how my database is wired in the console
Document(id: uuid, category_id: uuid, title: string, created_at: datetime, updated_at: datetime, version_id: uuid)
DocumentVersion(id: uuid, document_id: uuid, document_version_id: uuid, user_id: uuid, title: string, content: text, created_at: datetime, updated_at: datetime
It has something to do with the table join, but im not sure how to fix it. thanks for your help.