elastic-rails 0.6.2 → 0.6.3

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: 90b6db33bed1636b6da9df58b85bcc09af897e4c
4
- data.tar.gz: 5d5b72ba7731c3e650aa5df56fb40014c9aee787
3
+ metadata.gz: 7b7327309b8afdf84080efb767efa3ba254db36e
4
+ data.tar.gz: 74a5e89ab5f4b8dff0e547cd6eca69a7534bca72
5
5
  SHA512:
6
- metadata.gz: 58dfe90b0d76dd018762f1dd0d9016a2abfd758df48025289395f000e03819b0cc0983457a37d2600b10e8c7392e2989543d1e0eeba88c9c90593a35ca050b9b
7
- data.tar.gz: cc29015434afc2a7e5408547d89d830ee17a9d57afff15e6644cee2231b2e801042f195ba0a2d6fd899bb3a60cff6c21a6c4f8eedc2bef1ff9a9ad7c594fbc65
6
+ metadata.gz: 917fcdbc89a3fb8e9e1abb860426f2b574578483c14735f66c2eb1d9e9411d526ffe7ba0b46abcc86aa9a43d697ff0082a2b0d96181c2ccacff891faf0c449db
7
+ data.tar.gz: 1cae5b66a5cd48eb3f802ca733e657e39a84ce028b1bceba55f2e5f15ad24a1469c9d29d7cb4ddff8d22332f7871b27da5269d7191f6b2d36e3d08637c8bca1a
@@ -10,6 +10,12 @@ module Elastic::Dsl
10
10
  end
11
11
  end
12
12
 
13
+ def must_not(*_queries)
14
+ with_bool_query do |query|
15
+ query.must_not build_query_from_params(_queries)
16
+ end
17
+ end
18
+
13
19
  def should(*_queries)
14
20
  with_bool_query do |query|
15
21
  query.should build_query_from_params(_queries)
@@ -15,6 +15,7 @@ module Elastic::Nodes
15
15
  def initialize
16
16
  super
17
17
  @musts = []
18
+ @must_nots = []
18
19
  @shoulds = []
19
20
  @filters = []
20
21
  @disable_coord = !Elastic::Configuration.coord_similarity
@@ -24,6 +25,10 @@ module Elastic::Nodes
24
25
  @musts << _node
25
26
  end
26
27
 
28
+ def must_not(_node)
29
+ @must_nots << _node
30
+ end
31
+
27
32
  def should(_node)
28
33
  @shoulds << _node
29
34
  end
@@ -40,6 +45,14 @@ module Elastic::Nodes
40
45
  @musts.each
41
46
  end
42
47
 
48
+ def must_nots=(_nodes)
49
+ @must_nots = _nodes.dup.to_a
50
+ end
51
+
52
+ def must_nots
53
+ @must_nots.each
54
+ end
55
+
43
56
  def shoulds=(_nodes)
44
57
  @shoulds = _nodes.dup.to_a
45
58
  end
@@ -65,6 +78,7 @@ module Elastic::Nodes
65
78
  def render(_options = {})
66
79
  hash = {}
67
80
  hash['must'] = @musts.map { |n| n.render(_options) } if !@musts.empty?
81
+ hash['must_not'] = @must_nots.map { |n| n.render(_options) } if !@must_nots.empty?
68
82
  hash['should'] = @shoulds.map { |n| n.render(_options) } if !@shoulds.empty?
69
83
  hash['filters'] = @filters.map { |n| n.render(_options) } if !@filters.empty?
70
84
  hash['minimum_should_match'] = minimum_should_match unless minimum_should_match.nil?
@@ -75,28 +89,37 @@ module Elastic::Nodes
75
89
  end
76
90
 
77
91
  def clone
78
- prepare_clone super, @musts.map(&:clone), @shoulds.map(&:clone), @filters.map(&:clone)
92
+ prepare_clone(
93
+ super,
94
+ @musts.map(&:clone),
95
+ @must_nots.map(&:clone),
96
+ @shoulds.map(&:clone),
97
+ @filters.map(&:clone)
98
+ )
79
99
  end
80
100
 
81
101
  def simplify
82
102
  new_must = @musts.map(&:simplify)
103
+ new_must_not = @must_nots.map(&:simplify)
83
104
  new_should = @shoulds.map(&:simplify)
84
105
  new_filter = @filters.map(&:simplify)
85
106
 
86
107
  # TODO: detect must elements with boost = 0 and move them to "filter"
87
108
 
88
- if boost.nil? && (new_must.length + new_should.length + new_filter.length) == 1
89
- return new_must.first unless new_must.empty?
90
- return new_should.first unless new_should.empty? # at least 1 should match
109
+ total_nodes = new_must.length + new_must_not.length + new_should.length + new_filter.length
110
+ if boost.nil? && total_nodes == 1
111
+ return new_must.first if !new_must.empty?
112
+ return new_should.first if !new_should.empty? # at least 1 should match
91
113
  end
92
114
 
93
- prepare_clone(super, new_must, new_should, new_filter)
115
+ prepare_clone(super, new_must, new_must_not, new_should, new_filter)
94
116
  end
95
117
 
96
118
  private
97
119
 
98
- def prepare_clone(_clone, _musts, _shoulds, _filters)
120
+ def prepare_clone(_clone, _musts, _must_nots, _shoulds, _filters)
99
121
  _clone.musts = _musts
122
+ _clone.must_nots = _must_nots
100
123
  _clone.shoulds = _shoulds
101
124
  _clone.filters = _filters
102
125
  _clone.minimum_should_match = @minimum_should_match
@@ -1,3 +1,3 @@
1
1
  module Elastic
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastic-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ignacio Baixas