@words = Word.find_by_sql([“SELECT id, word, MATCH (word) AGAINST (?) AS
Score FROM words WHERE MATCH (word) AGAINST (?) ORDER BY Score Desc,
word!=?”, params[:search],params[:search],params[:search]])
I can’t add .page(params[:page]).per(5) to the end of “find_by_sql()” so
what can I do?
You need to extract from the paginator what offset and limit to add to
your query. Also, you don’t need to use find_by_sql here, which would
dodge the issue entirely
Stick your conditions in a call to where() and your select clause in
a call to select()
The problem, is that in select() can’t be params:
I need: “SELECT id, word, MATCH (word) AGAINST (?) AS score” and this
doesn’t work
@words = Word.select(“id, word, MATCH (word) AGAINST (?) AS
Score”,params[:search]).where(…)
It’s should be something like this, but this doesn’t work
@words = Word.select(“id, word, MATCH (word) AGAINST (?) AS
Score”,params[:search]).where(“MATCH (word) AGAINST
(?)”,params[:search]).order(“word!=(?), language”,
params[:search]).page(params[:page]).per(5)
@words = Word.select(“id, word, MATCH (word) AGAINST (?) AS
Score”,params[:search]).where(…)
It’s should be something like this, but this doesn’t work
What does doesn’t work mean ? Syntax error, unexpected result set,
mysql exception, something else?
It’s possible that select/order clauses don’t handle bind variables -
you might have to use string interpolation (don’t forget to use
Word.connection.quote to escape the string)
Fred
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.