Commit e406fab179197a73ff1694e4c09c8ee79b3a60a8
1 parent
982dbe11
Exists in
master
and in
18 other branches
Added total_entries option [skip ci]
Showing
4 changed files
with
10 additions
and
3 deletions
Show diff stats
CHANGELOG.md
@@ -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 |