Commit 842926f6bbc5e1478e9abbd9d35c96d94c160c19

Authored by Andrew Kane
2 parents f48fbce3 54e6a38a

Merge branch 'sharshenov-include-search-data'

CHANGELOG.md
1 1 ## 0.8.5 [unreleased]
2 2  
3 3 - Added `unsearchable` option
  4 +- Added `select: true` option
4 5  
5 6 ## 0.8.4
6 7  
... ...
lib/searchkick/query.rb
... ... @@ -355,10 +355,10 @@ module Searchkick
355 355  
356 356 # An empty array will cause only the _id and _type for each hit to be returned
357 357 # http://www.elasticsearch.org/guide/reference/api/search/fields/
358   - if load
  358 + if options[:select]
  359 + payload[:fields] = options[:select] if options[:select] != true
  360 + elsif load
359 361 payload[:fields] = []
360   - elsif options[:select]
361   - payload[:fields] = options[:select]
362 362 end
363 363  
364 364 if options[:type] or klass != searchkick_klass
... ...
test/sql_test.rb
... ... @@ -298,6 +298,13 @@ class TestSql < Minitest::Test
298 298 assert_equal [1, 2], result.user_ids
299 299 end
300 300  
  301 + def test_select_all
  302 + store [{name: "Product A", user_ids: [1, 2]}]
  303 + hit = Product.search("product", select: true).send(:hits).first
  304 + assert_equal hit["_source"]["name"], "Product A"
  305 + assert_equal hit["_source"]["user_ids"], [1, 2]
  306 + end
  307 +
301 308 def test_nested_object
302 309 aisle = {"id" => 1, "name" => "Frozen"}
303 310 store [{name: "Product A", aisle: aisle}]
... ...