elasticsearch-dsl 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +10 -19
- data/README.md +244 -15
- data/Rakefile +212 -0
- data/elasticsearch-dsl.gemspec +32 -15
- data/lib/elasticsearch-dsl.rb +1 -0
- data/lib/elasticsearch/dsl.rb +43 -3
- data/lib/elasticsearch/dsl/search.rb +241 -0
- data/lib/elasticsearch/dsl/search/aggregation.rb +79 -0
- data/lib/elasticsearch/dsl/search/aggregations/avg.rb +25 -0
- data/lib/elasticsearch/dsl/search/aggregations/cardinality.rb +32 -0
- data/lib/elasticsearch/dsl/search/aggregations/children.rb +39 -0
- data/lib/elasticsearch/dsl/search/aggregations/date_histogram.rb +40 -0
- data/lib/elasticsearch/dsl/search/aggregations/date_range.rb +34 -0
- data/lib/elasticsearch/dsl/search/aggregations/extended_stats.rb +25 -0
- data/lib/elasticsearch/dsl/search/aggregations/filter.rb +30 -0
- data/lib/elasticsearch/dsl/search/aggregations/filters.rb +35 -0
- data/lib/elasticsearch/dsl/search/aggregations/geo_bounds.rb +44 -0
- data/lib/elasticsearch/dsl/search/aggregations/geo_distance.rb +39 -0
- data/lib/elasticsearch/dsl/search/aggregations/geohash_grid.rb +35 -0
- data/lib/elasticsearch/dsl/search/aggregations/global.rb +25 -0
- data/lib/elasticsearch/dsl/search/aggregations/histogram.rb +35 -0
- data/lib/elasticsearch/dsl/search/aggregations/ip_range.rb +31 -0
- data/lib/elasticsearch/dsl/search/aggregations/max.rb +25 -0
- data/lib/elasticsearch/dsl/search/aggregations/min.rb +25 -0
- data/lib/elasticsearch/dsl/search/aggregations/nested.rb +34 -0
- data/lib/elasticsearch/dsl/search/aggregations/percentile_ranks.rb +34 -0
- data/lib/elasticsearch/dsl/search/aggregations/percentiles.rb +33 -0
- data/lib/elasticsearch/dsl/search/aggregations/range.rb +53 -0
- data/lib/elasticsearch/dsl/search/aggregations/reverse_nested.rb +37 -0
- data/lib/elasticsearch/dsl/search/aggregations/scripted_metric.rb +39 -0
- data/lib/elasticsearch/dsl/search/aggregations/significant_terms.rb +45 -0
- data/lib/elasticsearch/dsl/search/aggregations/stats.rb +25 -0
- data/lib/elasticsearch/dsl/search/aggregations/sum.rb +25 -0
- data/lib/elasticsearch/dsl/search/aggregations/terms.rb +33 -0
- data/lib/elasticsearch/dsl/search/aggregations/top_hits.rb +35 -0
- data/lib/elasticsearch/dsl/search/aggregations/value_count.rb +25 -0
- data/lib/elasticsearch/dsl/search/base_aggregation_component.rb +65 -0
- data/lib/elasticsearch/dsl/search/base_component.rb +162 -0
- data/lib/elasticsearch/dsl/search/base_compound_filter_component.rb +97 -0
- data/lib/elasticsearch/dsl/search/filter.rb +56 -0
- data/lib/elasticsearch/dsl/search/filters/and.rb +45 -0
- data/lib/elasticsearch/dsl/search/filters/bool.rb +80 -0
- data/lib/elasticsearch/dsl/search/filters/exists.rb +32 -0
- data/lib/elasticsearch/dsl/search/filters/geo_bounding_box.rb +45 -0
- data/lib/elasticsearch/dsl/search/filters/geo_distance.rb +57 -0
- data/lib/elasticsearch/dsl/search/filters/geo_distance_range.rb +32 -0
- data/lib/elasticsearch/dsl/search/filters/geo_polygon.rb +41 -0
- data/lib/elasticsearch/dsl/search/filters/geo_shape.rb +35 -0
- data/lib/elasticsearch/dsl/search/filters/geohash_cell.rb +46 -0
- data/lib/elasticsearch/dsl/search/filters/has_child.rb +73 -0
- data/lib/elasticsearch/dsl/search/filters/has_parent.rb +72 -0
- data/lib/elasticsearch/dsl/search/filters/ids.rb +32 -0
- data/lib/elasticsearch/dsl/search/filters/indices.rb +77 -0
- data/lib/elasticsearch/dsl/search/filters/limit.rb +31 -0
- data/lib/elasticsearch/dsl/search/filters/match_all.rb +29 -0
- data/lib/elasticsearch/dsl/search/filters/missing.rb +34 -0
- data/lib/elasticsearch/dsl/search/filters/nested.rb +58 -0
- data/lib/elasticsearch/dsl/search/filters/not.rb +73 -0
- data/lib/elasticsearch/dsl/search/filters/or.rb +45 -0
- data/lib/elasticsearch/dsl/search/filters/prefix.rb +29 -0
- data/lib/elasticsearch/dsl/search/filters/query.rb +54 -0
- data/lib/elasticsearch/dsl/search/filters/range.rb +39 -0
- data/lib/elasticsearch/dsl/search/filters/regexp.rb +34 -0
- data/lib/elasticsearch/dsl/search/filters/script.rb +32 -0
- data/lib/elasticsearch/dsl/search/filters/term.rb +32 -0
- data/lib/elasticsearch/dsl/search/filters/terms.rb +32 -0
- data/lib/elasticsearch/dsl/search/filters/type.rb +34 -0
- data/lib/elasticsearch/dsl/search/highlight.rb +92 -0
- data/lib/elasticsearch/dsl/search/options.rb +56 -0
- data/lib/elasticsearch/dsl/search/queries/bool.rb +75 -0
- data/lib/elasticsearch/dsl/search/queries/boosting.rb +33 -0
- data/lib/elasticsearch/dsl/search/queries/common.rb +38 -0
- data/lib/elasticsearch/dsl/search/queries/constant_score.rb +66 -0
- data/lib/elasticsearch/dsl/search/queries/dis_max.rb +35 -0
- data/lib/elasticsearch/dsl/search/queries/filtered.rb +77 -0
- data/lib/elasticsearch/dsl/search/queries/function_score.rb +102 -0
- data/lib/elasticsearch/dsl/search/queries/fuzzy.rb +45 -0
- data/lib/elasticsearch/dsl/search/queries/fuzzy_like_this.rb +37 -0
- data/lib/elasticsearch/dsl/search/queries/fuzzy_like_this_field.rb +36 -0
- data/lib/elasticsearch/dsl/search/queries/geo_shape.rb +31 -0
- data/lib/elasticsearch/dsl/search/queries/has_child.rb +57 -0
- data/lib/elasticsearch/dsl/search/queries/has_parent.rb +57 -0
- data/lib/elasticsearch/dsl/search/queries/ids.rb +28 -0
- data/lib/elasticsearch/dsl/search/queries/indices.rb +34 -0
- data/lib/elasticsearch/dsl/search/queries/match.rb +34 -0
- data/lib/elasticsearch/dsl/search/queries/match_all.rb +27 -0
- data/lib/elasticsearch/dsl/search/queries/more_like_this.rb +58 -0
- data/lib/elasticsearch/dsl/search/queries/multi_match.rb +35 -0
- data/lib/elasticsearch/dsl/search/queries/nested.rb +55 -0
- data/lib/elasticsearch/dsl/search/queries/prefix.rb +30 -0
- data/lib/elasticsearch/dsl/search/queries/query_string.rb +50 -0
- data/lib/elasticsearch/dsl/search/queries/range.rb +47 -0
- data/lib/elasticsearch/dsl/search/queries/regexp.rb +31 -0
- data/lib/elasticsearch/dsl/search/queries/simple_query_string.rb +38 -0
- data/lib/elasticsearch/dsl/search/queries/span_first.rb +28 -0
- data/lib/elasticsearch/dsl/search/queries/span_multi.rb +28 -0
- data/lib/elasticsearch/dsl/search/queries/span_near.rb +32 -0
- data/lib/elasticsearch/dsl/search/queries/span_not.rb +33 -0
- data/lib/elasticsearch/dsl/search/queries/span_or.rb +28 -0
- data/lib/elasticsearch/dsl/search/queries/span_term.rb +26 -0
- data/lib/elasticsearch/dsl/search/queries/template.rb +31 -0
- data/lib/elasticsearch/dsl/search/queries/term.rb +27 -0
- data/lib/elasticsearch/dsl/search/queries/terms.rb +27 -0
- data/lib/elasticsearch/dsl/search/queries/top_children.rb +58 -0
- data/lib/elasticsearch/dsl/search/queries/wildcard.rb +30 -0
- data/lib/elasticsearch/dsl/search/query.rb +55 -0
- data/lib/elasticsearch/dsl/search/sort.rb +50 -0
- data/lib/elasticsearch/dsl/search/suggest.rb +28 -0
- data/lib/elasticsearch/dsl/utils.rb +25 -0
- data/lib/elasticsearch/dsl/version.rb +2 -2
- data/test/integration/search_aggregation_children_test.rb +69 -0
- data/test/integration/search_aggregation_geo_test.rb +90 -0
- data/test/integration/search_aggregation_nested_test.rb +100 -0
- data/test/integration/search_aggregations_test.rb +232 -0
- data/test/integration/search_filters_test.rb +359 -0
- data/test/integration/search_options_test.rb +28 -0
- data/test/integration/search_query_test.rb +55 -0
- data/test/integration/search_size_from_test.rb +41 -0
- data/test/integration/search_sort_test.rb +36 -0
- data/test/integration/search_suggest_test.rb +62 -0
- data/test/test_helper.rb +62 -0
- data/test/unit/aggregations/avg_test.rb +24 -0
- data/test/unit/aggregations/cardinality_test.rb +40 -0
- data/test/unit/aggregations/children_test.rb +36 -0
- data/test/unit/aggregations/date_histogram_test.rb +49 -0
- data/test/unit/aggregations/date_range_test.rb +42 -0
- data/test/unit/aggregations/extended_stats_test.rb +24 -0
- data/test/unit/aggregations/filter_test.rb +31 -0
- data/test/unit/aggregations/filters_test.rb +52 -0
- data/test/unit/aggregations/geo_bounds_test.rb +37 -0
- data/test/unit/aggregations/geo_distance_test.rb +45 -0
- data/test/unit/aggregations/geohash_grid_test.rb +40 -0
- data/test/unit/aggregations/global_test.rb +20 -0
- data/test/unit/aggregations/histogram_test.rb +42 -0
- data/test/unit/aggregations/ip_range_test.rb +41 -0
- data/test/unit/aggregations/max_test.rb +24 -0
- data/test/unit/aggregations/min_test.rb +24 -0
- data/test/unit/aggregations/nested_test.rb +48 -0
- data/test/unit/aggregations/percentile_ranks_test.rb +41 -0
- data/test/unit/aggregations/percentiles_test.rb +40 -0
- data/test/unit/aggregations/range_test.rb +48 -0
- data/test/unit/aggregations/reverse_nested_test.rb +20 -0
- data/test/unit/aggregations/scripted_metric_test.rb +41 -0
- data/test/unit/aggregations/significant_terms_test.rb +46 -0
- data/test/unit/aggregations/stats_test.rb +24 -0
- data/test/unit/aggregations/sum_test.rb +24 -0
- data/test/unit/aggregations/terms_test.rb +51 -0
- data/test/unit/aggregations/top_hits_test.rb +38 -0
- data/test/unit/aggregations/value_count_test.rb +24 -0
- data/test/unit/dsl_test.rb +18 -0
- data/test/unit/filters/and_test.rb +69 -0
- data/test/unit/filters/bool_test.rb +98 -0
- data/test/unit/filters/exists_test.rb +36 -0
- data/test/unit/filters/geo_bounding_box_test.rb +45 -0
- data/test/unit/filters/geo_distance_range_test.rb +51 -0
- data/test/unit/filters/geo_distance_test.rb +58 -0
- data/test/unit/filters/geo_polygon_test.rb +36 -0
- data/test/unit/filters/geo_shape_test.rb +37 -0
- data/test/unit/filters/geohash_cell_test.rb +43 -0
- data/test/unit/filters/has_child_test.rb +52 -0
- data/test/unit/filters/has_parent_test.rb +52 -0
- data/test/unit/filters/ids_test.rb +38 -0
- data/test/unit/filters/indices_test.rb +52 -0
- data/test/unit/filters/limit_test.rb +36 -0
- data/test/unit/filters/match_all_test.rb +20 -0
- data/test/unit/filters/missing_test.rb +38 -0
- data/test/unit/filters/nested_test.rb +40 -0
- data/test/unit/filters/not_test.rb +35 -0
- data/test/unit/filters/or_test.rb +53 -0
- data/test/unit/filters/prefix_test.rb +25 -0
- data/test/unit/filters/query_test.rb +33 -0
- data/test/unit/filters/range_test.rb +47 -0
- data/test/unit/filters/regexp_test.rb +42 -0
- data/test/unit/filters/script_test.rb +38 -0
- data/test/unit/filters/term_test.rb +27 -0
- data/test/unit/filters/terms_test.rb +24 -0
- data/test/unit/filters/type_test.rb +36 -0
- data/test/unit/queries/bool_test.rb +107 -0
- data/test/unit/queries/boosting_test.rb +41 -0
- data/test/unit/queries/common_test.rb +42 -0
- data/test/unit/queries/constant_score_test.rb +47 -0
- data/test/unit/queries/dis_max_test.rb +38 -0
- data/test/unit/queries/filtered_test.rb +51 -0
- data/test/unit/queries/function_score_test.rb +70 -0
- data/test/unit/queries/fuzzy_like_this_field_test.rb +42 -0
- data/test/unit/queries/fuzzy_like_this_test.rb +44 -0
- data/test/unit/queries/fuzzy_test.rb +40 -0
- data/test/unit/queries/geo_shape_test.rb +37 -0
- data/test/unit/queries/has_child_test.rb +53 -0
- data/test/unit/queries/has_parent_test.rb +39 -0
- data/test/unit/queries/ids_test.rb +38 -0
- data/test/unit/queries/indices_test.rb +39 -0
- data/test/unit/queries/match_all_test.rb +36 -0
- data/test/unit/queries/match_test.rb +64 -0
- data/test/unit/queries/more_like_this_test.rb +53 -0
- data/test/unit/queries/multi_match_test.rb +42 -0
- data/test/unit/queries/nested_test.rb +50 -0
- data/test/unit/queries/prefix_test.rb +37 -0
- data/test/unit/queries/query_string_test.rb +55 -0
- data/test/unit/queries/range_test.rb +39 -0
- data/test/unit/queries/regexp_test.rb +43 -0
- data/test/unit/queries/simple_query_string_test.rb +43 -0
- data/test/unit/queries/span_first_test.rb +36 -0
- data/test/unit/queries/span_multi_test.rb +36 -0
- data/test/unit/queries/span_near_test.rb +39 -0
- data/test/unit/queries/span_not_test.rb +40 -0
- data/test/unit/queries/span_or_test.rb +36 -0
- data/test/unit/queries/span_term_test.rb +24 -0
- data/test/unit/queries/template_test.rb +43 -0
- data/test/unit/queries/term_test.rb +27 -0
- data/test/unit/queries/terms_test.rb +24 -0
- data/test/unit/queries/top_children_test.rb +53 -0
- data/test/unit/queries/wildcard_test.rb +43 -0
- data/test/unit/search_aggregation_test.rb +72 -0
- data/test/unit/search_base_aggregation_component_test.rb +41 -0
- data/test/unit/search_base_component_test.rb +176 -0
- data/test/unit/search_filter_test.rb +61 -0
- data/test/unit/search_highlight_test.rb +77 -0
- data/test/unit/search_options_test.rb +80 -0
- data/test/unit/search_query_test.rb +65 -0
- data/test/unit/search_size_from_test.rb +43 -0
- data/test/unit/search_sort_test.rb +40 -0
- data/test/unit/search_suggest_test.rb +20 -0
- data/test/unit/search_test.rb +201 -0
- data/test/unit/utils_test.rb +21 -0
- metadata +524 -25
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Test
|
5
|
+
module Filters
|
6
|
+
class RegexpTest < ::Test::Unit::TestCase
|
7
|
+
include Elasticsearch::DSL::Search::Filters
|
8
|
+
|
9
|
+
context "Regexp filter" do
|
10
|
+
subject { Regexp.new }
|
11
|
+
|
12
|
+
should "be converted to a Hash" do
|
13
|
+
assert_equal({ regexp: {} }, subject.to_hash)
|
14
|
+
end
|
15
|
+
|
16
|
+
should "have option methods" do
|
17
|
+
subject = Regexp.new :foo
|
18
|
+
|
19
|
+
subject.value 'bar'
|
20
|
+
subject.flags 'bar'
|
21
|
+
|
22
|
+
assert_equal %w[ flags value ],
|
23
|
+
subject.to_hash[:regexp][:foo].keys.map(&:to_s).sort
|
24
|
+
assert_equal 'bar', subject.to_hash[:regexp][:foo][:value]
|
25
|
+
end
|
26
|
+
|
27
|
+
should "take a Hash" do
|
28
|
+
subject = Regexp.new foo: 'b.*r'
|
29
|
+
assert_equal({regexp: { foo: 'b.*r' }}, subject.to_hash)
|
30
|
+
end
|
31
|
+
|
32
|
+
should "take a block" do
|
33
|
+
subject = Regexp.new :foo do
|
34
|
+
value 'b*r'
|
35
|
+
end
|
36
|
+
assert_equal({regexp: { foo: { value: 'b*r' } }}, subject.to_hash)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Test
|
5
|
+
module Filters
|
6
|
+
class ScriptTest < ::Test::Unit::TestCase
|
7
|
+
include Elasticsearch::DSL::Search::Filters
|
8
|
+
|
9
|
+
context "Script filter" do
|
10
|
+
subject { Script.new }
|
11
|
+
|
12
|
+
should "be converted to a Hash" do
|
13
|
+
assert_equal({ script: {} }, subject.to_hash)
|
14
|
+
end
|
15
|
+
|
16
|
+
should "have option methods" do
|
17
|
+
subject = Script.new :foo
|
18
|
+
|
19
|
+
subject.script 'bar'
|
20
|
+
subject.params foo: 'bar'
|
21
|
+
|
22
|
+
assert_equal %w[ params script ],
|
23
|
+
subject.to_hash[:script][:foo].keys.map(&:to_s).sort
|
24
|
+
assert_equal 'bar', subject.to_hash[:script][:foo][:script]
|
25
|
+
assert_equal 'bar', subject.to_hash[:script][:foo][:params][:foo]
|
26
|
+
end
|
27
|
+
|
28
|
+
should "take a block" do
|
29
|
+
subject = Script.new :foo do
|
30
|
+
script 'bar'
|
31
|
+
end
|
32
|
+
assert_equal({script: { foo: { script: 'bar' } }}, subject.to_hash)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Test
|
5
|
+
module Filters
|
6
|
+
class TermTest < ::Test::Unit::TestCase
|
7
|
+
include Elasticsearch::DSL::Search::Filters
|
8
|
+
|
9
|
+
subject { Term.new message: 'test' }
|
10
|
+
|
11
|
+
context "Term Filter" do
|
12
|
+
should "take a concrete value" do
|
13
|
+
@subject = Term.new message: 'test'
|
14
|
+
|
15
|
+
assert_equal({ term: { message: 'test' } }, @subject.to_hash)
|
16
|
+
end
|
17
|
+
|
18
|
+
should "take a Hash" do
|
19
|
+
@subject = Term.new message: { query: 'test', boost: 2 }
|
20
|
+
|
21
|
+
assert_equal({ term: { message: { query: 'test', boost: 2 }}}, @subject.to_hash)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Test
|
5
|
+
module Filters
|
6
|
+
class TermsTest < ::Test::Unit::TestCase
|
7
|
+
include Elasticsearch::DSL::Search::Filters
|
8
|
+
|
9
|
+
context "Terms filter" do
|
10
|
+
subject { Terms.new }
|
11
|
+
|
12
|
+
should "be converted to a Hash" do
|
13
|
+
assert_equal({ terms: {} }, subject.to_hash)
|
14
|
+
end
|
15
|
+
|
16
|
+
should "be take a Hash" do
|
17
|
+
subject = Terms.new foo: ['abc', 'xyz']
|
18
|
+
assert_equal({ terms: { foo: ['abc', 'xyz'] } }, subject.to_hash)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Test
|
5
|
+
module Filters
|
6
|
+
class TypeTest < ::Test::Unit::TestCase
|
7
|
+
include Elasticsearch::DSL::Search::Filters
|
8
|
+
|
9
|
+
context "Type filter" do
|
10
|
+
subject { Type.new }
|
11
|
+
|
12
|
+
should "be converted to a Hash" do
|
13
|
+
assert_equal({ type: {} }, subject.to_hash)
|
14
|
+
end
|
15
|
+
|
16
|
+
should "have option methods" do
|
17
|
+
subject = Type.new :foo
|
18
|
+
|
19
|
+
subject.value 'bar'
|
20
|
+
|
21
|
+
assert_equal %w[ value ],
|
22
|
+
subject.to_hash[:type][:foo].keys.map(&:to_s).sort
|
23
|
+
assert_equal 'bar', subject.to_hash[:type][:foo][:value]
|
24
|
+
end
|
25
|
+
|
26
|
+
should "take a block" do
|
27
|
+
subject = Type.new :foo do
|
28
|
+
value 'bar'
|
29
|
+
end
|
30
|
+
assert_equal({type: { foo: { value: 'bar' } }}, subject.to_hash)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Test
|
5
|
+
module Queries
|
6
|
+
class BoolTest < ::Test::Unit::TestCase
|
7
|
+
include Elasticsearch::DSL::Search::Queries
|
8
|
+
|
9
|
+
context "Bool Query" do
|
10
|
+
subject { Bool.new }
|
11
|
+
|
12
|
+
should "be converted to a Hash" do
|
13
|
+
assert_equal({ bool: {} }, subject.to_hash)
|
14
|
+
end
|
15
|
+
|
16
|
+
should "take a Hash" do
|
17
|
+
subject = Bool.new must: [ {match: { foo: 'bar' }} ]
|
18
|
+
|
19
|
+
assert_equal( { bool: { must: [ {match: { foo: 'bar' }} ] } }, subject.to_hash )
|
20
|
+
end
|
21
|
+
|
22
|
+
should "take a block" do
|
23
|
+
subject = Bool.new do
|
24
|
+
must { match foo: 'bar' }
|
25
|
+
end
|
26
|
+
|
27
|
+
assert_equal( { bool: {must: [ {match: { foo: 'bar' }} ] } }, subject.to_hash )
|
28
|
+
end
|
29
|
+
|
30
|
+
should "take a block with multiple methods" do
|
31
|
+
subject = Bool.new do
|
32
|
+
must { match foo: 'bar' }
|
33
|
+
must_not { match moo: 'bam' }
|
34
|
+
should { match xoo: 'bax' }
|
35
|
+
end
|
36
|
+
|
37
|
+
assert_equal( { bool:
|
38
|
+
{ must: [ {match: { foo: 'bar' }} ],
|
39
|
+
must_not: [ {match: { moo: 'bam' }} ],
|
40
|
+
should: [ {match: { xoo: 'bax' }} ]
|
41
|
+
}
|
42
|
+
},
|
43
|
+
subject.to_hash )
|
44
|
+
end
|
45
|
+
|
46
|
+
should "take a block with multiple conditions" do
|
47
|
+
subject = Bool.new do
|
48
|
+
must do
|
49
|
+
match foo: 'bar'
|
50
|
+
end
|
51
|
+
|
52
|
+
must do
|
53
|
+
match moo: 'bam'
|
54
|
+
end
|
55
|
+
|
56
|
+
should do
|
57
|
+
match xoo: 'bax'
|
58
|
+
end
|
59
|
+
|
60
|
+
should do
|
61
|
+
match zoo: 'baz'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Make sure we're not additive
|
66
|
+
subject.to_hash
|
67
|
+
subject.to_hash
|
68
|
+
|
69
|
+
assert_equal( { bool:
|
70
|
+
{ must: [ {match: { foo: 'bar' }}, {match: { moo: 'bam' }} ],
|
71
|
+
should: [ {match: { xoo: 'bax' }}, {match: { zoo: 'baz' }} ]
|
72
|
+
}
|
73
|
+
},
|
74
|
+
subject.to_hash )
|
75
|
+
end
|
76
|
+
|
77
|
+
should "take method calls" do
|
78
|
+
subject = Bool.new
|
79
|
+
|
80
|
+
subject.must { match foo: 'bar' }
|
81
|
+
assert_equal( { bool: { must: [ {match: { foo: 'bar' }} ] } }, subject.to_hash )
|
82
|
+
|
83
|
+
subject.must { match moo: 'bam' }
|
84
|
+
assert_equal( { bool: { must: [ {match: { foo: 'bar' }}, {match: { moo: 'bam' }} ]} },
|
85
|
+
subject.to_hash )
|
86
|
+
|
87
|
+
subject.should { match xoo: 'bax' }
|
88
|
+
assert_equal( { bool:
|
89
|
+
{ must: [ {match: { foo: 'bar' }}, {match: { moo: 'bam' }} ],
|
90
|
+
should: [ {match: { xoo: 'bax' }} ] }
|
91
|
+
},
|
92
|
+
subject.to_hash )
|
93
|
+
end
|
94
|
+
|
95
|
+
should "be chainable" do
|
96
|
+
subject = Bool.new
|
97
|
+
|
98
|
+
assert_instance_of Bool, subject.must { match foo: 'bar' }
|
99
|
+
assert_instance_of Bool, subject.must { match foo: 'bar' }.must { match moo: 'bam' }
|
100
|
+
assert_instance_of Bool, subject.must_not { match foo: 'bar' }
|
101
|
+
assert_instance_of Bool, subject.should { match foo: 'bar' }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Test
|
5
|
+
module Queries
|
6
|
+
class BoostingTest < ::Test::Unit::TestCase
|
7
|
+
include Elasticsearch::DSL::Search::Queries
|
8
|
+
|
9
|
+
context "Boosting query" do
|
10
|
+
subject { Boosting.new }
|
11
|
+
|
12
|
+
should "be converted to a Hash" do
|
13
|
+
assert_equal({ boosting: {} }, subject.to_hash)
|
14
|
+
end
|
15
|
+
|
16
|
+
should "have option methods" do
|
17
|
+
subject = Boosting.new
|
18
|
+
|
19
|
+
subject.positive 'bar'
|
20
|
+
subject.negative 'bar'
|
21
|
+
subject.negative_boost 'bar'
|
22
|
+
|
23
|
+
assert_equal %w[ negative negative_boost positive ],
|
24
|
+
subject.to_hash[:boosting].keys.map(&:to_s).sort
|
25
|
+
assert_equal 'bar', subject.to_hash[:boosting][:positive]
|
26
|
+
end
|
27
|
+
|
28
|
+
should "take a block" do
|
29
|
+
subject = Boosting.new do
|
30
|
+
positive foo: 'bar'
|
31
|
+
negative moo: 'xoo'
|
32
|
+
end
|
33
|
+
|
34
|
+
assert_equal 'bar', subject.to_hash[:boosting][:positive][:foo]
|
35
|
+
assert_equal 'xoo', subject.to_hash[:boosting][:negative][:moo]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Test
|
5
|
+
module Queries
|
6
|
+
class CommonTest < ::Test::Unit::TestCase
|
7
|
+
include Elasticsearch::DSL::Search::Queries
|
8
|
+
|
9
|
+
context "Common query" do
|
10
|
+
subject { Common.new }
|
11
|
+
|
12
|
+
should "be converted to a Hash" do
|
13
|
+
assert_equal({ common: {} }, subject.to_hash)
|
14
|
+
end
|
15
|
+
|
16
|
+
should "have option methods" do
|
17
|
+
subject = Common.new :foo
|
18
|
+
|
19
|
+
subject.query 'bar'
|
20
|
+
subject.cutoff_frequency 'bar'
|
21
|
+
subject.low_freq_operator 'bar'
|
22
|
+
subject.minimum_should_match 'bar'
|
23
|
+
subject.boost 'bar'
|
24
|
+
subject.analyzer 'bar'
|
25
|
+
subject.disable_coord 'bar'
|
26
|
+
|
27
|
+
assert_equal %w[ analyzer boost cutoff_frequency disable_coord low_freq_operator minimum_should_match query ],
|
28
|
+
subject.to_hash[:common][:foo].keys.map(&:to_s).sort
|
29
|
+
assert_equal 'bar', subject.to_hash[:common][:foo][:query]
|
30
|
+
end
|
31
|
+
|
32
|
+
should "take a block" do
|
33
|
+
subject = Common.new :foo do
|
34
|
+
query 'bar'
|
35
|
+
end
|
36
|
+
assert_equal 'bar', subject.to_hash[:common][:foo][:query]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Test
|
5
|
+
module Queries
|
6
|
+
class ConstantScoreTest < ::Test::Unit::TestCase
|
7
|
+
include Elasticsearch::DSL::Search::Queries
|
8
|
+
|
9
|
+
context "ConstantScore query" do
|
10
|
+
subject { ConstantScore.new }
|
11
|
+
|
12
|
+
should "be converted to a Hash" do
|
13
|
+
assert_equal({ constant_score: {} }, subject.to_hash)
|
14
|
+
end
|
15
|
+
|
16
|
+
should "have option methods" do
|
17
|
+
subject = ConstantScore.new
|
18
|
+
|
19
|
+
subject.query 'bar'
|
20
|
+
subject.filter 'bar'
|
21
|
+
subject.boost 'bar'
|
22
|
+
|
23
|
+
assert_equal %w[ boost filter query ],
|
24
|
+
subject.to_hash[:constant_score].keys.map(&:to_s).sort
|
25
|
+
assert_equal 'bar', subject.to_hash[:constant_score][:query]
|
26
|
+
end
|
27
|
+
|
28
|
+
should "take a block" do
|
29
|
+
subject = ConstantScore.new do
|
30
|
+
query term: { foo: 'bar' }
|
31
|
+
end
|
32
|
+
assert_equal 'bar', subject.to_hash[:constant_score][:query][:term][:foo]
|
33
|
+
end
|
34
|
+
|
35
|
+
should "evaluate a block passed to the option method" do
|
36
|
+
subject = ConstantScore.new do
|
37
|
+
query do
|
38
|
+
term foo: 'bar'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
assert_equal 'bar', subject.to_hash[:constant_score][:query][:term][:foo]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Test
|
5
|
+
module Queries
|
6
|
+
class DisMaxTest < ::Test::Unit::TestCase
|
7
|
+
include Elasticsearch::DSL::Search::Queries
|
8
|
+
|
9
|
+
context "DisMax query" do
|
10
|
+
subject { DisMax.new }
|
11
|
+
|
12
|
+
should "be converted to a Hash" do
|
13
|
+
assert_equal({ dis_max: {} }, subject.to_hash)
|
14
|
+
end
|
15
|
+
|
16
|
+
should "have option methods" do
|
17
|
+
subject = DisMax.new
|
18
|
+
|
19
|
+
subject.tie_breaker 'bar'
|
20
|
+
subject.boost 'bar'
|
21
|
+
subject.queries 'bar'
|
22
|
+
|
23
|
+
assert_equal %w[ boost queries tie_breaker ],
|
24
|
+
subject.to_hash[:dis_max].keys.map(&:to_s).sort
|
25
|
+
assert_equal 'bar', subject.to_hash[:dis_max][:tie_breaker]
|
26
|
+
end
|
27
|
+
|
28
|
+
should "take a block" do
|
29
|
+
subject = DisMax.new do
|
30
|
+
tie_breaker 'bar'
|
31
|
+
end
|
32
|
+
assert_equal 'bar', subject.to_hash[:dis_max][:tie_breaker]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|