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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b092a148409adc4a7e11885a4be8a235d7933dcb
4
- data.tar.gz: 8049626e93cbeb9f26d5f88859fa422b6425925c
3
+ metadata.gz: 58ea71d50e68bd34f58ea88ebf80197f1fc04083
4
+ data.tar.gz: 740f4b8b9bc70011fa146245bf2b5f30600f77cd
5
5
  SHA512:
6
- metadata.gz: fa7dd7e2e17f990df9a65fc62ca31b7c498374e35ff95051f77747a3d41ec859eb65ecef3bf33ebd9149eadf7781f4b6d1d94cd0e7b632314f0150e8007295d6
7
- data.tar.gz: ec226e57b6332ee5734a91272e3939218d7d80dc71c4eebe60d86a275eebbea0563e52ced4f5452f4bad57ef4b079ffe6fcb5b9302e354ffa7e445807386c5e9
6
+ metadata.gz: 0d9f5f2c133c66e27725e8e95051c780a407900f19ad278feae655de91305054e807bfa9fe87b591e57f991540d745790cf4f075f3cfd35f7c3d11c6150f09c2
7
+ data.tar.gz: ac2228701bf716f8febb33027a75640477b46cd276f47cdaeb1ffee4eed25ad7649588d9e4dd07f37756d576eb775efaab4bf796f5743c4469c6ef888b50d16b
@@ -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 << [name, search, mapper]
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
- multi_body = @searches.map do |name, search, _|
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: multi_body }) do
36
- Elasticity.config.client.msearch(body: multi_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
- Array(response["responses"]).each_with_index do |resp, idx|
41
- name, search, mapper = @searches[idx]
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
 
@@ -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}"
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module Elasticity
2
- VERSION = "0.2.8"
2
+ VERSION = "0.2.11"
3
3
  end
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.8
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-21 00:00:00.000000000 Z
11
+ date: 2014-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler