search_flip 3.0.0.beta1 → 3.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ed1af68a35f862ad7a429b646afeab420d78161b29e8833daf3a2e37048cb26
4
- data.tar.gz: 499dfeffd4abd5b21fc966b6d04b61130fe6bf1ffb771b3d97f92e4473592701
3
+ metadata.gz: 8594c0c22592c2dfa8fb54097151a87db3746221586b8c28e4c6c3c5c02dff6c
4
+ data.tar.gz: 55b27e4f8e3bc04c4420280d1dccafbf66e5f7e53cf6914c16f5e5dd3cb5ae10
5
5
  SHA512:
6
- metadata.gz: 0c1a401732c4ee47aa7e23e750496afa445e274c7fed20f28c27dbf136e2f795123cb805bc9f3513c26be1f2330ed6a0f82da145a4110e8c35858c951d3a8297
7
- data.tar.gz: 61ffd4396bb2e3c4372fd5389ffdff0b695dbc80a74c1439855cb7e8fb7f8fe4c6d1aab127d22bc789485427d43f5dad0835c8325c575c295d82a4de5235893d
6
+ metadata.gz: d54c4c22ba4637573d590288cf1a2407d0ff066e9c4505e3ee851a431ff6ebdc318424ea3af63b2c4d426f74521e27a1800c361feb97dec37c7d1159328dc819
7
+ data.tar.gz: 1b1bd5e46c5edfc2f1c7d3674564b1bb5627956aee05e16d06e1bdbf1107a70cdd1114bc530cb380db40cc16f383481bafc573c63e1ac3e26b218df97f0d65ed
data/CHANGELOG.md CHANGED
@@ -20,6 +20,7 @@
20
20
  * `Connection#cat_indices/get_indices` now accepts additional parameters
21
21
  * `Connection#freeze_index`, `Connection#unfreeze_index`, `Index#freeze_index`
22
22
  and `Index#unfreeze_index` added
23
+ * Added `SearchFlip::Result.from_hit`
23
24
 
24
25
  ## v2.3.1
25
26
 
@@ -166,15 +166,7 @@ module SearchFlip
166
166
  # @return [Array] An array of results
167
167
 
168
168
  def results
169
- @results ||= hits["hits"].map do |hit|
170
- raw_result = hit["_source"]
171
-
172
- raw_result["_hit"] = hit.each_with_object({}) do |(key, value), hash|
173
- hash[key] = value if key != "_source"
174
- end
175
-
176
- Result.new(raw_result)
177
- end
169
+ @results ||= hits["hits"].map { |hit| Result.from_hit(hit) }
178
170
  end
179
171
 
180
172
  # Returns the named sugggetion, if a name is specified or alle suggestions.
@@ -6,5 +6,24 @@ module SearchFlip
6
6
  def self.disable_warnings?(*args)
7
7
  true
8
8
  end
9
+
10
+ # Creates a SearchFlip::Result object from a raw hit. Useful for e.g.
11
+ # top hits aggregations.
12
+ #
13
+ # @example
14
+ # query = ProductIndex.aggregate(top_sales: { top_hits: "..." })
15
+ # top_sales_hits = query.aggregations(:top_sales).top_hits.hits.hits
16
+ #
17
+ # SearchFlip::Result.from_hit(top_sales_hits.first)
18
+
19
+ def self.from_hit(hit)
20
+ raw_result = hit["_source"].dup
21
+
22
+ raw_result["_hit"] = hit.each_with_object({}) do |(key, value), hash|
23
+ hash[key] = value if key != "_source"
24
+ end
25
+
26
+ new(raw_result)
27
+ end
9
28
  end
10
29
  end
@@ -1,3 +1,3 @@
1
1
  module SearchFlip
2
- VERSION = "3.0.0.beta1"
2
+ VERSION = "3.0.0.beta2"
3
3
  end
@@ -0,0 +1,17 @@
1
+ require File.expand_path("../spec_helper", __dir__)
2
+
3
+ RSpec.describe SearchFlip::Result do
4
+ describe ".from_hit" do
5
+ it "adds a _hit key into _source and merges the hit keys into it" do
6
+ result = SearchFlip::Result.from_hit("_score" => 1.0, "_source" => { "name" => "Some name" })
7
+
8
+ expect(result).to eq("name" => "Some name", "_hit" => { "_score" => 1.0 })
9
+ end
10
+
11
+ it "allows deep method access" do
12
+ result = SearchFlip::Result.from_hit("_source" => { "key1" => [{ "key2" => "value" }] })
13
+
14
+ expect(result.key1[0].key2).to eq("value")
15
+ end
16
+ end
17
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: search_flip
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.beta1
4
+ version: 3.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Vetter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-13 00:00:00.000000000 Z
11
+ date: 2020-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -224,6 +224,7 @@ files:
224
224
  - spec/search_flip/index_spec.rb
225
225
  - spec/search_flip/model_spec.rb
226
226
  - spec/search_flip/response_spec.rb
227
+ - spec/search_flip/result_spec.rb
227
228
  - spec/search_flip/to_json_spec.rb
228
229
  - spec/spec_helper.rb
229
230
  homepage: https://github.com/mrkamel/search_flip
@@ -248,8 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
248
249
  - !ruby/object:Gem::Version
249
250
  version: 1.3.1
250
251
  requirements: []
251
- rubyforge_project:
252
- rubygems_version: 2.7.3
252
+ rubygems_version: 3.0.3
253
253
  signing_key:
254
254
  specification_version: 4
255
255
  summary: Full-Featured Elasticsearch Ruby Client with a Chainable DSL
@@ -263,5 +263,6 @@ test_files:
263
263
  - spec/search_flip/index_spec.rb
264
264
  - spec/search_flip/model_spec.rb
265
265
  - spec/search_flip/response_spec.rb
266
+ - spec/search_flip/result_spec.rb
266
267
  - spec/search_flip/to_json_spec.rb
267
268
  - spec/spec_helper.rb