Find_by_sql help?

How to make it work with paginator (kaminari)?

MySQL and full text search: Words (id, word)

@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?

How to make it work with paginator (kaminari)?

MySQL and full text search: Words (id, word)

@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

Fred

How can I make same query without "find_by_sql"?

How can I make same query without "find_by_sql"?

Stick your conditions in a call to where() and your select clause in
a call to select()

Fred

Frederick Cheung wrote in post #1035593:

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 :frowning:

@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)

Any idea, how make it work?

Frederick Cheung wrote in post #1035593:

> 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 :frowning:

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