es-elasticity 0.2.8 → 0.2.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/elasticity/index.rb +1 -1
- data/lib/elasticity/multi_search.rb +12 -9
- data/lib/elasticity/railtie.rb +5 -1
- data/lib/elasticity/search.rb +21 -1
- data/lib/elasticity/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58ea71d50e68bd34f58ea88ebf80197f1fc04083
|
4
|
+
data.tar.gz: 740f4b8b9bc70011fa146245bf2b5f30600f77cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d9f5f2c133c66e27725e8e95051c780a407900f19ad278feae655de91305054e807bfa9fe87b591e57f991540d745790cf4f075f3cfd35f7c3d11c6150f09c2
|
7
|
+
data.tar.gz: ac2228701bf716f8febb33027a75640477b46cd276f47cdaeb1ffee4eed25ad7649588d9e4dd07f37756d576eb775efaab4bf796f5743c4469c6ef888b50d16b
|
data/lib/elasticity/index.rb
CHANGED
@@ -90,7 +90,7 @@ module Elasticity
|
|
90
90
|
private
|
91
91
|
|
92
92
|
def instrument(name, extra = {})
|
93
|
-
ActiveSupport::Notifications.instrument("#{name}.elasticity", args: extra) do
|
93
|
+
ActiveSupport::Notifications.instrument("#{name}.elasticity", args: extra, backtrace: caller(1)) do
|
94
94
|
yield
|
95
95
|
end
|
96
96
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module Elasticity
|
2
2
|
class MultiSearch
|
3
3
|
def initialize
|
4
|
-
@searches =
|
4
|
+
@searches = {}
|
5
|
+
@mappers = {}
|
5
6
|
yield self if block_given?
|
6
7
|
end
|
7
8
|
|
@@ -17,7 +18,9 @@ module Elasticity
|
|
17
18
|
raise ArgumentError, "you need to provide either :documents or :active_records as an option"
|
18
19
|
end
|
19
20
|
|
20
|
-
@searches
|
21
|
+
@searches[name] = { index: search.index.name, type: search.document_type, search: search.body }
|
22
|
+
@mappers[name] = mapper
|
23
|
+
name
|
21
24
|
end
|
22
25
|
|
23
26
|
def [](name)
|
@@ -28,17 +31,17 @@ module Elasticity
|
|
28
31
|
private
|
29
32
|
|
30
33
|
def fetch
|
31
|
-
|
32
|
-
{ index: search.index.name, type: search.document_type, search: search.body }
|
33
|
-
end
|
34
|
+
bodies = @searches.values.map(&:dup)
|
34
35
|
|
35
|
-
response = ActiveSupport::Notifications.instrument("multi_search.elasticity", args: { body:
|
36
|
-
Elasticity.config.client.msearch(body:
|
36
|
+
response = ActiveSupport::Notifications.instrument("multi_search.elasticity", args: { body: @searches.values }) do
|
37
|
+
Elasticity.config.client.msearch(body: bodies)
|
37
38
|
end
|
38
39
|
|
39
40
|
results = {}
|
40
|
-
|
41
|
-
|
41
|
+
|
42
|
+
@searches.keys.each_with_index do |name, idx|
|
43
|
+
resp = response["responses"][idx]
|
44
|
+
mapper = @mappers[name]
|
42
45
|
results[name] = Search::Result.new(resp, mapper)
|
43
46
|
end
|
44
47
|
|
data/lib/elasticity/railtie.rb
CHANGED
@@ -2,12 +2,16 @@ module Elasticity
|
|
2
2
|
class Railtie < Rails::Railtie
|
3
3
|
initializer 'elasticity.initialize_logging' do
|
4
4
|
ActiveSupport::Notifications.subscribe(/\.elasticity$/) do |name, start, finish, id, payload|
|
5
|
-
puts name
|
6
5
|
time = (finish - start)*1000
|
7
6
|
|
8
7
|
if logger = Elasticity.config.logger
|
9
8
|
logger.debug "#{name} #{"%.2f" % time}ms #{MultiJson.dump(payload[:args], pretty: Elasticity.config.pretty_json)}"
|
10
9
|
|
10
|
+
if payload[:backtrace].present?
|
11
|
+
bt = Rails.backtrace_cleaner.clean(payload[:backtrace])
|
12
|
+
logger.debug bt[0,4].join("\n")
|
13
|
+
end
|
14
|
+
|
11
15
|
exception, message = payload[:exception]
|
12
16
|
if exception
|
13
17
|
logger.error "#{name} #{exception}: #{message}"
|
data/lib/elasticity/search.rb
CHANGED
@@ -121,8 +121,28 @@ module Elasticity
|
|
121
121
|
end
|
122
122
|
|
123
123
|
class ActiveRecordMapper
|
124
|
+
class Relation < ActiveSupport::ProxyObject
|
125
|
+
def initialize(relation)
|
126
|
+
@relation = relation
|
127
|
+
end
|
128
|
+
|
129
|
+
def method_missing(name, *args, &block)
|
130
|
+
@relation.public_send(name, *args, &block)
|
131
|
+
end
|
132
|
+
|
133
|
+
def pretty_print(pp)
|
134
|
+
pp.object_group(self) do
|
135
|
+
pp.text " #{@relation.to_sql}"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def inspect
|
140
|
+
"#<#{self.class}: #{@relation.to_sql}>"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
124
144
|
def initialize(relation)
|
125
|
-
@relation = relation
|
145
|
+
@relation = Relation.new(relation)
|
126
146
|
end
|
127
147
|
|
128
148
|
def map(hits)
|
data/lib/elasticity/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: es-elasticity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Kochenburger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|