5

I've been following the Railscast for adding searching, sorting, and pagination to my app. I've modified my search logic in the model to search to columns (description and title). This seems to be working. I've also changed it to search non case sensitive. This seems to work perfect in my local app, but when I push it to heroku, I can only search by lowercase. Search with any capital letters at all produces no results, even if the case matches the results.

here is the code in my model:

  def self.search(search)
    if search
      where('LOWER (description) LIKE ? OR LOWER (title) LIKE ?', "%#{search}%" , "%#{search}%")
    else
      scoped
    end
  end
2
  • I'm not sure that this is your issue, but heroku uses Postgres, so any MySQL-specific syntax will not work (I don't know that any of that is mysql-specific, however). Commented Jan 12, 2011 at 19:07
  • That shouldn't be the issue: Postgres also has a LOWER function. Commented Jan 12, 2011 at 20:05

2 Answers 2

5

Try

where("LOWER (description) LIKE ? OR LOWER (title) LIKE ?", "%#{search.downcase}%" , "%#{search.downcase}%")
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks David, but this unfortunately returned a MySQL syntax error
I edited my reply (I had misread your question). Does this query work?
FYI the issue was that you were comparing a string to (forced) lowercase database values. If your string had an uppercase character, the comparison would fail. With this query, you also force the search function argument to be lower case, therefore ensuring a match (since both strings are guaranteed to be lowercase).
0

I had this problem, too. Heroku uses PostgreSQL and the LIKE-Operator there is strongly typed to strings. Check this http://www.postgresql.org/docs/8.3/interactive/functions-matching.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.