arelastic 2.1.1 → 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/arelastic/aggregations/bucket.rb +1 -1
- data/lib/arelastic/nodes/node.rb +4 -0
- data/lib/arelastic/queries.rb +2 -0
- data/lib/arelastic/queries/bool.rb +8 -7
- data/lib/arelastic/queries/dis_max.rb +1 -1
- data/lib/arelastic/queries/filter.rb +10 -2
- data/lib/arelastic/queries/function_score.rb +21 -0
- data/test/arelastic/queries/bool_test.rb +6 -4
- data/test/arelastic/queries/dis_max_test.rb +3 -3
- data/test/arelastic/queries/filter_test.rb +14 -16
- data/test/arelastic/queries/function_score_test.rb +33 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7e7cece5f867bbfe2dedcc985f0f6fec1a930fa
|
4
|
+
data.tar.gz: 76161f732806f810c4b8b48a197331fec647fb1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08fef26bfa8760dfff29d33e42926ffa23ea1d3ef978a64668c19047f2482eda7e6ff51f4095e694ade704db5f5f64740e97b07dd227180b1688fd86adceeea7'
|
7
|
+
data.tar.gz: 99c5b03d1ca49a7e1c7b262fd95cc002b61e1e9ae583f32270dcb8bd4da65f9646e6bca6d8134e1dca692250c703f4e69ff2313e4674ab333994b3229c24fd00
|
data/lib/arelastic/nodes/node.rb
CHANGED
data/lib/arelastic/queries.rb
CHANGED
@@ -5,6 +5,8 @@ require 'arelastic/queries/constant_score'
|
|
5
5
|
require 'arelastic/queries/dis_max'
|
6
6
|
require 'arelastic/queries/exists'
|
7
7
|
require 'arelastic/queries/field'
|
8
|
+
require 'arelastic/queries/filter'
|
9
|
+
require 'arelastic/queries/function_score'
|
8
10
|
require 'arelastic/queries/geo_bounding_box'
|
9
11
|
require 'arelastic/queries/geo_distance'
|
10
12
|
require 'arelastic/queries/has_child'
|
@@ -1,12 +1,13 @@
|
|
1
1
|
module Arelastic
|
2
2
|
module Queries
|
3
3
|
class Bool < Arelastic::Queries::Query
|
4
|
-
attr_accessor :must, :filter, :should, :must_not
|
5
|
-
def initialize(
|
6
|
-
@must = must
|
7
|
-
@filter = filter
|
8
|
-
@should = should
|
9
|
-
@must_not = must_not
|
4
|
+
attr_accessor :must, :filter, :should, :must_not, :options
|
5
|
+
def initialize(options)
|
6
|
+
@must = read_option! options, 'must'
|
7
|
+
@filter = read_option! options, 'filter'
|
8
|
+
@should = read_option! options, 'should'
|
9
|
+
@must_not = read_option! options, 'must_not'
|
10
|
+
@options = options
|
10
11
|
end
|
11
12
|
|
12
13
|
def as_elastic
|
@@ -21,7 +22,7 @@ module Arelastic
|
|
21
22
|
searches[k] = convert_to_elastic(v) if v
|
22
23
|
end
|
23
24
|
|
24
|
-
{'bool' => searches}
|
25
|
+
{ 'bool' => searches.update(options) }
|
25
26
|
end
|
26
27
|
end
|
27
28
|
end
|
@@ -1,8 +1,16 @@
|
|
1
1
|
module Arelastic
|
2
2
|
module Queries
|
3
3
|
class Filter < Arelastic::Queries::Query
|
4
|
-
|
5
|
-
|
4
|
+
attr_accessor :query, :options
|
5
|
+
def initialize(query, options = {})
|
6
|
+
@query = query
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def as_elastic
|
11
|
+
{
|
12
|
+
'filter' => convert_to_elastic(query)
|
13
|
+
}.update(options)
|
6
14
|
end
|
7
15
|
end
|
8
16
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Queries
|
3
|
+
class FunctionScore < Arelastic::Queries::Query
|
4
|
+
attr_accessor :query, :functions, :options
|
5
|
+
def initialize(options)
|
6
|
+
@query = read_option! options, 'query'
|
7
|
+
@functions = read_option! options, 'functions'
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def as_elastic
|
12
|
+
{
|
13
|
+
'function_score' => {
|
14
|
+
'query' => convert_to_elastic(query),
|
15
|
+
'functions' => convert_to_elastic(functions)
|
16
|
+
}.update(options)
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -17,7 +17,7 @@ class Arelastic::Queries::BoolTest < Minitest::Test
|
|
17
17
|
#
|
18
18
|
# assert_equal expected, filtered.as_elastic
|
19
19
|
# end
|
20
|
-
|
20
|
+
|
21
21
|
def test_as_elastic
|
22
22
|
bool = Arelastic::Queries::Bool.new(
|
23
23
|
must: {
|
@@ -28,7 +28,8 @@ class Arelastic::Queries::BoolTest < Minitest::Test
|
|
28
28
|
must_not: Arelastic::Queries::Match.new('color', 'green'),
|
29
29
|
should: [
|
30
30
|
Arelastic::Queries::Match.new('height', 6)
|
31
|
-
]
|
31
|
+
],
|
32
|
+
'boost' => 1.0
|
32
33
|
)
|
33
34
|
|
34
35
|
expected = {
|
@@ -47,10 +48,11 @@ class Arelastic::Queries::BoolTest < Minitest::Test
|
|
47
48
|
'match' => {
|
48
49
|
'height' => 6
|
49
50
|
}
|
50
|
-
]
|
51
|
+
],
|
52
|
+
'boost' => 1.0
|
51
53
|
}
|
52
54
|
}
|
53
55
|
|
54
56
|
assert_equal expected, bool.as_elastic
|
55
57
|
end
|
56
|
-
end
|
58
|
+
end
|
@@ -2,7 +2,7 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class Arelastic::Queries::DisMaxTest < Minitest::Test
|
4
4
|
def test_as_elastic
|
5
|
-
|
5
|
+
dis_max = Arelastic::Queries::DisMax.new(
|
6
6
|
queries: [
|
7
7
|
{'term' => {'user' => 'kimchy'}},
|
8
8
|
Arelastic::Queries::Match.new('color', 'green')
|
@@ -18,6 +18,6 @@ class Arelastic::Queries::DisMaxTest < Minitest::Test
|
|
18
18
|
}
|
19
19
|
}
|
20
20
|
|
21
|
-
assert_equal expected,
|
21
|
+
assert_equal expected, dis_max.as_elastic
|
22
22
|
end
|
23
|
-
end
|
23
|
+
end
|
@@ -1,22 +1,20 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class Arelastic::Queries::FilterTest < Minitest::Test
|
4
|
-
def
|
5
|
-
filter = Arelastic::Queries::
|
4
|
+
def test_as_elastic
|
5
|
+
filter = Arelastic::Queries::Filter.new(
|
6
|
+
Arelastic::Queries::Match.new('color', 'green'),
|
7
|
+
'weight' => 23
|
8
|
+
)
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
}
|
17
|
-
}
|
18
|
-
}
|
19
|
-
}
|
20
|
-
assert_equal(expected, nested_filter.as_elastic)
|
10
|
+
expected = {
|
11
|
+
'filter' => {
|
12
|
+
'match' => {
|
13
|
+
'color' => 'green'
|
14
|
+
}
|
15
|
+
},
|
16
|
+
'weight' => 23
|
17
|
+
}
|
18
|
+
assert_equal expected, filter.as_elastic
|
21
19
|
end
|
22
20
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Queries::FunctionScoreTest < Minitest::Test
|
4
|
+
def test_as_elastic
|
5
|
+
function_score = Arelastic::Queries::FunctionScore.new(
|
6
|
+
query: Arelastic::Queries::MatchAll.new,
|
7
|
+
'functions' => [
|
8
|
+
Arelastic::Queries::Filter.new(
|
9
|
+
Arelastic::Queries::Match.new('color', 'green')
|
10
|
+
)
|
11
|
+
],
|
12
|
+
'boost' => 1.0
|
13
|
+
)
|
14
|
+
|
15
|
+
expected = {
|
16
|
+
'function_score' => {
|
17
|
+
'query' => { 'match_all' => {} },
|
18
|
+
'functions' => [
|
19
|
+
{
|
20
|
+
'filter' => {
|
21
|
+
'match' => {
|
22
|
+
'color' => 'green'
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
],
|
27
|
+
'boost' => 1.0
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
assert_equal expected, function_score.as_elastic
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arelastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Higgins
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- lib/arelastic/queries/exists.rb
|
60
60
|
- lib/arelastic/queries/field.rb
|
61
61
|
- lib/arelastic/queries/filter.rb
|
62
|
+
- lib/arelastic/queries/function_score.rb
|
62
63
|
- lib/arelastic/queries/geo_bounding_box.rb
|
63
64
|
- lib/arelastic/queries/geo_distance.rb
|
64
65
|
- lib/arelastic/queries/has_child.rb
|
@@ -115,6 +116,7 @@ files:
|
|
115
116
|
- test/arelastic/queries/dis_max_test.rb
|
116
117
|
- test/arelastic/queries/exists_test.rb
|
117
118
|
- test/arelastic/queries/filter_test.rb
|
119
|
+
- test/arelastic/queries/function_score_test.rb
|
118
120
|
- test/arelastic/queries/geo_bounding_box_test.rb
|
119
121
|
- test/arelastic/queries/geo_distance_test.rb
|
120
122
|
- test/arelastic/queries/has_child_test.rb
|