Commit 4bb79fdb2347e126c69781ccebb5d1ee8851f612

Authored by Rustam Sharshenov
1 parent da2b7e14

Force select fields. Add :all value for select.

Showing 2 changed files with 10 additions and 3 deletions   Show diff stats
lib/searchkick/query.rb
@@ -355,10 +355,10 @@ module Searchkick @@ -355,10 +355,10 @@ module Searchkick
355 355
356 # An empty array will cause only the _id and _type for each hit to be returned 356 # An empty array will cause only the _id and _type for each hit to be returned
357 # http://www.elasticsearch.org/guide/reference/api/search/fields/ 357 # http://www.elasticsearch.org/guide/reference/api/search/fields/
358 - if load 358 + if options[:select]
  359 + payload[:fields] = options[:select] unless options[:select].respond_to?(:to_sym) and options[:select].to_sym == :all
  360 + elsif load
359 payload[:fields] = [] 361 payload[:fields] = []
360 - elsif options[:select]  
361 - payload[:fields] = options[:select]  
362 end 362 end
363 363
364 if options[:type] or klass != searchkick_klass 364 if options[:type] or klass != searchkick_klass
test/sql_test.rb
@@ -298,6 +298,13 @@ class TestSql < Minitest::Test @@ -298,6 +298,13 @@ class TestSql < Minitest::Test
298 assert_equal [1, 2], result.user_ids 298 assert_equal [1, 2], result.user_ids
299 end 299 end
300 300
  301 + def test_select_all
  302 + store [{name: "Product A", user_ids: [1, 2]}]
  303 + hit = Product.search("product", select: :all).__send__(:hits).first
  304 + assert_equal hit["_source"]["name"], "Product A"
  305 + assert_equal hit["_source"]["user_ids"], [1, 2]
  306 + end
  307 +
301 def test_nested_object 308 def test_nested_object
302 aisle = {"id" => 1, "name" => "Frozen"} 309 aisle = {"id" => 1, "name" => "Frozen"}
303 store [{name: "Product A", aisle: aisle}] 310 store [{name: "Product A", aisle: aisle}]