arelastic 3.2.0 → 3.3.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
  SHA256:
3
- metadata.gz: '0984b722326d3ec3a60b11114a249eba54399ba4a28a5f05635ec3c6570b16dc'
4
- data.tar.gz: 7f4451aa328ab073bc7aa66818bcb98b28ac6d2354c8d086213fdad1a441532d
3
+ metadata.gz: dbe2ab978160bb5c51def73c61c913c93582c675ce467caaa239a0967715826d
4
+ data.tar.gz: 4c0b18e7f5767acd373940f3eff5e1e4b676c1f4a6a08766b465f025c5f09f0c
5
5
  SHA512:
6
- metadata.gz: 01d68d3d7669ab860e232fdb6723b70460ddb103e2c8a4b3d4597a49d090b24da4ef25f3a6a847ee76e459e00b8b6f983499216aa9aa672bef80fe0141913af1
7
- data.tar.gz: 1a866d2a4b7129a7b59c44ed7c030748937f70bd0539afe9ed45fb6e10ca6a672d1fa4795672b5b9569b34c327764a8a1c798572e49090ebd017a631370430e9
6
+ metadata.gz: 36dd4ea278ccb16d0ffe3cc81d1c737fce8f76d25b5157a617cc2ca60b8ab5dfa02dbcad30f9ca634f343fb5f6bccc33e6050a0974602167614b193903c89b0a
7
+ data.tar.gz: 2e9c34a9603a8de8ea28a0e353f82014e5a1bed58ea0954769c104df550c56ba6dfc21a7e239295f5c15266ccc3ca434e242f9e9df6a376cd00fbe3ceae54582
data/README.md CHANGED
@@ -1,11 +1,9 @@
1
1
  [![Build Status](https://travis-ci.org/matthuhiggins/arelastic.svg?branch=master)](https://travis-ci.org/matthuhiggins/arelastic) [![Code Climate](https://codeclimate.com/github/matthuhiggins/arelastic/badges/gpa.svg)](https://codeclimate.com/github/matthuhiggins/arelastic)
2
2
  # Arelastic
3
3
 
4
- Arelastic is a Elasticsearch AST manager for Ruby. It simplifies the generation complex of Elasticsearch queries
4
+ Arelastic is a ElasticSearch AST manager for Ruby. It simplifies the generation complex of Elasticsearch queries.
5
5
 
6
- It is intended to be a framework framework; that is, you can build your own ORM with it.
7
-
8
- One example is [Elastic Record](https://github.com/data-axle/elastic_record)
6
+ It was extracted from my [Elastic Record](https://github.com/data-axle/elastic_record) project.
9
7
 
10
8
  ## Usage
11
9
 
@@ -14,6 +14,7 @@ module Arelastic
14
14
  geo_distance: Arelastic::Queries::GeoDistance,
15
15
  geo_polygon: Arelastic::Queries::GeoPolygon,
16
16
  has_child: Arelastic::Queries::HasChild,
17
+ has_parent: Arelastic::Queries::HasParent,
17
18
  ids: Arelastic::Queries::Ids,
18
19
  limit: Arelastic::Queries::Limit,
19
20
  match: Arelastic::Queries::Match,
@@ -0,0 +1,21 @@
1
+ module Arelastic
2
+ module Queries
3
+ class HasParent < Arelastic::Queries::Query
4
+ attr_reader :parent_type, :query
5
+
6
+ def initialize parent_type, query
7
+ @parent_type = parent_type
8
+ @query = query
9
+ end
10
+
11
+ def as_elastic
12
+ {
13
+ "has_parent" => {
14
+ "parent_type" => parent_type,
15
+ "query" => convert_to_elastic(query)
16
+ }
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -5,6 +5,14 @@ module Arelastic
5
5
  Arelastic::Queries::Nested.new path, self
6
6
  end
7
7
 
8
+ def has_child path
9
+ Arelastic::Queries::HasChild.new path, self
10
+ end
11
+
12
+ def has_parent path
13
+ Arelastic::Queries::HasParent.new path, self
14
+ end
15
+
8
16
  def negate
9
17
  Arelastic::Queries::Bool.new must_not: self
10
18
  end
@@ -12,6 +12,7 @@ require 'arelastic/queries/geo_bounding_box'
12
12
  require 'arelastic/queries/geo_distance'
13
13
  require 'arelastic/queries/geo_polygon'
14
14
  require 'arelastic/queries/has_child'
15
+ require 'arelastic/queries/has_parent'
15
16
  require 'arelastic/queries/ids'
16
17
  require 'arelastic/queries/limit'
17
18
  require 'arelastic/queries/match'
@@ -0,0 +1,9 @@
1
+ require 'helper'
2
+
3
+ class Arelastic::Queries::HasParentTest < Minitest::Test
4
+ def test_as_elastic
5
+ expected = {"has_parent" => {"parent_type" => "user", "query" => {"query_string" => "foo"}}}
6
+
7
+ assert_equal expected, Arelastic::Queries::HasParent.new("user", {"query_string" => "foo"}).as_elastic
8
+ end
9
+ end
@@ -16,6 +16,36 @@ class Arelastic::Queries::QueryTest < Minitest::Test
16
16
  assert_equal(expected, nested_query.as_elastic)
17
17
  end
18
18
 
19
+ def test_has_child
20
+ query = Arelastic::Queries::Term.new('foo', 'bar')
21
+
22
+ nested_query = query.has_child 'links'
23
+
24
+ assert nested_query.is_a?(Arelastic::Queries::HasChild)
25
+ expected = {
26
+ "has_child" => {
27
+ "type" => "links",
28
+ "query" => query.as_elastic
29
+ }
30
+ }
31
+ assert_equal(expected, nested_query.as_elastic)
32
+ end
33
+
34
+ def test_has_parent
35
+ query = Arelastic::Queries::Term.new('foo', 'bar')
36
+
37
+ nested_query = query.has_parent 'links'
38
+
39
+ assert nested_query.is_a?(Arelastic::Queries::HasParent)
40
+ expected = {
41
+ "has_parent" => {
42
+ "parent_type" => "links",
43
+ "query" => query.as_elastic
44
+ }
45
+ }
46
+ assert_equal(expected, nested_query.as_elastic)
47
+ end
48
+
19
49
  def test_negate
20
50
  filter = Arelastic::Queries::Term.new 'foo', 'bar'
21
51
 
data/test/helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'simplecov'
2
+
1
3
  require 'bundler/setup'
2
4
  Bundler.require
3
5
 
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: 3.2.0
4
+ version: 3.3.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: 2021-05-28 00:00:00.000000000 Z
11
+ date: 2022-01-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Build Elastic Search queries with objects
14
14
  email: developer@matthewhiggins.com
@@ -71,6 +71,7 @@ files:
71
71
  - lib/arelastic/queries/geo_distance.rb
72
72
  - lib/arelastic/queries/geo_polygon.rb
73
73
  - lib/arelastic/queries/has_child.rb
74
+ - lib/arelastic/queries/has_parent.rb
74
75
  - lib/arelastic/queries/ids.rb
75
76
  - lib/arelastic/queries/limit.rb
76
77
  - lib/arelastic/queries/match.rb
@@ -136,6 +137,7 @@ files:
136
137
  - test/arelastic/queries/geo_distance_test.rb
137
138
  - test/arelastic/queries/geo_polygon_test.rb
138
139
  - test/arelastic/queries/has_child_test.rb
140
+ - test/arelastic/queries/has_parent_test.rb
139
141
  - test/arelastic/queries/ids_test.rb
140
142
  - test/arelastic/queries/match_all_test.rb
141
143
  - test/arelastic/queries/match_none_test.rb
@@ -175,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
177
  - !ruby/object:Gem::Version
176
178
  version: '0'
177
179
  requirements: []
178
- rubygems_version: 3.2.15
180
+ rubygems_version: 3.3.6
179
181
  signing_key:
180
182
  specification_version: 4
181
183
  summary: Elastic Search query builder