es_tractor 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c95803c8427c65509539485cdae392f49ff00373
4
- data.tar.gz: 7fbf6a5eab0236b6c80bfda83fdfd6bd933a0417
3
+ metadata.gz: 81b24cb42d1f02473ff67c94f7bac55727670db8
4
+ data.tar.gz: f0050eb804dad31fdc1ebb054c7ba2cf3cd845cd
5
5
  SHA512:
6
- metadata.gz: 4693b910db8165c76056665d562332a14217f4d7a5fa0538c93df9d80cda4c4b9cbbc0ec104be2b7dea32e0e1ddd5cd32282369f21390e4de7ef89f971da6a1b
7
- data.tar.gz: 296367c0e4c487087de040ca2def83761098b14af7a3b46dbf68ab959c76a6bdc7f35b77c7b1405c326a75acba5675ef7ada3d5883ae6cbbdc7dd91c8ccf216a
6
+ metadata.gz: a203a98c2fa74ae46cdb05f3ed146af4abec25c5f6605b0ed6b362413e8cfac16b27261e03dc1b47887648968b59013067e9cd63c476c04e396af6a3a84a9ccf
7
+ data.tar.gz: dec2d62a0179aef4608c3544b50dcb97707cc6daba78447a107725caeed63f8a7428864ed275bbc4e9e5a5d55aaff0646c383102268a1c7a7357fe2393d44174
@@ -1,3 +1,7 @@
1
+ === 0.0.6 / 2017-10-22
2
+
3
+ * Doc and test for fields and sort
4
+
1
5
  === 0.0.5 / 2017-10-12
2
6
 
3
7
  * Add fields and sort
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  $LOAD_PATH.unshift File.dirname(__FILE__) + '/es_tractor'
3
4
  $LOAD_PATH.unshift File.dirname(__FILE__) \
4
5
  unless $LOAD_PATH.include?(File.dirname(__FILE__))
@@ -9,5 +10,5 @@ require 'client'
9
10
  # EsTractor provides tools to query Elasticsearch
10
11
 
11
12
  module EsTractor
12
- VERSION = '0.0.5' # :nodoc:
13
+ VERSION = '0.0.6' # :nodoc:
13
14
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'elasticsearch'
3
4
 
4
5
  module EsTractor
@@ -122,6 +123,8 @@ module EsTractor
122
123
  # Field name on which to apply the cardinality aggregation
123
124
  # @option opts [String] :extended_stats
124
125
  # Field name on which to apply the extended_stats aggregation
126
+ # @option opts [Array] :fields
127
+ # Field names to return
125
128
  # @option opts [String] :geo_bounds
126
129
  # Field name on which to apply the geo_bounds aggregation
127
130
  # @option opts [String] :geo_centroid
@@ -132,6 +135,8 @@ module EsTractor
132
135
  # Field name on which to apply the min aggregation
133
136
  # @option opts [String] :percentiles
134
137
  # Field name on which to apply the percentiles aggregation
138
+ # @option opts [Array] :sort
139
+ # Contains Hashes keyd on field name
135
140
  # @option opts [String] :stats
136
141
  # Field name on which to apply the stats aggregation
137
142
  # @option opts [String] :sum
@@ -154,8 +159,8 @@ module EsTractor
154
159
  end
155
160
 
156
161
  def metrics_aggs
157
- %i(avg cardinality extended_stats geo_bounds geo_centroid max min
158
- percentiles stats sum value_count)
162
+ %i[avg cardinality extended_stats geo_bounds geo_centroid max min
163
+ percentiles stats sum value_count]
159
164
  end
160
165
 
161
166
  def aggs(opts)
@@ -191,7 +196,7 @@ module EsTractor
191
196
  def query(opts = {})
192
197
  bool = { filter: [], must: [] }
193
198
 
194
- (%i(exists match query_string range term) & opts.keys)
199
+ (%i[exists match query_string range term] & opts.keys)
195
200
  .each do |qualifier|
196
201
  case qualifier
197
202
  when :exists
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  ENV['ESTRACTOR_ENV'] = 'test'
3
4
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'helper'
3
4
 
4
5
  module EsTractor
@@ -7,7 +8,7 @@ module EsTractor
7
8
  @tractor = Client.new
8
9
  end
9
10
 
10
- %w(count search).each do |action|
11
+ %w[count search].each do |action|
11
12
  exp = action == 'search' ? { from: 0, size: 0 } : {}
12
13
 
13
14
  define_method "test_#{action}_with_term_hash" do
@@ -94,14 +95,14 @@ module EsTractor
94
95
  end
95
96
 
96
97
  define_method "test_#{action}_with_exists_fieldname_array" do
97
- opts = { exists: %w(my_field my_other_field) }
98
+ opts = { exists: %w[my_field my_other_field] }
98
99
  exp[:body] = { query: {
99
100
  bool: {
100
101
  must: [],
101
102
  filter: [
102
103
  {
103
104
  exists: {
104
- field: %w(my_field my_other_field),
105
+ field: %w[my_field my_other_field],
105
106
  },
106
107
  },
107
108
  ],
@@ -129,10 +130,52 @@ module EsTractor
129
130
 
130
131
  next unless action == 'search'
131
132
 
132
- %i(
133
+ def test_search_with_fields_arg
134
+ opts = { fields: [:some_field] }
135
+ exp = {
136
+ from: 0,
137
+ size: 0,
138
+ body: {
139
+ query: {
140
+ bool: {
141
+ filter: [],
142
+ must: [],
143
+ },
144
+ },
145
+ fields: [:some_field]
146
+ },
147
+ }
148
+
149
+ @tractor.client.expects(:search).with(exp)
150
+
151
+ @tractor.search opts
152
+ end
153
+
154
+ def test_search_with_sort_arg
155
+ opts = { sort: [:some_field] }
156
+ exp = {
157
+ from: 0,
158
+ size: 0,
159
+ body: {
160
+ query: {
161
+ bool: {
162
+ filter: [],
163
+ must: [],
164
+ },
165
+ },
166
+ sort: [:some_field]
167
+ },
168
+ }
169
+
170
+ @tractor.client.expects(:search).with(exp)
171
+
172
+ @tractor.search opts
173
+ end
174
+
175
+ %i[
133
176
  avg cardinality extended_stats geo_bounds geo_centroid max min
134
177
  percentiles stats sum value_count
135
- ).each do |aggregation|
178
+ ].each do |aggregation|
136
179
  define_method "test_search_with_#{aggregation}_agg" do
137
180
  opts = {
138
181
  query_string: 'My query string',
@@ -142,17 +185,13 @@ module EsTractor
142
185
  from: 0,
143
186
  size: 0,
144
187
  body: {
145
- query: {
146
- bool: {
147
- must: [query_string: { query: 'My query string' }],
148
- filter: [],
149
- },
150
- },
151
- aggs: {
152
- "#{aggregation}-grade".to_sym => {
153
- aggregation => { field: 'grade' }
154
- },
155
- },
188
+ query: { bool: {
189
+ must: [query_string: { query: 'My query string' }],
190
+ filter: [],
191
+ }, },
192
+ aggs: { "#{aggregation}-grade".to_sym => {
193
+ aggregation => { field: 'grade' }
194
+ }, },
156
195
  },
157
196
  }
158
197
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'helper'
3
4
 
4
5
  class TestEsTractor < Test
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: es_tractor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oz Shelach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-12 00:00:00.000000000 Z
11
+ date: 2017-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: elasticsearch