arelastic 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/arelastic/builders/query.rb +2 -2
- data/lib/arelastic/filters.rb +1 -0
- data/lib/arelastic/filters/has_child.rb +21 -0
- data/lib/arelastic/queries/filtered.rb +6 -1
- data/test/arelastic/builders/query_test.rb +2 -2
- data/test/arelastic/filters/has_child_test.rb +9 -0
- data/test/arelastic/queries/filtered_test.rb +2 -2
- data/test/arelastic/queries/query_test.rb +2 -1
- metadata +4 -2
@@ -6,8 +6,8 @@ module Arelastic
|
|
6
6
|
new(field)
|
7
7
|
end
|
8
8
|
|
9
|
-
def constant_score(
|
10
|
-
query Arelastic::Queries::ConstantScore.new(
|
9
|
+
def constant_score(search)
|
10
|
+
query Arelastic::Queries::ConstantScore.new(search)
|
11
11
|
end
|
12
12
|
|
13
13
|
def filtered(query, filter)
|
data/lib/arelastic/filters.rb
CHANGED
@@ -3,6 +3,7 @@ require 'arelastic/filters/filter'
|
|
3
3
|
require 'arelastic/filters/and'
|
4
4
|
require 'arelastic/filters/exists'
|
5
5
|
require 'arelastic/filters/geo_distance'
|
6
|
+
require 'arelastic/filters/has_child'
|
6
7
|
require 'arelastic/filters/ids'
|
7
8
|
require 'arelastic/filters/limit'
|
8
9
|
require 'arelastic/filters/match_all'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Arelastic
|
2
|
+
module Filters
|
3
|
+
class HasChild < Arelastic::Filters::Filter
|
4
|
+
attr_reader :type, :query
|
5
|
+
|
6
|
+
def initialize type, query
|
7
|
+
@type = type
|
8
|
+
@query = query
|
9
|
+
end
|
10
|
+
|
11
|
+
def as_elastic
|
12
|
+
{
|
13
|
+
"has_child" => {
|
14
|
+
"type" => type,
|
15
|
+
"query" => convert_to_elastic(query)
|
16
|
+
}
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -8,7 +8,12 @@ module Arelastic
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def as_elastic
|
11
|
-
{
|
11
|
+
{
|
12
|
+
"filtered" => {
|
13
|
+
"query" => convert_to_elastic(query),
|
14
|
+
"filter" => convert_to_elastic(filter)
|
15
|
+
}
|
16
|
+
}
|
12
17
|
end
|
13
18
|
end
|
14
19
|
end
|
@@ -9,8 +9,8 @@ class Arelastic::Builders::QueryTest < MiniTest::Spec
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_filtered
|
12
|
-
query = Arelastic::Builders::Query.filtered({"
|
13
|
-
expected = {"query" => {"filtered" => {"query" => "foo", "filter" => "bar"}}}
|
12
|
+
query = Arelastic::Builders::Query.filtered({"query_string" => "foo"}, {"term" => "bar"})
|
13
|
+
expected = {"query" => {"filtered" => {"query" => {"query_string" => "foo"}, "filter" => {"term" => "bar"}}}}
|
14
14
|
|
15
15
|
assert_equal expected, query.as_elastic
|
16
16
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Arelastic::Filters::HasChildTest < MiniTest::Spec
|
4
|
+
def test_as_elastic
|
5
|
+
expected = {"has_child" => {"type" => "comment", "query" => {"query_string" => "lol"}}}
|
6
|
+
|
7
|
+
assert_equal expected, Arelastic::Filters::HasChild.new("comment", {"query_string" => "lol"}).as_elastic
|
8
|
+
end
|
9
|
+
end
|
@@ -2,8 +2,8 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class Arelastic::Queries::FilteredTest < MiniTest::Spec
|
4
4
|
def test_as_elastic
|
5
|
-
filtered = Arelastic::Queries::Filtered.new({"
|
6
|
-
expected = {"filtered" => {"query" => "bar", "filter" => "baz"}}
|
5
|
+
filtered = Arelastic::Queries::Filtered.new({"query_string" => "bar"}, {"term" => "baz"})
|
6
|
+
expected = {"filtered" => {"query" => {"query_string" => "bar"}, "filter" => {"term" => "baz"}}}
|
7
7
|
|
8
8
|
assert_equal expected, filtered.as_elastic
|
9
9
|
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.
|
4
|
+
version: 0.2.0
|
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-10-
|
12
|
+
date: 2012-10-16 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Build Elastic Search queries with objects
|
15
15
|
email: developer@matthewhiggins.com
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- lib/arelastic/filters/exists.rb
|
38
38
|
- lib/arelastic/filters/filter.rb
|
39
39
|
- lib/arelastic/filters/geo_distance.rb
|
40
|
+
- lib/arelastic/filters/has_child.rb
|
40
41
|
- lib/arelastic/filters/ids.rb
|
41
42
|
- lib/arelastic/filters/limit.rb
|
42
43
|
- lib/arelastic/filters/match_all.rb
|
@@ -85,6 +86,7 @@ files:
|
|
85
86
|
- test/arelastic/filters/exists_test.rb
|
86
87
|
- test/arelastic/filters/filter_test.rb
|
87
88
|
- test/arelastic/filters/geo_distance_test.rb
|
89
|
+
- test/arelastic/filters/has_child_test.rb
|
88
90
|
- test/arelastic/filters/ids_test.rb
|
89
91
|
- test/arelastic/filters/match_all_test.rb
|
90
92
|
- test/arelastic/filters/match_test.rb
|