From c1d2693820b74d86fa372ab9e9f4e52084b0fd9d Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Thu, 4 Feb 2016 01:03:07 -0800 Subject: [PATCH] source_select -> select_v2 --- lib/searchkick/query.rb | 8 ++++---- test/sql_test.rb | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/searchkick/query.rb b/lib/searchkick/query.rb index c68b74c..59d39af 100644 --- a/lib/searchkick/query.rb +++ b/lib/searchkick/query.rb @@ -568,14 +568,14 @@ module Searchkick # An empty array will cause only the _id and _type for each hit to be returned # doc for :select - http://www.elasticsearch.org/guide/reference/api/search/fields/ - # doc for :source_select - https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-source-filtering.html + # doc for :select_v2 - https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-source-filtering.html if options[:select] payload[:fields] = options[:select] if options[:select] != true - elsif options[:source_select] - if options[:source_select] == [] + elsif options[:select_v2] + if options[:select_v2] == [] payload[:fields] = [] # intuitively [] makes sense to return no fields, but ES by default returns all fields else - payload[:_source] = options[:source_select] + payload[:_source] = options[:select_v2] end elsif load # don't need any fields since we're going to load them from the DB anyways diff --git a/test/sql_test.rb b/test/sql_test.rb index 881c0f0..d1b1e77 100644 --- a/test/sql_test.rb +++ b/test/sql_test.rb @@ -111,40 +111,40 @@ class SqlTest < Minitest::Test assert_nil hit["_source"] end - # source_select + # select_v2 - def test_source_select + def test_select_v2 store [{name: "Product A", store_id: 1}] - result = Product.search("product", load: false, source_select: [:name, :store_id]).first + result = Product.search("product", load: false, select_v2: [:name, :store_id]).first assert_equal %w(id name store_id), result.keys.reject { |k| k.start_with?("_") }.sort assert_equal "Product A", result.name assert_equal 1, result.store_id end - def test_source_select_array + def test_select_v2_array store [{name: "Product A", user_ids: [1, 2]}] - result = Product.search("product", load: false, source_select: [:user_ids]).first + result = Product.search("product", load: false, select_v2: [:user_ids]).first assert_equal [1, 2], result.user_ids end - def test_source_select_single_field + def test_select_v2_single_field store [{name: "Product A", store_id: 1}] - result = Product.search("product", load: false, source_select: :name).first + result = Product.search("product", load: false, select_v2: :name).first assert_equal %w(id name), result.keys.reject { |k| k.start_with?("_") }.sort assert_equal "Product A", result.name assert_nil result.store_id end - def test_source_select_all + def test_select_v2_all store [{name: "Product A", user_ids: [1, 2]}] - hit = Product.search("product", source_select: true).hits.first + hit = Product.search("product", select_v2: true).hits.first assert_equal hit["_source"]["name"], "Product A" assert_equal hit["_source"]["user_ids"], [1, 2] end - def test_source_select_none + def test_select_v2_none store [{name: "Product A", user_ids: [1, 2]}] - hit = Product.search("product", source_select: []).hits.first + hit = Product.search("product", select_v2: []).hits.first assert_nil hit["_source"] end -- libgit2 0.21.0