Pagination using the DSL

timuckun edited this page Apr 4, 2012 · 2 revisions
def self.simple_search(search_terms, options={})
    search = Tire.search Settings.tire.prefix do
      query do
        string search_terms
      end
      highlight '_all'
      sort { by options[:sort], 'asc' } if options[:sort]
      page = (options[:page] || 1).to_i
      search_size = options[:per] || DEFAULT_SIZE
      from (page -1) * search_size
      size search_size
    end
end

@results = Module.simple_search('this OR that', :page => params[:page]).results
 
# you can feed the results into the paginator 

<%= paginate @results unless @results.empty? %>