I call a fairly simple function and cannot understand what is going on. (I am using rails 3.0.3 and the leading branch "will_paginate" gem). I have the following code:
results = Article.search(params)
@search_results = results.paginate :page => params[:page], :per_page=>8, :order => order_clause
No matter what I do order_clause (for example, "article_title desc" and "article_title asc"), the results are always the same in the same order. Therefore, when I check the use of something of a type @search_results[0], the element is always the same. In my opinion, they are obviously always the same. Am I missing something?
I'm sure this is something stupid, but I hit my head against the wall all night. Any help would be greatly appreciated!
Edited to add: a search clause performs the following actions:
def self.search(params)
full_text_search(params[:query].to_s).
category_search(params[:article_category].blank? ? '' : params[:article_category][:name]).
payout_search(params[:payout_direction], params[:payout_value]).
length_search(params[:length_direction], params[:length_value]).
pending.
distinct.
all
end
where each of these guys is a search function like this:
scope :text_search, lambda {|query|
{
:joins => "INNER JOIN users ON users.id IN (articles.writer_id, articles.buyer_id)",
:conditions => ["(articles.article_title LIKE :query) OR
(articles.description LIKE :query) OR
(users.first_name LIKE :query) OR
(users.last_name LIKE :query)", { :query => "%#{query}%" }]
}
}
scope :distinct, :select => "distinct articles.*"
def self.payout_search(dir, val)
return no_op if val.blank?
send("payment_amount_#{dir.gsub(/\s+/,'').underscore}", val)
end
def self.length_search(dir, val)
return no_op if val.blank?
send("min_words_#{dir.gsub(/\s+/,'').underscore}", val)
end
.