Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- +module Sunspot
- + # monkey patch for Sunspot v 1.1.1 to add support for solr "start" query parameter
- + # we can now optionally add a :start number to offset search results
- + # in this scenario, we want the first 3 results for the carousel, and then 5 more
- + # the code as is requires the start to be set to 3 and the per_page to 8 for this to work
- + # a better solution would be to modify the per_page= method but I was unable to do this
- + # with alias_method_chain, BF 12/6
- + module Query
- + class Pagination
- +
- + def start_offset=(offset)
- + @start_offset = offset
- + end
- +
- + def start_offset
- + @start_offset || 0
- + end
- +
- + private
- +
- + def start_with_start_offset
- + start_offset + start_without_start_offset
- + end
- +
- + alias_method_chain(:start,:start_offset)
- + end
- + end
- +
- + module DSL
- + module Paginatable
- + def paginate(options = {})
- + page = options.delete(:page)
- + per_page = options.delete(:per_page)
- + offset = options.delete(:start_offset) # remove term so we don't throw an error when an offset passed in
- + raise ArgumentError, "unknown argument #{options.keys.first.inspect} passed to paginate" unless options.empty?
- + @query.paginate(page, per_page)
- + end
- + end
- + end
- +
- +end
- +
- +
- +
Add Comment
Please, Sign In to add comment