arelastic 0.4.4 → 0.4.5

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: 86e61299c1a151518149a1394644685e6f9ce879
4
- data.tar.gz: e288608cd5e98ca466f12ea6b7ebf29cd4bbebc8
3
+ metadata.gz: 461f0c1c4638378978028848fa4b076be47c2e2f
4
+ data.tar.gz: 08a45801e8a532840076b49315029a4984ba0632
5
5
  SHA512:
6
- metadata.gz: 94f6f848709e97ecd2d127920b15f1784e36bf2405d0f1c050499babc177cc86b79df22c4d19d190ce58487637de667d7fa9ebfdef3f8480ab23d844a4460c31
7
- data.tar.gz: 594c93e4d097b2d6fdb47077f9f719a638b65f7b472f4b06ce24dacb52fb2e95ae2630d0976bb7e190605cda40104a8476ac7dfd0795ae1b6efea3e76c4a86c4
6
+ metadata.gz: 80d59ba50365fb2902826794e215114d6c28b93d1772328aba566ff18921665f83ec76865863febdda8a7d5e6c0b173a98af2e2cc30e5bdbf68113997c829567
7
+ data.tar.gz: 6c6d9e6b38e7d1717a50a1850aa94f8d4796434f7ada756deaf380e9830093a0a8135fc13aafea999571283f3bdc56d4bc13495a9b93c3cc933224cf41fa0753
@@ -18,7 +18,7 @@ module Arelastic
18
18
  end
19
19
 
20
20
  def as_elastic
21
- {self.class.operator => children.map { |child| convert_to_elastic(child) }}
21
+ {self.class.operator => convert_to_elastic(children)}
22
22
  end
23
23
  end
24
24
  end
@@ -6,7 +6,11 @@ module Arelastic
6
6
  extend Arelastic::Arities::Unary
7
7
 
8
8
  def convert_to_elastic(expr)
9
- expr.respond_to?(:as_elastic) ? expr.as_elastic : expr
9
+ if expr.is_a?(Array)
10
+ expr.map { |e| convert_to_elastic(e) }
11
+ else
12
+ expr.respond_to?(:as_elastic) ? expr.as_elastic : expr
13
+ end
10
14
  end
11
15
 
12
16
  def ==(other)
@@ -1,5 +1,6 @@
1
1
  require 'arelastic/queries/query'
2
2
 
3
+ require 'arelastic/queries/bool'
3
4
  require 'arelastic/queries/constant_score'
4
5
  require 'arelastic/queries/field'
5
6
  require 'arelastic/queries/filtered'
@@ -0,0 +1,19 @@
1
+ module Arelastic
2
+ module Queries
3
+ class Bool < Arelastic::Queries::Query
4
+ attr_accessor :options
5
+ def initialize(options)
6
+ @options = options
7
+ end
8
+
9
+ def as_elastic
10
+ params = {}
11
+ options.each do |key, value|
12
+ params[key] = convert_to_elastic(value)
13
+ end
14
+
15
+ { "bool" => params }
16
+ end
17
+ end
18
+ end
19
+ end
@@ -13,7 +13,7 @@ class Arelastic::Filters::NestedTest < MiniTest::Unit::TestCase
13
13
  }
14
14
  }
15
15
 
16
- assert_equal expected, Arelastic::Filters::Nested.new('bunnies', Arelastic::Searches::Query(Arelastic::Queries::Match.new('name', 'Harry'))).as_elastic
16
+ assert_equal expected, Arelastic::Filters::Nested.new('bunnies', Arelastic::Searches::Query.new(Arelastic::Queries::Match.new('name', 'Harry'))).as_elastic
17
17
  end
18
18
 
19
19
  end
@@ -0,0 +1,39 @@
1
+ require 'helper'
2
+
3
+ class Arelastic::Queries::BoolTest < MiniTest::Unit::TestCase
4
+ def test_as_elastic
5
+ bool = Arelastic::Queries::Bool.new(
6
+ 'must' => {
7
+ 'prefix' => {
8
+ 'user' => 'kimchy'
9
+ }
10
+ },
11
+ 'must_not' => Arelastic::Queries::Match.new('color', 'green'),
12
+ 'should' => [
13
+ Arelastic::Queries::Match.new('height', 6)
14
+ ]
15
+ )
16
+
17
+ expected = {
18
+ 'bool' => {
19
+ 'must' => {
20
+ 'prefix' => {
21
+ 'user' => 'kimchy'
22
+ }
23
+ },
24
+ 'must_not' => {
25
+ 'match' => {
26
+ 'color'=>'green'
27
+ }
28
+ },
29
+ 'should' => [
30
+ 'match' => {
31
+ 'height' => 6
32
+ }
33
+ ]
34
+ }
35
+ }
36
+
37
+ assert_equal expected, bool.as_elastic
38
+ end
39
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arelastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Higgins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-20 00:00:00.000000000 Z
11
+ date: 2013-10-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Build Elastic Search queries with objects
14
14
  email: developer@matthewhiggins.com
@@ -63,6 +63,7 @@ files:
63
63
  - lib/arelastic/nodes/hash_group.rb
64
64
  - lib/arelastic/nodes/node.rb
65
65
  - lib/arelastic/nodes.rb
66
+ - lib/arelastic/queries/bool.rb
66
67
  - lib/arelastic/queries/constant_score.rb
67
68
  - lib/arelastic/queries/field.rb
68
69
  - lib/arelastic/queries/filtered.rb
@@ -112,6 +113,7 @@ files:
112
113
  - test/arelastic/mappings/types/multi_field_test.rb
113
114
  - test/arelastic/mappings/types/string_test.rb
114
115
  - test/arelastic/nodes/node_test.rb
116
+ - test/arelastic/queries/bool_test.rb
115
117
  - test/arelastic/queries/filtered_test.rb
116
118
  - test/arelastic/queries/match_all_test.rb
117
119
  - test/arelastic/queries/multi_match_test.rb