diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f886e3..7c85af3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Made `exclude` option work with match all - Added `case_sensitive` option - Added `stem` option +- Added `total_entries` option ## 3.1.0 diff --git a/lib/searchkick/query.rb b/lib/searchkick/query.rb index 83bfb39..2b023ad 100644 --- a/lib/searchkick/query.rb +++ b/lib/searchkick/query.rb @@ -19,7 +19,7 @@ module Searchkick :boost_by, :boost_by_distance, :boost_by_recency, :boost_where, :conversions, :conversions_term, :debug, :emoji, :exclude, :execute, :explain, :fields, :highlight, :includes, :index_name, :indices_boost, :limit, :load, :match, :misspellings, :model_includes, :offset, :operator, :order, :padding, :page, :per_page, :profile, - :request_params, :routing, :scope_results, :select, :similar, :smart_aggs, :suggest, :track, :type, :where] + :request_params, :routing, :scope_results, :select, :similar, :smart_aggs, :suggest, :total_entries, :track, :type, :where] raise ArgumentError, "unknown keywords: #{unknown_keywords.join(", ")}" if unknown_keywords.any? term = term.to_s @@ -116,7 +116,8 @@ module Searchkick misspellings: @misspellings, term: term, scope_results: options[:scope_results], - index_name: options[:index_name] + index_name: options[:index_name], + total_entries: options[:total_entries] } if options[:debug] diff --git a/lib/searchkick/results.rb b/lib/searchkick/results.rb index 5f0a277..70f14f3 100644 --- a/lib/searchkick/results.rb +++ b/lib/searchkick/results.rb @@ -132,7 +132,7 @@ module Searchkick end def total_count - response["hits"]["total"] + options[:total_entries] || response["hits"]["total"] end alias_method :total_entries, :total_count diff --git a/test/pagination_test.rb b/test/pagination_test.rb index e5fbc1d..00ab7f4 100644 --- a/test/pagination_test.rb +++ b/test/pagination_test.rb @@ -77,6 +77,11 @@ class PaginationTest < Minitest::Test assert products.first_page? end + def test_total_entries + products = Product.search("product", total_entries: 4) + assert_equal 4, products.total_entries + end + def test_kaminari skip unless defined?(Kaminari) -- libgit2 0.21.0