ferret采用will_paginate实现分页

ferret采用will_paginate实现分页

rails_env有ferret经典教材有分页的实现,但貌似有点点粗.我结合will_paginate改了下
原来的代码
------------------------------------
def self.full_text_search(q, options = {})
return nil if q.nil? or q==""
default_options = {:limit => 10, age => 1}
options = default_options.merge options

# get the offset based on what page we're on
options[ffset] = options[:limit] * (options.delete(age).to_i-1)

# now do the query with our options
results = Member.find_by_contents(q, options)
return [results.total_hits, results]
end
-----------------------------------
现在的
---------------------------------------
def self.full_text_search(q,options = {})
return nil if q.nil? or q==""
default_options = {:limit => 10, age => 1 ,:sort => [score_sort],:type => :integer}
options = default_options.merge options
page = options[age]||1
# get the offset based on what page we're on
options[ffset] = options[:limit] * (options.delete(age).to_i-1)
# now do the query with our options
res = Vendor.find_by_contents(q, options)
returning WillPaginate::Collection.new(page,options[:limit], res.total_hits) do |pager|
pager.replace res
end
end

你可能感兴趣的:(Rails)