Commit ed7bfccbadbeddbb9dac3a77c209ed3e8f590a0b
1 parent
31491cc8
Exists in
master
and in
29 other branches
Avoid double pagination on find_by_contents
Only paginate with pg_options was given. This fixes a bug on the browse controller where not all results were shown.
Showing
1 changed file
with
6 additions
and
4 deletions
Show diff stats
lib/acts_as_searchable.rb
@@ -29,7 +29,6 @@ module ActsAsSearchable | @@ -29,7 +29,6 @@ module ActsAsSearchable | ||
29 | end | 29 | end |
30 | 30 | ||
31 | def find_by_contents(query, pg_options = {}, options = {}, db_options = {}) | 31 | def find_by_contents(query, pg_options = {}, options = {}, db_options = {}) |
32 | - pg_options[:page] ||= 1 | ||
33 | options[:limit] = 1000000; | 32 | options[:limit] = 1000000; |
34 | options[:scores] = true; | 33 | options[:scores] = true; |
35 | 34 | ||
@@ -40,7 +39,7 @@ module ActsAsSearchable | @@ -40,7 +39,7 @@ module ActsAsSearchable | ||
40 | else | 39 | else |
41 | facets = options.include?(:facets) ? solr_result.facets : {} | 40 | facets = options.include?(:facets) ? solr_result.facets : {} |
42 | if db_options.empty? | 41 | if db_options.empty? |
43 | - results = solr_result.results.paginate(pg_options) | 42 | + results = solr_result.results |
44 | else | 43 | else |
45 | ids = solr_result.results.map{|r|r[:id].to_i} | 44 | ids = solr_result.results.map{|r|r[:id].to_i} |
46 | if ids.empty? | 45 | if ids.empty? |
@@ -53,11 +52,14 @@ module ActsAsSearchable | @@ -53,11 +52,14 @@ module ActsAsSearchable | ||
53 | db_options[:conditions] = "#{table_name}.id in (#{ids.join(', ')})" | 52 | db_options[:conditions] = "#{table_name}.id in (#{ids.join(', ')})" |
54 | end | 53 | end |
55 | 54 | ||
56 | - result = find(:all, db_options) | ||
57 | - results = result.paginate(pg_options) | 55 | + results = find(:all, db_options) |
58 | end | 56 | end |
59 | end | 57 | end |
60 | 58 | ||
59 | + if !pg_options.empty? | ||
60 | + pg_options[:page] ||= 1 | ||
61 | + results = results.paginate(pg_options) | ||
62 | + end | ||
61 | {:results => results, :facets => facets} | 63 | {:results => results, :facets => facets} |
62 | end | 64 | end |
63 | end | 65 | end |