Commit c1d2693820b74d86fa372ab9e9f4e52084b0fd9d

Authored by Andrew Kane
1 parent 915939df

source_select -> select_v2

Showing 2 changed files with 15 additions and 15 deletions   Show diff stats
lib/searchkick/query.rb
@@ -568,14 +568,14 @@ module Searchkick @@ -568,14 +568,14 @@ module Searchkick
568 568
569 # An empty array will cause only the _id and _type for each hit to be returned 569 # An empty array will cause only the _id and _type for each hit to be returned
570 # doc for :select - http://www.elasticsearch.org/guide/reference/api/search/fields/ 570 # doc for :select - http://www.elasticsearch.org/guide/reference/api/search/fields/
571 - # doc for :source_select - https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-source-filtering.html 571 + # doc for :select_v2 - https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-source-filtering.html
572 if options[:select] 572 if options[:select]
573 payload[:fields] = options[:select] if options[:select] != true 573 payload[:fields] = options[:select] if options[:select] != true
574 - elsif options[:source_select]  
575 - if options[:source_select] == [] 574 + elsif options[:select_v2]
  575 + if options[:select_v2] == []
576 payload[:fields] = [] # intuitively [] makes sense to return no fields, but ES by default returns all fields 576 payload[:fields] = [] # intuitively [] makes sense to return no fields, but ES by default returns all fields
577 else 577 else
578 - payload[:_source] = options[:source_select] 578 + payload[:_source] = options[:select_v2]
579 end 579 end
580 elsif load 580 elsif load
581 # don't need any fields since we're going to load them from the DB anyways 581 # don't need any fields since we're going to load them from the DB anyways
test/sql_test.rb
@@ -111,40 +111,40 @@ class SqlTest < Minitest::Test @@ -111,40 +111,40 @@ class SqlTest < Minitest::Test
111 assert_nil hit["_source"] 111 assert_nil hit["_source"]
112 end 112 end
113 113
114 - # source_select 114 + # select_v2
115 115
116 - def test_source_select 116 + def test_select_v2
117 store [{name: "Product A", store_id: 1}] 117 store [{name: "Product A", store_id: 1}]
118 - result = Product.search("product", load: false, source_select: [:name, :store_id]).first 118 + result = Product.search("product", load: false, select_v2: [:name, :store_id]).first
119 assert_equal %w(id name store_id), result.keys.reject { |k| k.start_with?("_") }.sort 119 assert_equal %w(id name store_id), result.keys.reject { |k| k.start_with?("_") }.sort
120 assert_equal "Product A", result.name 120 assert_equal "Product A", result.name
121 assert_equal 1, result.store_id 121 assert_equal 1, result.store_id
122 end 122 end
123 123
124 - def test_source_select_array 124 + def test_select_v2_array
125 store [{name: "Product A", user_ids: [1, 2]}] 125 store [{name: "Product A", user_ids: [1, 2]}]
126 - result = Product.search("product", load: false, source_select: [:user_ids]).first 126 + result = Product.search("product", load: false, select_v2: [:user_ids]).first
127 assert_equal [1, 2], result.user_ids 127 assert_equal [1, 2], result.user_ids
128 end 128 end
129 129
130 - def test_source_select_single_field 130 + def test_select_v2_single_field
131 store [{name: "Product A", store_id: 1}] 131 store [{name: "Product A", store_id: 1}]
132 - result = Product.search("product", load: false, source_select: :name).first 132 + result = Product.search("product", load: false, select_v2: :name).first
133 assert_equal %w(id name), result.keys.reject { |k| k.start_with?("_") }.sort 133 assert_equal %w(id name), result.keys.reject { |k| k.start_with?("_") }.sort
134 assert_equal "Product A", result.name 134 assert_equal "Product A", result.name
135 assert_nil result.store_id 135 assert_nil result.store_id
136 end 136 end
137 137
138 - def test_source_select_all 138 + def test_select_v2_all
139 store [{name: "Product A", user_ids: [1, 2]}] 139 store [{name: "Product A", user_ids: [1, 2]}]
140 - hit = Product.search("product", source_select: true).hits.first 140 + hit = Product.search("product", select_v2: true).hits.first
141 assert_equal hit["_source"]["name"], "Product A" 141 assert_equal hit["_source"]["name"], "Product A"
142 assert_equal hit["_source"]["user_ids"], [1, 2] 142 assert_equal hit["_source"]["user_ids"], [1, 2]
143 end 143 end
144 144
145 - def test_source_select_none 145 + def test_select_v2_none
146 store [{name: "Product A", user_ids: [1, 2]}] 146 store [{name: "Product A", user_ids: [1, 2]}]
147 - hit = Product.search("product", source_select: []).hits.first 147 + hit = Product.search("product", select_v2: []).hits.first
148 assert_nil hit["_source"] 148 assert_nil hit["_source"]
149 end 149 end
150 150