elastic-rails 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/elastic/dsl/bool_query_builder.rb +6 -0
- data/lib/elastic/nodes/boolean.rb +29 -6
- data/lib/elastic/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b7327309b8afdf84080efb767efa3ba254db36e
|
4
|
+
data.tar.gz: 74a5e89ab5f4b8dff0e547cd6eca69a7534bca72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
89
|
-
|
90
|
-
return
|
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
|
data/lib/elastic/version.rb
CHANGED