arelastic 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9423c0576c44867372fc88a1ca44407425d06e15
4
- data.tar.gz: aa0065aea8b9ba21ff8cdf1a757f1117a1a53f23
3
+ metadata.gz: 11298654c38fbd7bd96231464189148b4949e182
4
+ data.tar.gz: 171eb4e3b6122b231c5e5d3944970ada55080fc8
5
5
  SHA512:
6
- metadata.gz: b5818ba5af9d8e1df98f26288ad4a36e5872f2ce1dc057224bd18643df27832935ec69fe8702aaa90077dc5a99b88d6fce8693b8345b58fa652faa997538ab71
7
- data.tar.gz: 5d0fd2581a854c34602319803c50b3a13f87b66d9e7ef524f8acb5676d75f5370cd37d18ddc3070c8db6db831b353e71112ef76f4e0ffaa7ce9b31fe7c4246fb
6
+ metadata.gz: 7cd3171f03da4ce5bc59972f0614448e93b65925bd29129076c390d273dd5ee5c68a284ee90ba5874e83f170c5b34c309ebac701184e20710f778a023709b018
7
+ data.tar.gz: 3d777f0dbcf20b748f912b59580a3c85704a6b1a8958c248591d6f992ad84d82e83a596b85aadfb123c8152bc2775b0a762e4d2fd42289c690abf40ac21d4e30
@@ -8,11 +8,11 @@ module Arelastic
8
8
  end
9
9
 
10
10
  def asc(options = nil)
11
- Arelastic::Sorts::Sort.new({field => 'asc'}, options)
11
+ Arelastic::Sorts::Field.new({field => 'asc'}, options)
12
12
  end
13
13
 
14
14
  def desc(options = nil)
15
- Arelastic::Sorts::Sort.new({field => 'desc'}, options)
15
+ Arelastic::Sorts::Field.new({field => 'desc'}, options)
16
16
  end
17
17
  end
18
18
  end
@@ -1 +1,2 @@
1
- require 'arelastic/sorts/sort'
1
+ require 'arelastic/sorts/field'
2
+ require 'arelastic/sorts/geo_distance'
@@ -1,18 +1,18 @@
1
1
  module Arelastic
2
2
  module Sorts
3
- class Sort < Arelastic::Nodes::Node
3
+ class Field < Arelastic::Nodes::Node
4
4
  attr_reader :field, :options
5
5
 
6
- # Sort.new('price').as_elastic
6
+ # Field.new('price').as_elastic
7
7
  # => 'price'
8
8
  #
9
- # Sort.new('price' => 'asc').as_elastic
9
+ # Field.new('price' => 'asc').as_elastic
10
10
  # => {'price' => 'asc'}
11
11
  #
12
- # Sort.new('price', 'order' => 'asc').as_elastic
12
+ # Field.new('price', 'order' => 'asc').as_elastic
13
13
  # => {'price' => {'order', 'asc'}}
14
14
  #
15
- # Sort.new({'price' => 'asc'}, {'missing' => '_last'}).as_elastic
15
+ # Field.new({'price' => 'asc'}, {'missing' => '_last'}).as_elastic
16
16
  # => {'price' => {'order' => 'asc', 'missing' => '_last'}}
17
17
  #
18
18
  def initialize(field, extra_options = nil)
@@ -31,9 +31,9 @@ module Arelastic
31
31
  reverse_order = ordering == 'desc' ? 'asc' : 'desc'
32
32
 
33
33
  if options.is_a?(Hash)
34
- Arelastic::Sorts::Sort.new(field, options.merge('order' => reverse_order))
34
+ Arelastic::Sorts::Field.new(field, options.merge('order' => reverse_order))
35
35
  else
36
- Arelastic::Sorts::Sort.new(field => reverse_order)
36
+ Arelastic::Sorts::Field.new(field => reverse_order)
37
37
  end
38
38
  end
39
39
 
@@ -0,0 +1,23 @@
1
+ module Arelastic
2
+ module Sorts
3
+ class GeoDistance < Arelastic::Nodes::Node
4
+ attr_accessor :field, :location, :options
5
+
6
+ # GeoDistance.new('coordinates', [-70, 40]).as_elastic
7
+ # => {'_geo_distance' => {'coordinates' => [-70, 40]}}
8
+ #
9
+ # GeoDistance.new('coordinates', [-70, 40], 'distance_type' => 'plane').as_elastic
10
+ # => {'_geo_distance' => {'coordinates' => [-70, 40], 'distance_type' => 'plane'}}
11
+ #
12
+ def initialize(field, location, options = {})
13
+ @field = field
14
+ @location = location
15
+ @options = options
16
+ end
17
+
18
+ def as_elastic
19
+ {'_geo_distance' => {field => location}.update(options)}
20
+ end
21
+ end
22
+ end
23
+ end
@@ -3,7 +3,7 @@ require 'helper'
3
3
  class Arelastic::Searches::SortTest < MiniTest::Spec
4
4
  def test_as_elastic
5
5
  sort = Arelastic::Searches::Sort.new [
6
- Arelastic::Sorts::Sort.new('price'),
6
+ Arelastic::Sorts::Field.new('price'),
7
7
  {'name' => 'asc'}
8
8
  ]
9
9
  expected = {'sort' => ['price', {'name' => 'asc'}]}
@@ -0,0 +1,47 @@
1
+ require 'helper'
2
+
3
+ class Arelastic::Sorts::FieldTest < MiniTest::Spec
4
+ def test_as_elastic
5
+ assert_equal(
6
+ 'price',
7
+ Arelastic::Sorts::Field.new('price').as_elastic,
8
+ )
9
+
10
+ assert_equal(
11
+ {'price' => 'asc'},
12
+ Arelastic::Sorts::Field.new('price' => 'asc').as_elastic
13
+ )
14
+
15
+ assert_equal(
16
+ {'price' => {'order' => 'asc'}},
17
+ Arelastic::Sorts::Field.new('price', 'order' => 'asc').as_elastic
18
+ )
19
+
20
+ assert_equal(
21
+ {'price' => {'order' => 'asc', 'missing' => '_last'}},
22
+ Arelastic::Sorts::Field.new({'price' => 'asc'}, {'missing' => '_last'}).as_elastic
23
+ )
24
+ end
25
+
26
+ def test_reverse
27
+ assert_equal(
28
+ {'price' => 'desc'},
29
+ Arelastic::Sorts::Field.new('price').reverse.as_elastic,
30
+ )
31
+
32
+ assert_equal(
33
+ {'price' => 'desc'},
34
+ Arelastic::Sorts::Field.new('price' => 'asc').reverse.as_elastic
35
+ )
36
+
37
+ assert_equal(
38
+ {'price' => 'asc'},
39
+ Arelastic::Sorts::Field.new('price' => 'desc').reverse.as_elastic
40
+ )
41
+
42
+ assert_equal(
43
+ {'price' => {'order' => 'asc', 'missing' => '_last'}},
44
+ Arelastic::Sorts::Field.new({'price' => 'desc'}, {'missing' => '_last'}).reverse.as_elastic
45
+ )
46
+ end
47
+ end
@@ -0,0 +1,17 @@
1
+ require 'helper'
2
+
3
+ class Arelastic::Sorts::GeoDistanceTest < MiniTest::Spec
4
+ def test_as_elastic
5
+ assert_equal(
6
+ {"_geo_distance" => {"coordinates" => [-70, 40]}},
7
+ Arelastic::Sorts::GeoDistance.new('coordinates', [-70, 40]).as_elastic,
8
+ )
9
+ end
10
+
11
+ def test_as_elastic_with_options
12
+ assert_equal(
13
+ {"_geo_distance" => {"coordinates" => [-70, 40], "distance_type" => "plane"}},
14
+ Arelastic::Sorts::GeoDistance.new('coordinates', [-70, 40], 'distance_type' => 'plane').as_elastic,
15
+ )
16
+ end
17
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arelastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Higgins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-13 00:00:00.000000000 Z
11
+ date: 2016-01-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Build Elastic Search queries with objects
14
14
  email: developer@matthewhiggins.com
@@ -97,8 +97,8 @@ files:
97
97
  - lib/arelastic/searches/sort.rb
98
98
  - lib/arelastic/searches/terms.rb
99
99
  - lib/arelastic/sorts.rb
100
- - lib/arelastic/sorts/asc.rb
101
- - lib/arelastic/sorts/sort.rb
100
+ - lib/arelastic/sorts/field.rb
101
+ - lib/arelastic/sorts/geo_distance.rb
102
102
  - test/arelastic/aggregations/aggregation_test.rb
103
103
  - test/arelastic/aggregations/date_histogram_test.rb
104
104
  - test/arelastic/aggregations/filter_test.rb
@@ -140,7 +140,8 @@ files:
140
140
  - test/arelastic/queries/wildcard_test.rb
141
141
  - test/arelastic/searches/aggregations_test.rb
142
142
  - test/arelastic/searches/sort_test.rb
143
- - test/arelastic/sorts/sort_test.rb
143
+ - test/arelastic/sorts/field_test.rb
144
+ - test/arelastic/sorts/geo_distance_test.rb
144
145
  - test/helper.rb
145
146
  homepage: http://github.com/matthuhiggins/arelastic
146
147
  licenses:
File without changes
@@ -1,47 +0,0 @@
1
- require 'helper'
2
-
3
- class Arelastic::Sorts::SortTest < MiniTest::Spec
4
- def test_as_elastic
5
- assert_equal(
6
- 'price',
7
- Arelastic::Sorts::Sort.new('price').as_elastic,
8
- )
9
-
10
- assert_equal(
11
- {'price' => 'asc'},
12
- Arelastic::Sorts::Sort.new('price' => 'asc').as_elastic
13
- )
14
-
15
- assert_equal(
16
- {'price' => {'order' => 'asc'}},
17
- Arelastic::Sorts::Sort.new('price', 'order' => 'asc').as_elastic
18
- )
19
-
20
- assert_equal(
21
- {'price' => {'order' => 'asc', 'missing' => '_last'}},
22
- Arelastic::Sorts::Sort.new({'price' => 'asc'}, {'missing' => '_last'}).as_elastic
23
- )
24
- end
25
-
26
- def test_reverse
27
- assert_equal(
28
- {'price' => 'desc'},
29
- Arelastic::Sorts::Sort.new('price').reverse.as_elastic,
30
- )
31
-
32
- assert_equal(
33
- {'price' => 'desc'},
34
- Arelastic::Sorts::Sort.new('price' => 'asc').reverse.as_elastic
35
- )
36
-
37
- assert_equal(
38
- {'price' => 'asc'},
39
- Arelastic::Sorts::Sort.new('price' => 'desc').reverse.as_elastic
40
- )
41
-
42
- assert_equal(
43
- {'price' => {'order' => 'asc', 'missing' => '_last'}},
44
- Arelastic::Sorts::Sort.new({'price' => 'desc'}, {'missing' => '_last'}).reverse.as_elastic
45
- )
46
- end
47
- end