Commit dedc285f697f25aa45f83d46d8c599adabf03c63
1 parent
44bc22ee
Exists in
master
and in
28 other branches
Speed up find_by_contents
Only search the content for one page, loading more than a hundred results is slow cause solr send xmls for us to parse.
Showing
1 changed file
with
7 additions
and
6 deletions
Show diff stats
lib/acts_as_searchable.rb
... | ... | @@ -29,7 +29,9 @@ module ActsAsSearchable |
29 | 29 | end |
30 | 30 | |
31 | 31 | def find_by_contents(query, pg_options = {}, options = {}, db_options = {}) |
32 | - options[:limit] = 1000000; | |
32 | + pg_options[:page] ||= 1 | |
33 | + pg_options[:per_page] ||= 20 | |
34 | + options[:limit] = pg_options[:per_page].to_i*pg_options[:page].to_i | |
33 | 35 | options[:scores] = true; |
34 | 36 | |
35 | 37 | query = !schema_name.empty? ? "+schema_name:\"#{schema_name}\" AND #{query}" : query |
... | ... | @@ -37,7 +39,8 @@ module ActsAsSearchable |
37 | 39 | if solr_result.nil? |
38 | 40 | results = facets = [] |
39 | 41 | else |
40 | - facets = options.include?(:facets) ? solr_result.facets : {} | |
42 | + facets = options.include?(:facets) ? solr_result.facets : [] | |
43 | + | |
41 | 44 | if db_options.empty? |
42 | 45 | results = solr_result.results |
43 | 46 | else |
... | ... | @@ -54,12 +57,10 @@ module ActsAsSearchable |
54 | 57 | |
55 | 58 | results = find(:all, db_options) |
56 | 59 | end |
57 | - end | |
58 | 60 | |
59 | - if !pg_options.empty? | |
60 | - pg_options[:page] ||= 1 | |
61 | - results = results.paginate(pg_options) | |
61 | + results = results.paginate(pg_options.merge(:total_entries => solr_result.total)) | |
62 | 62 | end |
63 | + | |
63 | 64 | {:results => results, :facets => facets} |
64 | 65 | end |
65 | 66 | end | ... | ... |