elasticated 2.4.0 → 2.5.0
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 +4 -4
- data/lib/elasticated.rb +20 -0
- data/lib/elasticated/aggregation.rb +4 -0
- data/lib/elasticated/aggregations/filter_aggregation.rb +4 -0
- data/lib/elasticated/boolean_clause.rb +8 -0
- data/lib/elasticated/conditions/custom_condition.rb +2 -2
- data/lib/elasticated/conditions/range_condition.rb +2 -5
- data/lib/elasticated/conditions/script_condition.rb +2 -2
- data/lib/elasticated/conditions/standard_condition.rb +2 -2
- data/lib/elasticated/conditions/terms_condition.rb +2 -2
- data/lib/elasticated/date_delimiter_factory.rb +123 -0
- data/lib/elasticated/delimiter_visitor.rb +51 -0
- data/lib/elasticated/delimiters/date_field_delimiter.rb +14 -19
- data/lib/elasticated/delimiters/standard_field_delimiter.rb +2 -18
- data/lib/elasticated/delimiters/term_field_delimiter.rb +5 -6
- data/lib/elasticated/index_selector.rb +10 -12
- data/lib/elasticated/partitioned_repository.rb +9 -4
- data/lib/elasticated/query.rb +4 -5
- data/lib/elasticated/query_aggregations.rb +5 -1
- data/lib/elasticated/query_conditions.rb +2 -4
- data/lib/elasticated/strategy_params_for_query_service.rb +14 -0
- data/lib/elasticated/term_delimiter_factory.rb +71 -0
- data/lib/version.rb +5 -1
- data/spec/date_field_delimiter_spec.rb +4 -43
- data/spec/delimiter_factory_spec.rb +366 -0
- data/spec/query_conditions_spec.rb +0 -59
- data/spec/strategy_params_for_query_service_spec.rb +328 -0
- data/spec/term_field_delimiter_spec.rb +8 -8
- metadata +28 -20
@@ -13,13 +13,18 @@ module Elasticated
|
|
13
13
|
client.refresh_indices affected_indices
|
14
14
|
end
|
15
15
|
|
16
|
+
# override
|
17
|
+
def execute_aggregations(query, opts={})
|
18
|
+
super(query, {delimit_by: [:conditions, :aggregations]}.merge(opts))
|
19
|
+
end
|
20
|
+
|
16
21
|
protected
|
17
22
|
|
18
23
|
# override
|
19
24
|
def execute(action, query, opts={})
|
20
|
-
affected_indices = affected_indices_for query
|
25
|
+
affected_indices = affected_indices_for query, opts
|
21
26
|
affected_indices = affected_indices*','
|
22
|
-
super action, query, opts.merge(index: affected_indices)
|
27
|
+
super action, query, opts.merge(index: affected_indices).reject { |k,_| k == :delimit_by }
|
23
28
|
end
|
24
29
|
|
25
30
|
# override
|
@@ -34,8 +39,8 @@ module Elasticated
|
|
34
39
|
super action, query, opts.merge(index: affected_index)
|
35
40
|
end
|
36
41
|
|
37
|
-
def affected_indices_for(query)
|
38
|
-
index_selector.indices_for_query(query)
|
42
|
+
def affected_indices_for(query, opts={})
|
43
|
+
index_selector.indices_for_query(query, opts)
|
39
44
|
end
|
40
45
|
|
41
46
|
end
|
data/lib/elasticated/query.rb
CHANGED
@@ -150,11 +150,10 @@ module Elasticated
|
|
150
150
|
_aggregations.parse response
|
151
151
|
end
|
152
152
|
|
153
|
-
#
|
154
|
-
|
155
|
-
def
|
156
|
-
|
157
|
-
_filter_conditions.fill_delimiter field_delimiter
|
153
|
+
# visitor methods
|
154
|
+
|
155
|
+
def accept_visitor(visitor)
|
156
|
+
visitor.visit_query(self)
|
158
157
|
end
|
159
158
|
|
160
159
|
# conditions & filter shorthands
|
@@ -27,12 +27,16 @@ module Elasticated
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def merge!
|
30
|
+
def merge!(other_query_aggs)
|
31
31
|
other_query_aggs._aggregations.each do |other_aggregation|
|
32
32
|
add_aggregation other_aggregation
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
def accept_visitor(visitor)
|
37
|
+
visitor.visit_query_aggregations(self)
|
38
|
+
end
|
39
|
+
|
36
40
|
private
|
37
41
|
|
38
42
|
def get_aggregation_class(agg_name)
|
@@ -11,10 +11,8 @@ module Elasticated
|
|
11
11
|
self._should = BooleanClause.new
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
def fill_delimiter(field_delimiter)
|
17
|
-
_must.fill_delimiter field_delimiter
|
14
|
+
def accept_visitor(visitor)
|
15
|
+
visitor.visit_query_conditions(self)
|
18
16
|
end
|
19
17
|
|
20
18
|
# conditions
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Elasticated
|
2
|
+
class StrategyParamsForQueryService
|
3
|
+
|
4
|
+
def strategy_params_for_query(empty_delimiters, query, opts={})
|
5
|
+
query_delimiters = query.accept_visitor(Elasticated.delimiter_visitor)
|
6
|
+
|
7
|
+
empty_delimiters.inject Hash.new do |params, empty_delimiter|
|
8
|
+
built_delimiter = empty_delimiter.completed_with(query_delimiters, opts)
|
9
|
+
params.merge built_delimiter.build_strategy_params
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Elasticated
|
2
|
+
class TermDelimiterFactory
|
3
|
+
|
4
|
+
def create(empty_delimiter, query_delimiters, opts={})
|
5
|
+
klass = Delimiters::TermFieldDelimiter
|
6
|
+
field = empty_delimiter.field_name
|
7
|
+
delimit_by = opts.fetch(:delimit_by, [:conditions])
|
8
|
+
|
9
|
+
case delimit_by
|
10
|
+
when []
|
11
|
+
relevant_delimiters = []
|
12
|
+
when [:conditions]
|
13
|
+
relevant_delimiters = relevant_field_delimiters(query_delimiters.fetch(:conditions), field)
|
14
|
+
when [:aggregations]
|
15
|
+
relevant_delimiters = relevant_field_delimiters(query_delimiters.fetch(:aggregations), field)
|
16
|
+
else
|
17
|
+
condition_delimiters = query_delimiters.fetch(:conditions)
|
18
|
+
aggregation_delimiters = query_delimiters.fetch(:aggregations)
|
19
|
+
relevant_delimiters = [merge_delimiters(condition_delimiters, aggregation_delimiters,field)]
|
20
|
+
end
|
21
|
+
|
22
|
+
values = empty_delimiter.values + relevant_delimiters.flat_map(&:values).flatten(1)
|
23
|
+
klass.new(values: values, field: field, as: empty_delimiter.filter_name)
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def relevant_field_delimiters(all_delimiters, field)
|
28
|
+
all_delimiters.each_with_object(Array.new) do |delimiter, array|
|
29
|
+
field_delimiter = delimiter.select { |k,_| k == field }
|
30
|
+
array << field_delimiter unless field_delimiter.empty?
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def merge_delimiters(condition_delimiters, aggregation_delimiters, field)
|
35
|
+
aggregation_delimiters_by_field = extract_aggregation_delimiters(aggregation_delimiters, field)
|
36
|
+
condition_delimiters_by_field = extract_condition_delimiters(condition_delimiters,field)
|
37
|
+
aggregation_delimiters_by_field.merge condition_delimiters_by_field
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def extract_aggregation_delimiters(delimiters, field)
|
43
|
+
delimiters.inject(delimiters.first) do |mcd_acum, delimiter|
|
44
|
+
merge_aggregation_repeated_keys(mcd_acum, delimiter, field)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def extract_condition_delimiters(delimiters, field)
|
49
|
+
delimiters.inject(delimiters.first) do |mcd_acum, delimiter|
|
50
|
+
merge_condition_repeated_keys(mcd_acum, delimiter, field)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def merge_aggregation_repeated_keys(this, another_hash, field)
|
55
|
+
this_field = this[field]
|
56
|
+
another_hash_field = another_hash[field]
|
57
|
+
return {} if this_field.nil? or another_hash_field.nil?
|
58
|
+
{field => (this_field + another_hash_field).uniq}
|
59
|
+
end
|
60
|
+
|
61
|
+
def merge_condition_repeated_keys(this, another_hash, field)
|
62
|
+
this_field = this[field]
|
63
|
+
another_hash_field = another_hash[field]
|
64
|
+
return this if another_hash_field.nil? and not this_field.nil?
|
65
|
+
return (another_hash.select { |(k,v)| k == field }) if this_field.nil? and not another_hash_field.nil?
|
66
|
+
return {} if another_hash_field.nil? and this_field.nil?
|
67
|
+
{field => (this_field + another_hash_field).uniq}
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
data/lib/version.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
module Elasticated
|
2
|
-
VERSION = '2.
|
2
|
+
VERSION = '2.5.0'
|
3
3
|
end
|
4
4
|
|
5
5
|
# Changelog
|
6
6
|
|
7
|
+
# 2.5.0
|
8
|
+
# Ahora los delimiters son inmutables
|
9
|
+
# Se puede delimitar por aggregations
|
10
|
+
|
7
11
|
# 2.4.0
|
8
12
|
# Ahora se puede ordenar un search por un campo, script o hash custom
|
9
13
|
|
@@ -14,56 +14,17 @@ module Elasticated
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should delimit by one term" do
|
17
|
-
delimiter.
|
18
|
-
params =
|
17
|
+
completed_delimiter = delimiter.completed_with conditions: [{created_at: '2016-07-19'}]
|
18
|
+
params = completed_delimiter.build_strategy_params
|
19
19
|
expect(params).to eq date: '2016-07-19'
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should delimit by multiple terms" do
|
23
|
-
delimiter.
|
24
|
-
|
25
|
-
delimiter.add_term :created_at, '2017-03-27'
|
26
|
-
params = delimiter.build_strategy_params
|
23
|
+
completed_delimiter = delimiter.completed_with conditions: [{created_at: '2017-03-30'},{created_at: '2017-03-25'},{created_at: '2017-03-27'}]
|
24
|
+
params = completed_delimiter.build_strategy_params
|
27
25
|
expect(params).to eq date_since: '2017-03-25', date_until: '2017-03-30'
|
28
26
|
end
|
29
27
|
|
30
|
-
it "should delimit by a min date" do
|
31
|
-
delimiter.set_minimum :created_at, '2016-07-19'
|
32
|
-
params = delimiter.build_strategy_params
|
33
|
-
expect(params).to eq date_since: '2016-07-19'
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should delimit by a max date" do
|
37
|
-
delimiter.set_maximum :created_at, '2016-07-19'
|
38
|
-
params = delimiter.build_strategy_params
|
39
|
-
expect(params).to eq date_until: '2016-07-19'
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should delimit by a range of dates" do
|
43
|
-
delimiter.set_minimum :created_at, '2016-07-19'
|
44
|
-
delimiter.set_maximum :created_at, '2016-07-21'
|
45
|
-
params = delimiter.build_strategy_params
|
46
|
-
expect(params).to eq date_since: '2016-07-19', date_until: '2016-07-21'
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should delimit by the most restricted range of dates" do
|
50
|
-
delimiter.set_minimum :created_at, '2016-07-19'
|
51
|
-
delimiter.set_maximum :created_at, '2016-07-25'
|
52
|
-
delimiter.set_minimum :created_at, '2016-07-17' # ignored minimum
|
53
|
-
delimiter.set_maximum :created_at, '2016-07-24'
|
54
|
-
delimiter.set_maximum :created_at, '2016-07-26' # ignored maximum
|
55
|
-
params = delimiter.build_strategy_params
|
56
|
-
expect(params).to eq date_since: '2016-07-19', date_until: '2016-07-24'
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should prefer a term over a range of dates" do
|
60
|
-
delimiter.set_minimum :created_at, '2016-07-19'
|
61
|
-
delimiter.set_maximum :created_at, '2016-07-21'
|
62
|
-
delimiter.add_term :created_at, '2016-07-20'
|
63
|
-
params = delimiter.build_strategy_params
|
64
|
-
expect(params).to eq date: '2016-07-20'
|
65
|
-
end
|
66
|
-
|
67
28
|
end
|
68
29
|
end
|
69
30
|
end
|
@@ -0,0 +1,366 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
module Elasticated
|
4
|
+
describe TermDelimiterFactory do
|
5
|
+
let(:empty_delimiter){ Elasticated::Delimiters::TermFieldDelimiter.new(field: :account, as: :accounts) }
|
6
|
+
|
7
|
+
it "should create empty term delimiter from empty conditions" do
|
8
|
+
query_delimiters = { conditions: [], aggregations: []}
|
9
|
+
expected = Elasticated::Delimiters::TermFieldDelimiter.new(field: :account, as: :accounts, values: [])
|
10
|
+
actual = Elasticated.term_delimiter_factory.create(empty_delimiter, query_delimiters)
|
11
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should create empty term delimiter from empty condition delimiter definition and none aggregation delimiters' do
|
15
|
+
query_delimiters = { conditions: [{}], aggregations: [] }
|
16
|
+
expected = Elasticated::Delimiters::TermFieldDelimiter.new(field: :account, as: :accounts, values: [])
|
17
|
+
actual = Elasticated.term_delimiter_factory.create(empty_delimiter, query_delimiters)
|
18
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
19
|
+
|
20
|
+
query_delimiters = { conditions: [{}, {}], aggregations: [] }
|
21
|
+
actual = Elasticated.term_delimiter_factory.create(empty_delimiter, query_delimiters)
|
22
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should create term delimiter with account from condition delimiter' do
|
26
|
+
query_delimiters = { conditions: [{account: [39]}], aggregations: [] }
|
27
|
+
expected = Elasticated::Delimiters::TermFieldDelimiter.new(field: :account, as: :accounts, values: [39])
|
28
|
+
actual = Elasticated.term_delimiter_factory.create(empty_delimiter, query_delimiters)
|
29
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should create term delimiter with account from condition delimiter with other empty definitions' do
|
33
|
+
query_delimiters = { conditions: [{account: [39]}, {}, {}], aggregations: [] }
|
34
|
+
expected = Elasticated::Delimiters::TermFieldDelimiter.new(field: :account, as: :accounts, values: [39])
|
35
|
+
actual = Elasticated.term_delimiter_factory.create(empty_delimiter, query_delimiters)
|
36
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
37
|
+
|
38
|
+
query_delimiters = { conditions: [{account: [39,40]}, {}, {}], aggregations: [] }
|
39
|
+
expected = Elasticated::Delimiters::TermFieldDelimiter.new(field: :account, as: :accounts, values: [39,40])
|
40
|
+
actual = Elasticated.term_delimiter_factory.create(empty_delimiter, query_delimiters)
|
41
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should create term delimiter with two accounts from different condition delimiters' do
|
45
|
+
query_delimiters = { conditions: [{account: [39]}, {account: 40}, {}], aggregations: [] }
|
46
|
+
expected = Elasticated::Delimiters::TermFieldDelimiter.new(field: :account, as: :accounts, values: [39, 40])
|
47
|
+
actual = Elasticated.term_delimiter_factory.create(empty_delimiter, query_delimiters)
|
48
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should create term delimiter with two accounts from different condition delimiters with one different field in one delimiter' do
|
52
|
+
query_delimiters = { conditions: [{account: [39], tags: ["a_tag"]}, {account: 40}, {}], aggregations: [] }
|
53
|
+
expected = Elasticated::Delimiters::TermFieldDelimiter.new(field: :account, as: :accounts, values: [39, 40])
|
54
|
+
actual = Elasticated.term_delimiter_factory.create(empty_delimiter, query_delimiters)
|
55
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
56
|
+
|
57
|
+
query_delimiters = { conditions: [{account: [39], tags: ["a_tag"]}, {account: 40, tags: ["another_tag"]}, {}], aggregations: [] }
|
58
|
+
actual = Elasticated.term_delimiter_factory.create(empty_delimiter, query_delimiters)
|
59
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should create term delimiter with account from aggregation delimiter with no condition delimiters' do
|
63
|
+
options = {delimit_by: [:aggregations]}
|
64
|
+
query_delimiters = { conditions: [{}], aggregations: [{account: [39]}] }
|
65
|
+
expected = Elasticated::Delimiters::TermFieldDelimiter.new(field: :account, as: :accounts, values: [39])
|
66
|
+
actual = Elasticated.term_delimiter_factory.create(empty_delimiter, query_delimiters, options)
|
67
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
68
|
+
|
69
|
+
query_delimiters = { conditions: [{}], aggregations: [{account: [39]}, {account: [40]}] }
|
70
|
+
expected = Elasticated::Delimiters::TermFieldDelimiter.new(field: :account, as: :accounts, values: [39, 40])
|
71
|
+
actual = Elasticated.term_delimiter_factory.create(empty_delimiter, query_delimiters, options)
|
72
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should merge empty delimiters' do
|
76
|
+
condition_delimiters = [{}]
|
77
|
+
aggregation_delimiters = [{}]
|
78
|
+
field = :account
|
79
|
+
expected = {}
|
80
|
+
actual = Elasticated.term_delimiter_factory.merge_delimiters(condition_delimiters, aggregation_delimiters, field)
|
81
|
+
expect(actual).to eq(expected)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should merge empty condition delimiter with one aggregation delimiter' do
|
85
|
+
condition_delimiters = [{}]
|
86
|
+
aggregation_delimiters = [{account: [39]}]
|
87
|
+
field = :account
|
88
|
+
expected = {account: [39]}
|
89
|
+
actual = Elasticated.term_delimiter_factory.merge_delimiters(condition_delimiters, aggregation_delimiters, field)
|
90
|
+
expect(actual).to eq(expected)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should merge empty condition delimiter with two aggregation delimiters' do
|
94
|
+
condition_delimiters = [{}]
|
95
|
+
aggregation_delimiters = [{account: [39]}, {account: [40]}]
|
96
|
+
field = :account
|
97
|
+
expected = {account: [39, 40]}
|
98
|
+
actual = Elasticated.term_delimiter_factory.merge_delimiters(condition_delimiters, aggregation_delimiters, field)
|
99
|
+
expect(actual).to eq(expected)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should merge empty condition delimiter with two different aggregation delimiters' do
|
103
|
+
condition_delimiters = [{}]
|
104
|
+
aggregation_delimiters = [{account: [39]}, {tags: ["a_tag"]}]
|
105
|
+
field = :account
|
106
|
+
expected = {}
|
107
|
+
actual = Elasticated.term_delimiter_factory.merge_delimiters(condition_delimiters, aggregation_delimiters, field)
|
108
|
+
expect(actual).to eq(expected)
|
109
|
+
|
110
|
+
aggregation_delimiters = [{tags: ["a_tag"]}, {account: [39]}]
|
111
|
+
actual = Elasticated.term_delimiter_factory.merge_delimiters(condition_delimiters, aggregation_delimiters, field)
|
112
|
+
expect(actual).to eq(expected)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should merge empty condition delimiter with two equal aggregation delimiters and one different' do
|
116
|
+
condition_delimiters = [{}]
|
117
|
+
aggregation_delimiters = [{account: [39]}, {account: [40], tags: ["a_tag"]}]
|
118
|
+
field = :account
|
119
|
+
expected = {account: [39, 40]}
|
120
|
+
actual = Elasticated.term_delimiter_factory.merge_delimiters(condition_delimiters, aggregation_delimiters, field)
|
121
|
+
expect(actual).to eq(expected)
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'should merge one condition delimiter with empty aggregation delimiters' do
|
125
|
+
condition_delimiters = [{account: [39]}]
|
126
|
+
aggregation_delimiters = [{}]
|
127
|
+
field = :account
|
128
|
+
expected = {account: [39]}
|
129
|
+
actual = Elasticated.term_delimiter_factory.merge_delimiters(condition_delimiters, aggregation_delimiters, field)
|
130
|
+
expect(actual).to eq(expected)
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'should merge two condition delimiter with empty aggregation delimiters' do
|
134
|
+
condition_delimiters = [{account: [39]}, {account: [40]}]
|
135
|
+
aggregation_delimiters = [{}]
|
136
|
+
field = :account
|
137
|
+
expected = {account: [39, 40]}
|
138
|
+
actual = Elasticated.term_delimiter_factory.merge_delimiters(condition_delimiters, aggregation_delimiters, field)
|
139
|
+
expect(actual).to eq(expected)
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should merge two different condition delimiters with empty aggregation delimiters' do
|
143
|
+
condition_delimiters = [{account: [39]}, {tags: ["a_tag"]}]
|
144
|
+
aggregation_delimiters = [{}]
|
145
|
+
field = :account
|
146
|
+
expected = {account: [39]}
|
147
|
+
actual = Elasticated.term_delimiter_factory.merge_delimiters(condition_delimiters, aggregation_delimiters, field)
|
148
|
+
expect(actual).to eq(expected)
|
149
|
+
|
150
|
+
condition_delimiters = [{tags: ["a_tag"]}, {account: [39]}]
|
151
|
+
actual = Elasticated.term_delimiter_factory.merge_delimiters(condition_delimiters, aggregation_delimiters, field)
|
152
|
+
expect(actual).to eq(expected)
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'should merge two equal and one different condition delimiters with empty delimiters' do
|
156
|
+
condition_delimiters = [{account: [39]}, {account: [40], tags: ["a_tag"]}]
|
157
|
+
aggregation_delimiters = [{}]
|
158
|
+
field = :account
|
159
|
+
expected = {account: [39, 40]}
|
160
|
+
actual = Elasticated.term_delimiter_factory.merge_delimiters(condition_delimiters, aggregation_delimiters, field)
|
161
|
+
expect(actual).to eq(expected)
|
162
|
+
|
163
|
+
condition_delimiters = [{tags: ["a_tag"], account: [40]}, {account: [39]}]
|
164
|
+
expected = {account: [40, 39]}
|
165
|
+
actual = Elasticated.term_delimiter_factory.merge_delimiters(condition_delimiters, aggregation_delimiters, field)
|
166
|
+
expect(actual).to eq(expected)
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'should merge one condition delimiter with one aggregation delimiter of a different field' do
|
170
|
+
condition_delimiters = [{account: [39]}]
|
171
|
+
aggregation_delimiters = [{tags: ["a_tag"]}]
|
172
|
+
field = :account
|
173
|
+
expected = {account: [39]}
|
174
|
+
actual = Elasticated.term_delimiter_factory.merge_delimiters(condition_delimiters, aggregation_delimiters, field)
|
175
|
+
expect(actual).to eq(expected)
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'should merge one condition delimiter with one aggregation delimiter of the same field' do
|
179
|
+
condition_delimiters = [{account: [39]}]
|
180
|
+
aggregation_delimiters = [{account: [40]}]
|
181
|
+
field = :account
|
182
|
+
expected = {account: [39]}
|
183
|
+
actual = Elasticated.term_delimiter_factory.merge_delimiters(condition_delimiters, aggregation_delimiters, field)
|
184
|
+
expect(actual).to eq(expected)
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'should merge two condition delimiter of different field with one aggregation delimiter of another field' do
|
188
|
+
condition_delimiters = [{account: [39]}, {groups: ["a_group"]}]
|
189
|
+
aggregation_delimiters = [{tags: ["a_tag"]}]
|
190
|
+
field = :account
|
191
|
+
expected = {account: [39]}
|
192
|
+
actual = Elasticated.term_delimiter_factory.merge_delimiters(condition_delimiters, aggregation_delimiters, field)
|
193
|
+
expect(actual).to eq(expected)
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
|
198
|
+
describe DateDelimiterFactory do
|
199
|
+
let(:empty_delimiter){ Elasticated::Delimiters::DateFieldDelimiter.new(field: :date) }
|
200
|
+
let(:term_empty_delimiter){ Elasticated::Delimiters::TermFieldDelimiter.new(field: :date) }
|
201
|
+
|
202
|
+
it "should create empty date delimiter from empty conditions" do
|
203
|
+
query_delimiters = { conditions: [], aggregations: []}
|
204
|
+
expected = Elasticated::Delimiters::TermFieldDelimiter.new(field: :date)
|
205
|
+
actual = Elasticated.term_delimiter_factory.create(term_empty_delimiter, query_delimiters)
|
206
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'should create empty date delimiter from empty condition delimiter definition and none aggregation delimiters' do
|
210
|
+
query_delimiters = { conditions: [{}], aggregations: [] }
|
211
|
+
expected = Elasticated::Delimiters::TermFieldDelimiter.new(field: :date)
|
212
|
+
actual = Elasticated.term_delimiter_factory.create(term_empty_delimiter, query_delimiters)
|
213
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
214
|
+
|
215
|
+
query_delimiters = { conditions: [{}, {}], aggregations: [] }
|
216
|
+
actual = Elasticated.term_delimiter_factory.create(term_empty_delimiter, query_delimiters)
|
217
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'should create date delimiter from condition delimiter' do
|
221
|
+
query_delimiters = { conditions: [{date: ['2017-05-26']}], aggregations: [] }
|
222
|
+
expected = Elasticated::Delimiters::TermFieldDelimiter.new(field: :date, values: ['2017-05-26'])
|
223
|
+
actual = Elasticated.term_delimiter_factory.create(term_empty_delimiter, query_delimiters)
|
224
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
225
|
+
|
226
|
+
query_delimiters = { conditions: [{date_since: '2017-05-26'}], aggregations: [] }
|
227
|
+
expected = Elasticated::Delimiters::DateFieldDelimiter.new(field: :date, date_since: '2017-05-26')
|
228
|
+
actual = Elasticated.date_delimiter_factory.create(empty_delimiter, query_delimiters)
|
229
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
230
|
+
|
231
|
+
query_delimiters = { conditions: [{date_until: '2017-05-26'}], aggregations: [] }
|
232
|
+
expected = Elasticated::Delimiters::DateFieldDelimiter.new(field: :date, date_until: '2017-05-26')
|
233
|
+
actual = Elasticated.date_delimiter_factory.create(empty_delimiter, query_delimiters)
|
234
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
235
|
+
|
236
|
+
query_delimiters = { conditions: [{date_since: '2017-05-26', date_until: '2017-05-26'}], aggregations: [] }
|
237
|
+
expected = Elasticated::Delimiters::DateFieldDelimiter.new(field: :date, date_since: '2017-05-26', date_until: '2017-05-26')
|
238
|
+
actual = Elasticated.date_delimiter_factory.create(empty_delimiter, query_delimiters)
|
239
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'should create date delimiter from many condition delimiters' do
|
243
|
+
query_delimiters = { conditions: [{date: ['2017-05-26']}, {date: ['2017-05-27']}, {date: ['2017-05-25']}], aggregations: [] }
|
244
|
+
expected = Elasticated::Delimiters::TermFieldDelimiter.new(field: :date, values: ['2017-05-26', '2017-05-27', '2017-05-25'])
|
245
|
+
actual = Elasticated.term_delimiter_factory.create(term_empty_delimiter, query_delimiters)
|
246
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
247
|
+
|
248
|
+
query_delimiters = { conditions: [{date_since: '2017-05-26'}, {date_since: '2017-05-25'}, {date_since: '2017-05-27'}], aggregations: [] }
|
249
|
+
expected = Elasticated::Delimiters::DateFieldDelimiter.new(field: :date, date_since: '2017-05-25')
|
250
|
+
actual = Elasticated.date_delimiter_factory.create(empty_delimiter, query_delimiters)
|
251
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
252
|
+
|
253
|
+
query_delimiters = { conditions: [{date_until: '2017-05-26'}, {date_until: '2017-05-25'}, {date_until: '2017-05-27'}], aggregations: [] }
|
254
|
+
expected = Elasticated::Delimiters::DateFieldDelimiter.new(field: :date, date_until: '2017-05-27')
|
255
|
+
actual = Elasticated.date_delimiter_factory.create(empty_delimiter, query_delimiters)
|
256
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
257
|
+
|
258
|
+
query_delimiters = { conditions: [{date_since: '2017-05-25', date_until: '2017-05-26'}, {date_since: '2017-05-27', date_until: '2017-05-28'}], aggregations: [] }
|
259
|
+
expected = Elasticated::Delimiters::DateFieldDelimiter.new(field: :date, date_since: '2017-05-25', date_until: '2017-05-28')
|
260
|
+
actual = Elasticated.date_delimiter_factory.create(empty_delimiter, query_delimiters)
|
261
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
262
|
+
end
|
263
|
+
|
264
|
+
it 'should create date delimiter from aggregation delimiters' do
|
265
|
+
options = {delimit_by: [:aggregations]}
|
266
|
+
query_delimiters = { conditions: [{}], aggregations: [{date_since: '2017-05-26'}] }
|
267
|
+
expected = Elasticated::Delimiters::DateFieldDelimiter.new(field: :date, date_since: '2017-05-26')
|
268
|
+
actual = Elasticated.date_delimiter_factory.create(empty_delimiter, query_delimiters, options)
|
269
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
270
|
+
|
271
|
+
query_delimiters = { conditions: [], aggregations: [{date_since: '2017-05-26'}] }
|
272
|
+
expected = Elasticated::Delimiters::DateFieldDelimiter.new(field: :date, date_since: '2017-05-26')
|
273
|
+
actual = Elasticated.date_delimiter_factory.create(empty_delimiter, query_delimiters, options)
|
274
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
275
|
+
|
276
|
+
query_delimiters = { conditions: [], aggregations: [{date_until: '2017-05-26'}] }
|
277
|
+
expected = Elasticated::Delimiters::DateFieldDelimiter.new(field: :date, date_until: '2017-05-26')
|
278
|
+
actual = Elasticated.date_delimiter_factory.create(empty_delimiter, query_delimiters, options)
|
279
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
280
|
+
|
281
|
+
query_delimiters = { conditions: [], aggregations: [{date_since: '2017-05-26', date_until: '2017-05-26'}] }
|
282
|
+
expected = Elasticated::Delimiters::DateFieldDelimiter.new(field: :date, date_since: '2017-05-26', date_until: '2017-05-26')
|
283
|
+
actual = Elasticated.date_delimiter_factory.create(empty_delimiter, query_delimiters, options)
|
284
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
285
|
+
end
|
286
|
+
|
287
|
+
it 'should create date delimiter from many aggregation delimiters' do
|
288
|
+
options = {delimit_by: [:aggregations]}
|
289
|
+
query_delimiters = { conditions: [], aggregations: [{date: ['2017-05-26']}, {date: ['2017-05-27']}, {date: ['2017-05-25']}] }
|
290
|
+
expected = Elasticated::Delimiters::TermFieldDelimiter.new(field: :date, values: ['2017-05-26', '2017-05-27', '2017-05-25'])
|
291
|
+
actual = Elasticated.term_delimiter_factory.create(term_empty_delimiter, query_delimiters, options)
|
292
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
293
|
+
|
294
|
+
query_delimiters = { conditions: [], aggregations: [{date_since: '2017-05-26'}, {date_since: '2017-05-25'}, {date_since: '2017-05-27'}] }
|
295
|
+
expected = Elasticated::Delimiters::DateFieldDelimiter.new(field: :date, date_since: '2017-05-25')
|
296
|
+
actual = Elasticated.date_delimiter_factory.create(empty_delimiter, query_delimiters, options)
|
297
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
298
|
+
|
299
|
+
query_delimiters = { conditions: [], aggregations: [{date_until: '2017-05-26'}, {date_until: '2017-05-25'}, {date_until: '2017-05-27'}] }
|
300
|
+
expected = Elasticated::Delimiters::DateFieldDelimiter.new(field: :date, date_until: '2017-05-27')
|
301
|
+
actual = Elasticated.date_delimiter_factory.create(empty_delimiter, query_delimiters, options)
|
302
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
303
|
+
|
304
|
+
query_delimiters = { conditions: [], aggregations: [{date_since: '2017-05-25', date_until: '2017-05-26'}, {date_since: '2017-05-27', date_until: '2017-05-28'}] }
|
305
|
+
expected = Elasticated::Delimiters::DateFieldDelimiter.new(field: :date, date_since: '2017-05-25', date_until: '2017-05-28')
|
306
|
+
actual = Elasticated.date_delimiter_factory.create(empty_delimiter, query_delimiters, options)
|
307
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
308
|
+
|
309
|
+
query_delimiters = { conditions: [], aggregations: [{date_since: '2017-05-25'}, {date_until: '2017-05-28'}] }
|
310
|
+
expected = Elasticated::Delimiters::DateFieldDelimiter.new(field: :date)
|
311
|
+
actual = Elasticated.date_delimiter_factory.create(empty_delimiter, query_delimiters, options)
|
312
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
313
|
+
end
|
314
|
+
|
315
|
+
it 'should create date delimiter from condition and aggregation delimiters' do
|
316
|
+
options = {delimit_by: [:conditions, :aggregations]}
|
317
|
+
query_delimiters = { conditions: [{date: ['2017-05-26']}, {date: ['2017-05-27']}], aggregations: [{date: ['2017-05-25']}] }
|
318
|
+
expected = Elasticated::Delimiters::TermFieldDelimiter.new(field: :date, values: ['2017-05-26', '2017-05-27'])
|
319
|
+
actual = Elasticated.term_delimiter_factory.create(term_empty_delimiter, query_delimiters, options)
|
320
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
321
|
+
|
322
|
+
query_delimiters = { conditions: [{date_since: '2017-05-26'}], aggregations: [{date_since: '2017-05-25'}, {date_since: '2017-05-27'}] }
|
323
|
+
expected = Elasticated::Delimiters::DateFieldDelimiter.new(field: :date, date_since: '2017-05-26')
|
324
|
+
actual = Elasticated.date_delimiter_factory.create(empty_delimiter, query_delimiters, options)
|
325
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
326
|
+
|
327
|
+
query_delimiters = { conditions: [{date_until: '2017-05-26'}, {date_until: '2017-05-25'}], aggregations: [{date_until: '2017-05-27'}] }
|
328
|
+
expected = Elasticated::Delimiters::DateFieldDelimiter.new(field: :date, date_until: '2017-05-26')
|
329
|
+
actual = Elasticated.date_delimiter_factory.create(empty_delimiter, query_delimiters, options)
|
330
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
331
|
+
|
332
|
+
query_delimiters = { conditions: [{date_since: '2017-05-25', date_until: '2017-05-26'}], aggregations: [{date_since: '2017-05-27', date_until: '2017-05-28'}] }
|
333
|
+
expected = Elasticated::Delimiters::DateFieldDelimiter.new(field: :date, date_since: '2017-05-25', date_until: '2017-05-26')
|
334
|
+
actual = Elasticated.date_delimiter_factory.create(empty_delimiter, query_delimiters, options)
|
335
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
336
|
+
|
337
|
+
query_delimiters = { conditions: [{date_until: '2017-05-28'}], aggregations: [{date_since: '2017-05-25'}] }
|
338
|
+
expected = Elasticated::Delimiters::DateFieldDelimiter.new(field: :date, date_since: '2017-05-25', date_until: '2017-05-28')
|
339
|
+
actual = Elasticated.date_delimiter_factory.create(empty_delimiter, query_delimiters, options)
|
340
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
341
|
+
|
342
|
+
query_delimiters = { conditions: [], aggregations: [{date_since: '2017-05-27', date_until: '2017-05-28'}] }
|
343
|
+
expected = Elasticated::Delimiters::DateFieldDelimiter.new(field: :date, date_since: '2017-05-27', date_until: '2017-05-28')
|
344
|
+
actual = Elasticated.date_delimiter_factory.create(empty_delimiter, query_delimiters, options)
|
345
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
346
|
+
|
347
|
+
query_delimiters = { conditions: [{date_since: '2017-05-26'}], aggregations: [{date_since: '2017-05-27', date_until: '2017-05-28'}] }
|
348
|
+
expected = Elasticated::Delimiters::DateFieldDelimiter.new(field: :date, date_since: '2017-05-26', date_until: '2017-05-28')
|
349
|
+
actual = Elasticated.date_delimiter_factory.create(empty_delimiter, query_delimiters, options)
|
350
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
351
|
+
|
352
|
+
query_delimiters = { conditions: [{date_since: '2017-05-26'}], aggregations: [{date_since: '2017-05-27', date_until: '2017-05-28'}, {date_since: '2017-05-27'}] }
|
353
|
+
expected = Elasticated::Delimiters::DateFieldDelimiter.new(field: :date, date_since: '2017-05-26')
|
354
|
+
actual = Elasticated.date_delimiter_factory.create(empty_delimiter, query_delimiters, options)
|
355
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
356
|
+
end
|
357
|
+
|
358
|
+
it 'should create date delimiter from condition and aggregation delimiters when condition delimiter has many different filters' do
|
359
|
+
options = {delimit_by: [:conditions, :aggregations]}
|
360
|
+
query_delimiters = { conditions: [{date_since: '2017-05-26'}, {date_until: '2017-05-31'}], aggregations: [{date_since: '2017-05-27', date_until: '2017-05-28'}, {date_since: '2017-05-27'}] }
|
361
|
+
expected = Elasticated::Delimiters::DateFieldDelimiter.new(field: :date, date_since: '2017-05-26', date_until: '2017-05-31')
|
362
|
+
actual = Elasticated.date_delimiter_factory.create(empty_delimiter, query_delimiters, options)
|
363
|
+
expect(actual.build_strategy_params).to eq(expected.build_strategy_params)
|
364
|
+
end
|
365
|
+
end
|
366
|
+
end
|