arelastic 2.1.1 → 2.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93b2709cca3f4723d5f150393c9f6775a8b7cbcc
4
- data.tar.gz: e5486609d6bc06427221f16934c654e4734251ee
3
+ metadata.gz: d7e7cece5f867bbfe2dedcc985f0f6fec1a930fa
4
+ data.tar.gz: 76161f732806f810c4b8b48a197331fec647fb1f
5
5
  SHA512:
6
- metadata.gz: e487e432fee0ec87e3605e53fb31762afc997b3d70f7a462a7268a590903d8966d6cc65d5f45a68923097c856381e8f121cabf21288647cad9bafe074a0f73a5
7
- data.tar.gz: 0fba9e18f025a42890305a02f5cffadc7c930c64f90b6bb86608529d53c785f533ffd3cfcc15ea03bd2c7a2bd06316f5c40a9e68e8a1ab7920f4da79d861f418
6
+ metadata.gz: '08fef26bfa8760dfff29d33e42926ffa23ea1d3ef978a64668c19047f2482eda7e6ff51f4095e694ade704db5f5f64740e97b07dd227180b1688fd86adceeea7'
7
+ data.tar.gz: 99c5b03d1ca49a7e1c7b262fd95cc002b61e1e9ae583f32270dcb8bd4da65f9646e6bca6d8134e1dca692250c703f4e69ff2313e4674ab333994b3229c24fd00
@@ -5,7 +5,7 @@ module Arelastic
5
5
 
6
6
  def initialize(name, options = {})
7
7
  options = options.dup
8
- @aggs = options.delete(:aggs) || options.delete('aggs')
8
+ @aggs = read_option! options, 'aggs'
9
9
  super(name, options)
10
10
  end
11
11
 
@@ -13,6 +13,10 @@ module Arelastic
13
13
  end
14
14
  end
15
15
 
16
+ def read_option!(options, key)
17
+ options.delete(key) || options.delete(key.to_sym)
18
+ end
19
+
16
20
  def ==(other)
17
21
  other.is_a?(Arelastic::Nodes::Node) && as_elastic == other.as_elastic
18
22
  end
@@ -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(must: nil, filter: nil, should: nil, must_not: nil)
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
@@ -3,7 +3,7 @@ module Arelastic
3
3
  class DisMax < Arelastic::Queries::Query
4
4
  attr_accessor :queries, :options
5
5
  def initialize(options)
6
- @queries = options.delete('queries') || options.delete(:queries)
6
+ @queries = read_option! options, 'queries'
7
7
  @options = options
8
8
  end
9
9
 
@@ -1,8 +1,16 @@
1
1
  module Arelastic
2
2
  module Queries
3
3
  class Filter < Arelastic::Queries::Query
4
- def nested path
5
- Arelastic::Queries::Nested.new path, self
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
- bool = Arelastic::Queries::DisMax.new(
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, bool.as_elastic
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 test_nested
5
- filter = Arelastic::Queries::Term.new('foo', 'bar')
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
- nested_filter = filter.nested 'links'
8
-
9
- assert nested_filter.is_a?(Arelastic::Queries::Nested)
10
- expected = {
11
- "nested" => {
12
- "path" => "links",
13
- "query" => {
14
- "term" => {
15
- "foo" => "bar"
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.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