Permalink
Browse files

a search result returns the current page, this means integration with…

… will_paginate
  • Loading branch information...
1 parent 4065b8d commit 4427490f79b6ae65252d2175dc0feb2412608c37 @dcrec1 dcrec1 committed May 22, 2010
View
6 lib/acts_as_solr/parser_methods.rb
@@ -141,7 +141,11 @@ def parse_results(solr_data, options = {})
results.update(:facets => solr_data.data['facet_counts']) if options[:facets]
results.update({:docs => result, :total => solr_data.total_hits, :max_score => solr_data.max_score, :query_time => solr_data.data['responseHeader']['QTime']})
results.update({:highlights=>highlighted})
- results.update :rows => solr_data.header['params']['rows'].to_i unless solr_data.header['params'].nil?
+ unless solr_data.header['params'].nil?
+ header = solr_data.header
+ results.update :rows => header['params']['rows']
+ results.update :start => header['params']['start']
+ end
SearchResults.new(results)
end
View
5 lib/acts_as_solr/search_results.rb
@@ -78,6 +78,11 @@ def total_pages
(total / per_page.to_f).ceil
end
+ # Returns the current page
+ def current_page
+ (@solr_data[:start].to_i / per_page.to_i) + 1
+ end
+
alias docs results
alias records results
alias num_found total
View
8 test/functional/acts_as_solr_test.rb
@@ -478,4 +478,12 @@ def test_total_pages_is_returned_when_limit_specified
def test_total_pages_is_returned_when_limit_not_specified
assert_equal 1, Posting.search("test").total_pages
end
+
+ def test_current_page_is_returned
+ assert_equal 2, Posting.search("test", :limit => 1, :offset => 1).current_page
+ end
+
+ def test_current_page_1_is_returned
+ assert_equal 1, Posting.search("test").current_page
+ end
end

0 comments on commit 4427490

Please sign in to comment.