search_flip 3.0.0.beta1 → 3.0.0.beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -0
- data/lib/search_flip/response.rb +1 -9
- data/lib/search_flip/result.rb +19 -0
- data/lib/search_flip/version.rb +1 -1
- data/spec/search_flip/result_spec.rb +17 -0
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8594c0c22592c2dfa8fb54097151a87db3746221586b8c28e4c6c3c5c02dff6c
|
|
4
|
+
data.tar.gz: 55b27e4f8e3bc04c4420280d1dccafbf66e5f7e53cf6914c16f5e5dd3cb5ae10
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d54c4c22ba4637573d590288cf1a2407d0ff066e9c4505e3ee851a431ff6ebdc318424ea3af63b2c4d426f74521e27a1800c361feb97dec37c7d1159328dc819
|
|
7
|
+
data.tar.gz: 1b1bd5e46c5edfc2f1c7d3674564b1bb5627956aee05e16d06e1bdbf1107a70cdd1114bc530cb380db40cc16f383481bafc573c63e1ac3e26b218df97f0d65ed
|
data/CHANGELOG.md
CHANGED
data/lib/search_flip/response.rb
CHANGED
|
@@ -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
|
|
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.
|
data/lib/search_flip/result.rb
CHANGED
|
@@ -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
|
data/lib/search_flip/version.rb
CHANGED
|
@@ -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.
|
|
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-
|
|
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
|
-
|
|
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
|