arelastic 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -0
- data/lib/arelastic/builders/filter.rb +11 -7
- data/lib/arelastic/filters.rb +1 -0
- data/lib/arelastic/filters/geo_distance.rb +19 -0
- data/lib/arelastic/filters/terms.rb +12 -1
- data/test/arelastic/builders/filter_test.rb +15 -2
- data/test/arelastic/filters/geo_distance_test.rb +14 -0
- metadata +4 -2
data/README.rdoc
CHANGED
@@ -9,6 +9,10 @@ module Arelastic
|
|
9
9
|
def ids *ids
|
10
10
|
Arelastic::Filters::Ids.new ids.flatten
|
11
11
|
end
|
12
|
+
|
13
|
+
def not expr
|
14
|
+
Arelastic::Filters::Not.new expr
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
14
18
|
def eq other
|
@@ -16,10 +20,10 @@ module Arelastic
|
|
16
20
|
end
|
17
21
|
|
18
22
|
def not_eq other
|
19
|
-
self.not eq(other)
|
23
|
+
self.class.not eq(other)
|
20
24
|
end
|
21
25
|
|
22
|
-
def in other
|
26
|
+
def in other, options = {}
|
23
27
|
case other
|
24
28
|
when Range
|
25
29
|
if other.exclude_end?
|
@@ -28,12 +32,12 @@ module Arelastic
|
|
28
32
|
range 'gte' => other.begin, 'lte' => other.end
|
29
33
|
end
|
30
34
|
else
|
31
|
-
Arelastic::Filters::Terms.new field, other
|
35
|
+
Arelastic::Filters::Terms.new field, other, options
|
32
36
|
end
|
33
37
|
end
|
34
38
|
|
35
|
-
def not_in other
|
36
|
-
self.not self.in(other)
|
39
|
+
def not_in other, options = {}
|
40
|
+
self.class.not self.in(other, options)
|
37
41
|
end
|
38
42
|
|
39
43
|
def prefix other
|
@@ -64,8 +68,8 @@ module Arelastic
|
|
64
68
|
range 'lt' => other
|
65
69
|
end
|
66
70
|
|
67
|
-
def
|
68
|
-
Arelastic::Filters::
|
71
|
+
def distance location, distance, options = {}
|
72
|
+
Arelastic::Filters::GeoDistance.new(field, location, distance, options)
|
69
73
|
end
|
70
74
|
|
71
75
|
private
|
data/lib/arelastic/filters.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Filters
|
3
|
+
class GeoDistance < Arelastic::Filters::Filter
|
4
|
+
attr_accessor :field, :location, :distance, :options
|
5
|
+
def initialize(field, location, distance, options = {})
|
6
|
+
@field = field
|
7
|
+
@location = location
|
8
|
+
@distance = distance
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def as_elastic
|
13
|
+
params = { field => location, "distance" => distance }.update(options)
|
14
|
+
|
15
|
+
{ "geo_distance" => params }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,7 +1,18 @@
|
|
1
1
|
module Arelastic
|
2
2
|
module Filters
|
3
3
|
class Terms < Arelastic::Filters::Filter
|
4
|
-
|
4
|
+
attr_accessor :field, :terms, :options
|
5
|
+
def initialize(field, terms, options = {})
|
6
|
+
@field = field
|
7
|
+
@terms = terms
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def as_elastic
|
12
|
+
params = {field => terms}.update(options)
|
13
|
+
|
14
|
+
{ "terms" => params }
|
15
|
+
end
|
5
16
|
end
|
6
17
|
end
|
7
18
|
end
|
@@ -17,10 +17,15 @@ class Arelastic::Builders::FilterTest < MiniTest::Spec
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_in
|
20
|
-
expected = {"terms" => {"color"=>["blue"]}}
|
20
|
+
expected = {"terms" => {"color" => ["blue"]}}
|
21
21
|
assert_equal expected, builder.in(['blue']).as_elastic
|
22
22
|
end
|
23
23
|
|
24
|
+
def test_in_with_options
|
25
|
+
expected = {"terms" => {"color" => ["blue"], "execution" => "bool"}}
|
26
|
+
assert_equal expected, builder.in(['blue'], "execution" => "bool").as_elastic
|
27
|
+
end
|
28
|
+
|
24
29
|
def test_in_with_range
|
25
30
|
expected = {"range" => {"color" => {"gte"=>1, "lte"=>3}}}
|
26
31
|
assert_equal expected, builder.in(1..3).as_elastic
|
@@ -40,7 +45,7 @@ class Arelastic::Builders::FilterTest < MiniTest::Spec
|
|
40
45
|
end
|
41
46
|
|
42
47
|
def test_exists
|
43
|
-
expected = {"exists" => {"field"=>"color"}}
|
48
|
+
expected = {"exists" => {"field" => "color"}}
|
44
49
|
assert_equal expected, builder.exists.as_elastic
|
45
50
|
end
|
46
51
|
|
@@ -49,6 +54,14 @@ class Arelastic::Builders::FilterTest < MiniTest::Spec
|
|
49
54
|
assert_equal expected, builder.lt(5).as_elastic
|
50
55
|
end
|
51
56
|
|
57
|
+
def test_distance
|
58
|
+
expected = {"geo_distance" => {"distance" => "10km", "color" => [10, 11]}}
|
59
|
+
assert_equal expected, builder.distance([10, 11], '10km').as_elastic
|
60
|
+
|
61
|
+
expected = {"geo_distance" => {"distance" => "10km", "color" => [10, 11], "distance_type" => "plane"}}
|
62
|
+
assert_equal expected, builder.distance([10, 11], '10km', 'distance_type' => 'plane').as_elastic
|
63
|
+
end
|
64
|
+
|
52
65
|
private
|
53
66
|
def builder
|
54
67
|
@builder ||= Arelastic::Builders::Filter['color']
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Filters::GeoDistanceTest < MiniTest::Spec
|
4
|
+
def test_as_elastic
|
5
|
+
expected = {
|
6
|
+
"geo_distance" => {
|
7
|
+
"pin.location" => [40, -70],
|
8
|
+
"distance" => "12km"
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
assert_equal expected, Arelastic::Filters::GeoDistance.new('pin.location', [40, -70], '12km').as_elastic
|
13
|
+
end
|
14
|
+
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: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-06 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Build Elastic Search queries with objects
|
15
15
|
email: developer@matthewhiggins.com
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- lib/arelastic/filters/and.rb
|
37
37
|
- lib/arelastic/filters/exists.rb
|
38
38
|
- lib/arelastic/filters/filter.rb
|
39
|
+
- lib/arelastic/filters/geo_distance.rb
|
39
40
|
- lib/arelastic/filters/ids.rb
|
40
41
|
- lib/arelastic/filters/limit.rb
|
41
42
|
- lib/arelastic/filters/missing.rb
|
@@ -79,6 +80,7 @@ files:
|
|
79
80
|
- test/arelastic/facets/terms_test.rb
|
80
81
|
- test/arelastic/filters/exists_test.rb
|
81
82
|
- test/arelastic/filters/filter_test.rb
|
83
|
+
- test/arelastic/filters/geo_distance_test.rb
|
82
84
|
- test/arelastic/filters/ids_test.rb
|
83
85
|
- test/arelastic/filters/missing_test.rb
|
84
86
|
- test/arelastic/filters/not_test.rb
|