0

I'm having trouble running pg_search. I think it's set up correctly, but for some reason when trying to run a search, this comes up:

SQLite3::SQLException: unrecognized token: ":": SELECT "courses".*, ((ts_rank((to_tsvector('simple',
coalesce("courses"."title"::text, ''))), (to_tsquery('simple', ''' ' || 'finance' || ' ''')), 0))) AS
pg_search_rank FROM "courses"  WHERE (((to_tsvector('simple', coalesce("courses"."title"::text, '')))
@@ (to_tsquery('simple', ''' ' || 'finance' || ' ''')))) ORDER BY pg_search_rank DESC, "courses"."id" ASC

Course model:

include PgSearch
scope :by_course_title, lambda { |ttl|
  _by_course_title(ttl) if ttl.present? }
pg_search_scope :_by_course_title, against: :title

Search Controller:

def index
    @course = Course.by_course_title(params[:fname])
end

In the html:

<% @course.each do |courses| %>
    <div><%= courses %></div>
<% end %>

Is it possible that this is caused by the .each? If I only keep <%= @course %>, the page loads up and shows:

#<ActiveRecord::Relation:0x....>

Am I supposed to convert the resulting array before passing the .each function?

Revent
  • 2,091
  • 2
  • 18
  • 33
John
  • 31
  • 2
  • 5

1 Answers1

4

You have a PostgreSQL specific library (PgSearch) and you're using SQLite3 as your database. Pick one or the other, but not both.

The casting operator :: in coalesce("courses"."title"::text, '') is valid for PostgreSQL only. With SQLite you can leave out casting completely (the ::text part), but as mentioned before, you likely won't get PgSearch to work correctly unless you switch over to a PostgreSQL database.

PinnyM
  • 35,165
  • 3
  • 73
  • 81
  • Oh I see. Well I ended up learning basic SQL and juste created my own search code. I'm still very new to this and thought that SQLite and PostgreSQL were somehow connected. – John Aug 08 '13 at 17:21
  • They are both relational database systems supporting ANSI SQL (for the most part) - and that is about the extent of their relationship. Please mark as accepted if this helped you. – PinnyM Aug 08 '13 at 18:09