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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Dec 7, 1:25 pm, Fresh Mix <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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> -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
How can I make same query without "find_by_sql"? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Dec 7, 3:16 pm, Fresh Mix <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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> > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 :( @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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Dec 7, 8:32 pm, Fresh Mix <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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 :( >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> @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? > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.