arelastic 0.5.0 → 0.6.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: 48bbbfd23e2aaa2b73017ccc16b002661b6a31f5
4
- data.tar.gz: 48fa91f28a48d51ba96eae2a66776b76187405c5
3
+ metadata.gz: 07f59256aabbab61856a138e8fe03c35869d1458
4
+ data.tar.gz: 8058c713097d4abdaa99c31876ca4004a47cdff8
5
5
  SHA512:
6
- metadata.gz: 934d9ac4da52da217fa78904a70899f1b6fca2857159b7054f1b2976cebac351355864cdd1d1184e1647b798980ad0c84f79b39159202beb785b6b747849d939
7
- data.tar.gz: d89ea4221656300193f51b424cdf4a222a32eef357bee03206c583adc4edf02e28ebbfb3d89454aeb9e9ae9bfccde414239b6163f3440dbfaeb4c790e45142e7
6
+ metadata.gz: de4a47668f6a772019ccb19605e3a1084a187cf73efe232d23eb4c8d98db9a74960a52ff022888754d9e27f6a3e81937baefdc82a7719ffcf9f22250d9b65f9e
7
+ data.tar.gz: b4a33f99f145257dd727f2f5303976e97ae6e4de54262fa267c68d2b4586f804d6804fec20df64570ae3b50d7875af163f5bb943febdc49a4f89bcef9eb8fe6e
@@ -0,0 +1,25 @@
1
+ module Arelastic
2
+ module Aggregations
3
+ class Aggregation < Arelastic::Nodes::Node
4
+ attr_accessor :name, :options, :aggs
5
+
6
+ def initialize(name, options)
7
+ @name = name
8
+ @options = options
9
+ end
10
+
11
+ def as_elastic
12
+ params = as_elastic_aggregation
13
+ # if aggs.any?
14
+ # params['aggs'] = convert_to_elastic(aggs)
15
+ # end
16
+
17
+ {name => params}
18
+ end
19
+
20
+ # def nested path
21
+ # Arelastic::Aggregations::Nested.new path, self
22
+ # end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ module Arelastic
2
+ module Aggregations
3
+ class Min < Arelastic::Aggs::Aggregation
4
+ attr_accessor :options
5
+
6
+ def initialize name, options
7
+ # @field = field
8
+ @options = options
9
+ end
10
+
11
+ def as_elastic_aggregation
12
+ # {"min" => options}
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ module Arelastic
2
+ module Aggregations
3
+ class Terms < Arelastic::Aggregations::Aggregation
4
+ def as_elastic_aggregation
5
+ {"terms" => options}
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ require 'arelastic/aggregations/aggregation'
2
+
3
+ require 'arelastic/aggregations/terms'
@@ -0,0 +1,19 @@
1
+ module Arelastic
2
+ module Builders
3
+ class Aggregation < Struct.new :name
4
+ class << self
5
+ def [](name)
6
+ new(name)
7
+ end
8
+ end
9
+
10
+ def terms field, options = {}
11
+ Arelastic::Facets::Terms.new name, field, options
12
+ end
13
+
14
+ def histogram options
15
+ Arelastic::Facets::Histogram.new name, options
16
+ end
17
+ end
18
+ end
19
+ end
@@ -10,6 +10,10 @@ module Arelastic
10
10
  filter[field]
11
11
  end
12
12
 
13
+ def aggregation
14
+ Arelastic::Builders::Aggregation
15
+ end
16
+
13
17
  def facet
14
18
  Arelastic::Builders::Facet
15
19
  end
@@ -24,4 +28,4 @@ module Arelastic
24
28
  end
25
29
  end
26
30
  end
27
- end
31
+ end
@@ -1,3 +1,4 @@
1
+ require 'arelastic/builders/aggregation'
1
2
  require 'arelastic/builders/filter'
2
3
  require 'arelastic/builders/facet'
3
4
  require 'arelastic/builders/mapping'
@@ -0,0 +1,14 @@
1
+ module Arelastic
2
+ module Searches
3
+ class Aggregations < Arelastic::Searches::Search
4
+ attr_accessor :grouping
5
+ def initialize aggregations
6
+ @grouping = Arelastic::Nodes::HashGroup.new aggregations
7
+ end
8
+
9
+ def as_elastic
10
+ { "aggs" => convert_to_elastic(grouping) }
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ module Arelastic
2
+ module Aggregations
3
+ class Terms < Arelastic::Aggs::Aggregation
4
+ attr_accessor :field, :options
5
+
6
+ def initialize field, options = {}
7
+ @field = field
8
+ @options = options
9
+ end
10
+
11
+ def as_elastic
12
+ params = {"field" => field}.update(options)
13
+
14
+ {"terms" => params}
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,6 @@
1
1
  require 'arelastic/searches/search'
2
2
 
3
+ require 'arelastic/searches/aggregations'
3
4
  require 'arelastic/searches/facets'
4
5
  require 'arelastic/searches/filter'
5
6
  require 'arelastic/searches/from'
data/lib/arelastic.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'arelastic/arities'
2
2
  require 'arelastic/nodes'
3
+ require 'arelastic/aggregations'
3
4
  require 'arelastic/facets'
4
5
  require 'arelastic/filters'
5
6
  require 'arelastic/mappings'
@@ -7,4 +8,4 @@ require 'arelastic/queries'
7
8
  require 'arelastic/searches'
8
9
  require 'arelastic/sorts'
9
10
 
10
- require 'arelastic/builders'
11
+ require 'arelastic/builders'
@@ -0,0 +1,17 @@
1
+ require 'helper'
2
+
3
+ class Arelastic::Aggregations::TermsTest < MiniTest::Unit::TestCase
4
+ def test_as_elastic
5
+ aggregation = Arelastic::Aggregations::Terms.new('foo', 'field' => 'tags', 'size' => 10)
6
+ expected = {
7
+ "foo" => {
8
+ "terms" => {
9
+ "field" => "tags",
10
+ "size" => 10,
11
+ }
12
+ }
13
+ }
14
+
15
+ assert_equal expected, aggregation.as_elastic
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ require 'helper'
2
+
3
+ class Arelastic::Builders::AggregationTest < MiniTest::Unit::TestCase
4
+ def test_terms
5
+ expected = {"name" => {"terms" => {"field" => "term"}}}
6
+ actual = Arelastic::Builders::Aggregation['name'].terms('term').as_elastic
7
+
8
+ assert_equal expected, actual
9
+ end
10
+ end
@@ -2,8 +2,8 @@ require 'helper'
2
2
 
3
3
  class Arelastic::Builders::FacetTest < MiniTest::Unit::TestCase
4
4
  def test_terms
5
- expected = {"name"=>{"terms"=>{"field"=>"term"}}}
5
+ expected = {"name" => {"terms" => {"field" => "term"}}}
6
6
  actual = Arelastic::Builders::Facet['name'].terms('term').as_elastic
7
7
  assert_equal expected, actual
8
8
  end
9
- end
9
+ end
@@ -9,6 +9,10 @@ class Arelastic::Builders::SearchTest < MiniTest::Unit::TestCase
9
9
  assert_kind_of Arelastic::Builders::Filter, Arelastic::Builders::Search['poop']
10
10
  end
11
11
 
12
+ def test_aggregation
13
+ assert_equal Arelastic::Builders::Aggregation, Arelastic::Builders::Search.aggregation
14
+ end
15
+
12
16
  def test_facet
13
17
  assert_equal Arelastic::Builders::Facet, Arelastic::Builders::Search.facet
14
18
  end
@@ -20,4 +24,4 @@ class Arelastic::Builders::SearchTest < MiniTest::Unit::TestCase
20
24
  def test_filter
21
25
  assert_equal Arelastic::Builders::Sort, Arelastic::Builders::Search.sort
22
26
  end
23
- end
27
+ end
@@ -4,7 +4,7 @@ class Arelastic::Queries::MultiMatchTest < MiniTest::Unit::TestCase
4
4
  def test_as_elastic
5
5
  query = "bar"
6
6
  fields = ["field_1", "field_2"]
7
- multi_match = Arelastic::Queries::MultiMatch.new(query, fields)
7
+ multi_match = Arelastic::Queries::MultiMatch.new(fields, query)
8
8
  expected = {
9
9
  "multi_match" => {
10
10
  "query" => "bar",
@@ -21,7 +21,7 @@ class Arelastic::Queries::MultiMatchTest < MiniTest::Unit::TestCase
21
21
  "use_dis_max" => false,
22
22
  "tie_breaker" => 0.5
23
23
  }
24
- multi_match = Arelastic::Queries::MultiMatch.new(query, fields, options)
24
+ multi_match = Arelastic::Queries::MultiMatch.new(fields, query, options)
25
25
  expected = {
26
26
  "multi_match" => {
27
27
  "query" => "bar",
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: 0.5.0
4
+ version: 0.6.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: 2014-09-20 00:00:00.000000000 Z
11
+ date: 2014-09-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Build Elastic Search queries with objects
14
14
  email: developer@matthewhiggins.com
@@ -19,11 +19,16 @@ extra_rdoc_files:
19
19
  files:
20
20
  - README.rdoc
21
21
  - lib/arelastic.rb
22
+ - lib/arelastic/aggregations.rb
23
+ - lib/arelastic/aggregations/aggregation.rb
24
+ - lib/arelastic/aggregations/min.rb
25
+ - lib/arelastic/aggregations/terms.rb
22
26
  - lib/arelastic/arities.rb
23
27
  - lib/arelastic/arities/binary.rb
24
28
  - lib/arelastic/arities/polyadic.rb
25
29
  - lib/arelastic/arities/unary.rb
26
30
  - lib/arelastic/builders.rb
31
+ - lib/arelastic/builders/aggregation.rb
27
32
  - lib/arelastic/builders/facet.rb
28
33
  - lib/arelastic/builders/filter.rb
29
34
  - lib/arelastic/builders/mapping.rb
@@ -81,6 +86,7 @@ files:
81
86
  - lib/arelastic/queries/term.rb
82
87
  - lib/arelastic/queries/terms.rb
83
88
  - lib/arelastic/searches.rb
89
+ - lib/arelastic/searches/aggregations.rb
84
90
  - lib/arelastic/searches/facets.rb
85
91
  - lib/arelastic/searches/filter.rb
86
92
  - lib/arelastic/searches/from.rb
@@ -88,12 +94,15 @@ files:
88
94
  - lib/arelastic/searches/search.rb
89
95
  - lib/arelastic/searches/size.rb
90
96
  - lib/arelastic/searches/sort.rb
97
+ - lib/arelastic/searches/terms.rb
91
98
  - lib/arelastic/sorts.rb
92
99
  - lib/arelastic/sorts/asc.rb
93
100
  - lib/arelastic/sorts/sort.rb
101
+ - test/arelastic/aggregations/terms_test.rb
94
102
  - test/arelastic/arities/binary_test.rb
95
103
  - test/arelastic/arities/polyadic_test.rb
96
104
  - test/arelastic/arities/unary_test.rb
105
+ - test/arelastic/builders/aggregation_test.rb
97
106
  - test/arelastic/builders/facet_test.rb
98
107
  - test/arelastic/builders/filter_test.rb
99
108
  - test/arelastic/builders/mapping_test.rb