Commit e406fab179197a73ff1694e4c09c8ee79b3a60a8

Authored by Andrew
1 parent 982dbe11

Added total_entries option [skip ci]

@@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
4 - Made `exclude` option work with match all 4 - Made `exclude` option work with match all
5 - Added `case_sensitive` option 5 - Added `case_sensitive` option
6 - Added `stem` option 6 - Added `stem` option
  7 +- Added `total_entries` option
7 8
8 ## 3.1.0 9 ## 3.1.0
9 10
lib/searchkick/query.rb
@@ -19,7 +19,7 @@ module Searchkick @@ -19,7 +19,7 @@ module Searchkick
19 :boost_by, :boost_by_distance, :boost_by_recency, :boost_where, :conversions, :conversions_term, :debug, :emoji, :exclude, :execute, :explain, 19 :boost_by, :boost_by_distance, :boost_by_recency, :boost_where, :conversions, :conversions_term, :debug, :emoji, :exclude, :execute, :explain,
20 :fields, :highlight, :includes, :index_name, :indices_boost, :limit, :load, 20 :fields, :highlight, :includes, :index_name, :indices_boost, :limit, :load,
21 :match, :misspellings, :model_includes, :offset, :operator, :order, :padding, :page, :per_page, :profile, 21 :match, :misspellings, :model_includes, :offset, :operator, :order, :padding, :page, :per_page, :profile,
22 - :request_params, :routing, :scope_results, :select, :similar, :smart_aggs, :suggest, :track, :type, :where] 22 + :request_params, :routing, :scope_results, :select, :similar, :smart_aggs, :suggest, :total_entries, :track, :type, :where]
23 raise ArgumentError, "unknown keywords: #{unknown_keywords.join(", ")}" if unknown_keywords.any? 23 raise ArgumentError, "unknown keywords: #{unknown_keywords.join(", ")}" if unknown_keywords.any?
24 24
25 term = term.to_s 25 term = term.to_s
@@ -116,7 +116,8 @@ module Searchkick @@ -116,7 +116,8 @@ module Searchkick
116 misspellings: @misspellings, 116 misspellings: @misspellings,
117 term: term, 117 term: term,
118 scope_results: options[:scope_results], 118 scope_results: options[:scope_results],
119 - index_name: options[:index_name] 119 + index_name: options[:index_name],
  120 + total_entries: options[:total_entries]
120 } 121 }
121 122
122 if options[:debug] 123 if options[:debug]
lib/searchkick/results.rb
@@ -132,7 +132,7 @@ module Searchkick @@ -132,7 +132,7 @@ module Searchkick
132 end 132 end
133 133
134 def total_count 134 def total_count
135 - response["hits"]["total"] 135 + options[:total_entries] || response["hits"]["total"]
136 end 136 end
137 alias_method :total_entries, :total_count 137 alias_method :total_entries, :total_count
138 138
test/pagination_test.rb
@@ -77,6 +77,11 @@ class PaginationTest < Minitest::Test @@ -77,6 +77,11 @@ class PaginationTest < Minitest::Test
77 assert products.first_page? 77 assert products.first_page?
78 end 78 end
79 79
  80 + def test_total_entries
  81 + products = Product.search("product", total_entries: 4)
  82 + assert_equal 4, products.total_entries
  83 + end
  84 +
80 def test_kaminari 85 def test_kaminari
81 skip unless defined?(Kaminari) 86 skip unless defined?(Kaminari)
82 87