eson-dsl 0.7.0
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.
- data/LICENSE.md +20 -0
- data/README.md +179 -0
- data/Rakefile +30 -0
- data/TODO.md +1 -0
- data/eson-dsl.gemspec +21 -0
- data/examples/facets/date_histogram.rb +5 -0
- data/examples/facets/filter.rb +7 -0
- data/examples/facets/geo_distance.rb +14 -0
- data/examples/facets/histogram.rb +5 -0
- data/examples/facets/query.rb +7 -0
- data/examples/facets/range.rb +8 -0
- data/examples/facets/scoped.rb +17 -0
- data/examples/facets/statistical.rb +5 -0
- data/examples/facets/term_stats.rb +9 -0
- data/examples/facets/terms.rb +8 -0
- data/examples/filters/and.rb +11 -0
- data/examples/filters/and_without_keyword.rb +9 -0
- data/examples/filters/bool.rb +16 -0
- data/examples/filters/exists.rb +9 -0
- data/examples/filters/fquery.rb +11 -0
- data/examples/filters/geo_bounding_box.rb +8 -0
- data/examples/filters/geo_distance.rb +8 -0
- data/examples/filters/geo_distance_alternate.rb +9 -0
- data/examples/filters/geo_distance_range.rb +10 -0
- data/examples/filters/geo_polygon.rb +10 -0
- data/examples/filters/has_child.rb +9 -0
- data/examples/filters/ids.rb +8 -0
- data/examples/filters/missing.rb +9 -0
- data/examples/filters/not.rb +10 -0
- data/examples/filters/numeric_range.rb +9 -0
- data/examples/filters/or.rb +11 -0
- data/examples/filters/range.rb +5 -0
- data/examples/filters/type.rb +5 -0
- data/examples/queries/bool.rb +16 -0
- data/examples/queries/boosting.rb +12 -0
- data/examples/queries/constant_score.rb +9 -0
- data/examples/queries/constant_score_with_filter.rb +9 -0
- data/examples/queries/custom_score.rb +15 -0
- data/examples/queries/dis_max.rb +10 -0
- data/examples/queries/field.rb +5 -0
- data/examples/queries/filters_and_facets.rb +11 -0
- data/examples/queries/flt.rb +7 -0
- data/examples/queries/flt_field.rb +7 -0
- data/examples/queries/fuzzy.rb +5 -0
- data/examples/queries/fuzzy_complex.rb +5 -0
- data/examples/queries/has_child.rb +9 -0
- data/examples/queries/has_child_complex.rb +12 -0
- data/examples/queries/ids.rb +5 -0
- data/examples/queries/match_all.rb +5 -0
- data/examples/queries/mlt.rb +7 -0
- data/examples/queries/mlt_field.rb +7 -0
- data/examples/queries/nested.rb +12 -0
- data/examples/queries/prefix.rb +5 -0
- data/examples/queries/prefix_short.rb +5 -0
- data/examples/queries/query_string.rb +6 -0
- data/examples/queries/query_string_with_multiple_fields.rb +7 -0
- data/examples/queries/query_string_without_default_field.rb +5 -0
- data/examples/queries/range.rb +5 -0
- data/examples/queries/span_first.rb +7 -0
- data/examples/queries/span_near.rb +11 -0
- data/examples/queries/span_not.rb +8 -0
- data/examples/queries/span_or.rb +11 -0
- data/examples/queries/span_term.rb +5 -0
- data/examples/queries/term.rb +5 -0
- data/examples/queries/term_with_parameters.rb +5 -0
- data/examples/queries/terms.rb +5 -0
- data/examples/queries/text.rb +5 -0
- data/examples/queries/top_children.rb +7 -0
- data/examples/queries/wildcard.rb +5 -0
- data/examples/queries/wildcard_short.rb +5 -0
- data/lib/eson/modules/query_plugin.rb +44 -0
- data/lib/eson/search/and.rb +27 -0
- data/lib/eson/search/base_query.rb +39 -0
- data/lib/eson/search/bool.rb +51 -0
- data/lib/eson/search/boosting.rb +45 -0
- data/lib/eson/search/constant_score.rb +21 -0
- data/lib/eson/search/custom_score.rb +19 -0
- data/lib/eson/search/date_histogram.rb +13 -0
- data/lib/eson/search/dis_max.rb +22 -0
- data/lib/eson/search/exists.rb +18 -0
- data/lib/eson/search/facet.rb +39 -0
- data/lib/eson/search/facets.rb +37 -0
- data/lib/eson/search/field.rb +16 -0
- data/lib/eson/search/field_based.rb +24 -0
- data/lib/eson/search/filter.rb +28 -0
- data/lib/eson/search/filter_facet.rb +13 -0
- data/lib/eson/search/filters.rb +69 -0
- data/lib/eson/search/fquery.rb +22 -0
- data/lib/eson/search/fuzzy.rb +29 -0
- data/lib/eson/search/fuzzy_like_this.rb +16 -0
- data/lib/eson/search/fuzzy_like_this_field.rb +20 -0
- data/lib/eson/search/geo_bounding_box.rb +35 -0
- data/lib/eson/search/geo_distance.rb +34 -0
- data/lib/eson/search/geo_distance_range.rb +29 -0
- data/lib/eson/search/geo_polygon.rb +32 -0
- data/lib/eson/search/has_child.rb +29 -0
- data/lib/eson/search/histogram.rb +20 -0
- data/lib/eson/search/ids.rb +27 -0
- data/lib/eson/search/match_all.rb +21 -0
- data/lib/eson/search/missing.rb +21 -0
- data/lib/eson/search/more_like_this.rb +16 -0
- data/lib/eson/search/more_like_this_field.rb +20 -0
- data/lib/eson/search/nested.rb +24 -0
- data/lib/eson/search/node.rb +28 -0
- data/lib/eson/search/not.rb +23 -0
- data/lib/eson/search/numeric_range.rb +20 -0
- data/lib/eson/search/or.rb +23 -0
- data/lib/eson/search/parametrized.rb +15 -0
- data/lib/eson/search/prefix.rb +22 -0
- data/lib/eson/search/queries.rb +65 -0
- data/lib/eson/search/query.rb +28 -0
- data/lib/eson/search/query_facet.rb +16 -0
- data/lib/eson/search/query_field.rb +33 -0
- data/lib/eson/search/query_group.rb +34 -0
- data/lib/eson/search/query_string.rb +20 -0
- data/lib/eson/search/range.rb +26 -0
- data/lib/eson/search/span_first.rb +27 -0
- data/lib/eson/search/span_near.rb +29 -0
- data/lib/eson/search/span_not.rb +29 -0
- data/lib/eson/search/span_or.rb +29 -0
- data/lib/eson/search/span_term.rb +18 -0
- data/lib/eson/search/statistical.rb +20 -0
- data/lib/eson/search/sub_query.rb +7 -0
- data/lib/eson/search/term.rb +22 -0
- data/lib/eson/search/terms.rb +22 -0
- data/lib/eson/search/terms_stats.rb +20 -0
- data/lib/eson/search/text.rb +23 -0
- data/lib/eson/search/top_children.rb +28 -0
- data/lib/eson/search/type.rb +20 -0
- data/lib/eson/search/wildcard.rb +18 -0
- data/lib/eson-dsl.rb +64 -0
- data/log4j.properties +18 -0
- data/test/search/facet_test.rb +92 -0
- data/test/search/facets/date_histogram.documents +1 -0
- data/test/search/facets/date_histogram.mapping +1 -0
- data/test/search/facets/date_histogram.rb +13 -0
- data/test/search/facets/geo_distance.documents +1 -0
- data/test/search/facets/geo_distance.mapping +8 -0
- data/test/search/facets/geo_distance.rb +1 -0
- data/test/search/facets/histogram.documents +1 -0
- data/test/search/facets/histogram.rb +13 -0
- data/test/search/facets/query.documents +1 -0
- data/test/search/facets/query.rb +14 -0
- data/test/search/facets/range.documents +1 -0
- data/test/search/facets/range.rb +17 -0
- data/test/search/facets/scoped.documents +1 -0
- data/test/search/facets/scoped.json +1 -0
- data/test/search/facets/scoped.mapping +9 -0
- data/test/search/facets/statistical.documents +1 -0
- data/test/search/facets/statistical.rb +12 -0
- data/test/search/facets/tag_facet.documents +1 -0
- data/test/search/facets/tag_facet.rb +14 -0
- data/test/search/facets/terms.rb +14 -0
- data/test/search/facets/terms_stats.documents +1 -0
- data/test/search/facets/terms_stats.json +1 -0
- data/test/search/facets/terms_stats.rb +13 -0
- data/test/search/filters/and.rb +15 -0
- data/test/search/filters/bool.json +1 -0
- data/test/search/filters/bool.rb +27 -0
- data/test/search/filters/exists.json +1 -0
- data/test/search/filters/exists.rb +1 -0
- data/test/search/filters/filter_query.rb +14 -0
- data/test/search/filters/geo_bounding_box_hash.documents +1 -0
- data/test/search/filters/geo_bounding_box_hash.json +1 -0
- data/test/search/filters/geo_bounding_box_hash.mapping +8 -0
- data/test/search/filters/geo_distance_hash.documents +1 -0
- data/test/search/filters/geo_distance_hash.json +1 -0
- data/test/search/filters/geo_distance_hash.mapping +8 -0
- data/test/search/filters/geo_distance_range_hash.documents +1 -0
- data/test/search/filters/geo_distance_range_hash.json +1 -0
- data/test/search/filters/geo_distance_range_hash.mapping +8 -0
- data/test/search/filters/geo_polygon_hash.documents +1 -0
- data/test/search/filters/geo_polygon_hash.json +1 -0
- data/test/search/filters/geo_polygon_hash.mapping +8 -0
- data/test/search/filters/has_child.blog.mapping +1 -0
- data/test/search/filters/has_child.blog_tag.mapping +1 -0
- data/test/search/filters/has_child.rb +15 -0
- data/test/search/filters/ids.rb +14 -0
- data/test/search/filters/missing.rb +1 -0
- data/test/search/filters/not.rb +16 -0
- data/test/search/filters/numeric_range.documents +1 -0
- data/test/search/filters/numeric_range.rb +1 -0
- data/test/search/filters/or.rb +15 -0
- data/test/search/filters/range.rb +16 -0
- data/test/search/filters/type.json +1 -0
- data/test/search/filters/type.rb +1 -0
- data/test/search/filters_test.rb +166 -0
- data/test/search/queries/bool.json +1 -0
- data/test/search/queries/bool.rb +21 -0
- data/test/search/queries/boosting.json +1 -0
- data/test/search/queries/boosting.rb +17 -0
- data/test/search/queries/constant_score.rb +10 -0
- data/test/search/queries/constant_score_filter.rb +10 -0
- data/test/search/queries/custom_score.documents +1 -0
- data/test/search/queries/custom_score.rb +14 -0
- data/test/search/queries/dis_max.rb +15 -0
- data/test/search/queries/field.rb +7 -0
- data/test/search/queries/filters_and_facets.documents +1 -0
- data/test/search/queries/filters_and_facets.json +1 -0
- data/test/search/queries/flt.rb +9 -0
- data/test/search/queries/flt_field.rb +10 -0
- data/test/search/queries/fuzzy_complex.rb +5 -0
- data/test/search/queries/fuzzy_simple.rb +5 -0
- data/test/search/queries/has_child.blog.mapping +1 -0
- data/test/search/queries/has_child.blog_tag.mapping +1 -0
- data/test/search/queries/has_child.rb +10 -0
- data/test/search/queries/has_child_complex.blog.mapping +1 -0
- data/test/search/queries/has_child_complex.blog_tag.mapping +1 -0
- data/test/search/queries/has_child_complex.rb +17 -0
- data/test/search/queries/ids.rb +1 -0
- data/test/search/queries/match_all.rb +1 -0
- data/test/search/queries/mlt.json +1 -0
- data/test/search/queries/mlt.rb +9 -0
- data/test/search/queries/mlt_field.rb +10 -0
- data/test/search/queries/nested.json +1 -0
- data/test/search/queries/nested.mapping +9 -0
- data/test/search/queries/phrase_prefix.rb +8 -0
- data/test/search/queries/prefix.rb +1 -0
- data/test/search/queries/prefix_short.rb +1 -0
- data/test/search/queries/query_string.rb +8 -0
- data/test/search/queries/query_string_with_multiple_fields.rb +9 -0
- data/test/search/queries/query_string_without_default_field.rb +7 -0
- data/test/search/queries/range.rb +11 -0
- data/test/search/queries/span_near.json +1 -0
- data/test/search/queries/span_not.json +1 -0
- data/test/search/queries/span_or.json +1 -0
- data/test/search/queries/span_term.json +1 -0
- data/test/search/queries/term.json +1 -0
- data/test/search/queries/term.rb +1 -0
- data/test/search/queries/terms.rb +1 -0
- data/test/search/queries/text.json +1 -0
- data/test/search/queries/text.rb +8 -0
- data/test/search/queries/top_children.blog.mapping +1 -0
- data/test/search/queries/top_children.blog_tag.mapping +1 -0
- data/test/search/queries/top_children.rb +11 -0
- data/test/search/queries/wildcard.rb +1 -0
- data/test/search/queries/wildcard_short.rb +1 -0
- data/test/search/query_test.rb +311 -0
- data/test/test_config.rb +157 -0
- metadata +413 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
module Eson
|
|
2
|
+
module Search
|
|
3
|
+
module Queries
|
|
4
|
+
module QueryMethods
|
|
5
|
+
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
class QueriesArray < Array
|
|
9
|
+
include QueryMethods
|
|
10
|
+
include Parametrized
|
|
11
|
+
|
|
12
|
+
def queries
|
|
13
|
+
self
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def initialize(args)
|
|
17
|
+
self.args = args
|
|
18
|
+
instance_exec(self, &Proc.new) if block_given?
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def to_query_hash
|
|
22
|
+
if length == 1
|
|
23
|
+
first.to_query_hash
|
|
24
|
+
else
|
|
25
|
+
map(&:to_query_hash)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
attr_accessor :queries
|
|
31
|
+
|
|
32
|
+
def self.register(name, klass)
|
|
33
|
+
QueryMethods.__send__(:define_method, name) do |*args, &block|
|
|
34
|
+
o = klass.new(*args)
|
|
35
|
+
o.context = :query
|
|
36
|
+
o.args = self.args
|
|
37
|
+
o.instance_exec(o, &block) if block
|
|
38
|
+
queries << o
|
|
39
|
+
o
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def queries(&block)
|
|
44
|
+
@queries ||= QueriesArray.new(args, &block)
|
|
45
|
+
end
|
|
46
|
+
alias :query :queries
|
|
47
|
+
|
|
48
|
+
def queries?
|
|
49
|
+
@queries && !(@queries.empty?)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def to_query_hash
|
|
53
|
+
others = super if defined?(super)
|
|
54
|
+
|
|
55
|
+
if queries?
|
|
56
|
+
{ :query => queries.to_query_hash }.tap do |h|
|
|
57
|
+
h.merge!(others) if others
|
|
58
|
+
end
|
|
59
|
+
else
|
|
60
|
+
others
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Eson
|
|
2
|
+
module Search
|
|
3
|
+
module Query
|
|
4
|
+
module ClassMethods
|
|
5
|
+
def short_name(name)
|
|
6
|
+
define_method :name do
|
|
7
|
+
name
|
|
8
|
+
end
|
|
9
|
+
Queries.register name, self
|
|
10
|
+
|
|
11
|
+
super if defined? super
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.included(base)
|
|
16
|
+
base.class_eval do
|
|
17
|
+
extend ClassMethods
|
|
18
|
+
include Node unless base.kind_of? Node
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def method_missing(name, arg)
|
|
23
|
+
warn("#{name} called as a query option")
|
|
24
|
+
self.options[name] = arg
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'ostruct'
|
|
2
|
+
|
|
3
|
+
module Eson
|
|
4
|
+
module Search
|
|
5
|
+
class QueryField < OpenStruct
|
|
6
|
+
def initialize(name, *fields)
|
|
7
|
+
@_name = name
|
|
8
|
+
|
|
9
|
+
if fields.length == 1 && Hash === fields.first
|
|
10
|
+
super(fields.first)
|
|
11
|
+
else
|
|
12
|
+
@list = fields
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def to_query_hash
|
|
17
|
+
if @list
|
|
18
|
+
{ _name => @list }
|
|
19
|
+
else
|
|
20
|
+
{ _name => @table }
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def _name
|
|
25
|
+
@_name
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def _options
|
|
29
|
+
@_table
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Eson
|
|
2
|
+
module Search
|
|
3
|
+
module QueryGroup
|
|
4
|
+
include Filters
|
|
5
|
+
include Queries
|
|
6
|
+
include Parametrized
|
|
7
|
+
|
|
8
|
+
def to_query_hash
|
|
9
|
+
if queries && filters && queries.any? && filters.any?
|
|
10
|
+
hash = {
|
|
11
|
+
:filtered => {
|
|
12
|
+
:query => queries.to_query_hash,
|
|
13
|
+
:filter => filters.to_query_hash
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
else
|
|
17
|
+
if filters && filters.any?
|
|
18
|
+
hash = filters.to_query_hash
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
if queries && queries.any?
|
|
22
|
+
hash = queries.to_query_hash
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
hash
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def to_hash
|
|
30
|
+
to_query_hash
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Eson
|
|
2
|
+
module Search
|
|
3
|
+
class QueryString
|
|
4
|
+
include Query
|
|
5
|
+
|
|
6
|
+
# @macro eson.query
|
|
7
|
+
short_name :query_string
|
|
8
|
+
|
|
9
|
+
attr_accessor :options
|
|
10
|
+
|
|
11
|
+
def initialize(options = {})
|
|
12
|
+
if Hash === options
|
|
13
|
+
self.options = options
|
|
14
|
+
else
|
|
15
|
+
self.options = {:query => options.to_s }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Eson
|
|
2
|
+
module Search
|
|
3
|
+
class Range
|
|
4
|
+
include Query
|
|
5
|
+
include Filter
|
|
6
|
+
include Facet
|
|
7
|
+
|
|
8
|
+
# @macro range
|
|
9
|
+
# Generates a `$1` filter, facet or query, depending on context.
|
|
10
|
+
# {include:file:eson-dsl/examples/filters/$1.rb}
|
|
11
|
+
# {include:file:eson-dsl/examples/facet/$1.rb}
|
|
12
|
+
# {include:file:eson-dsl/examples/queries/$1.rb}
|
|
13
|
+
short_name :range
|
|
14
|
+
|
|
15
|
+
attr_accessor :field
|
|
16
|
+
|
|
17
|
+
def initialize(field, *options)
|
|
18
|
+
self.field = QueryField.new(field, *options)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def to_query_hash
|
|
22
|
+
{name => field.to_query_hash}
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Eson
|
|
2
|
+
module Search
|
|
3
|
+
class SpanFirst
|
|
4
|
+
include Query
|
|
5
|
+
include Queries
|
|
6
|
+
include QueryMethods
|
|
7
|
+
|
|
8
|
+
# @macro eson.query
|
|
9
|
+
short_name :span_first
|
|
10
|
+
|
|
11
|
+
attr_accessor :options
|
|
12
|
+
|
|
13
|
+
def initialize(options = {})
|
|
14
|
+
self.options = options
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def to_query_hash
|
|
18
|
+
result = {}
|
|
19
|
+
|
|
20
|
+
result[:match] = queries.to_query_hash
|
|
21
|
+
|
|
22
|
+
{name => result.merge(options)}
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Eson
|
|
2
|
+
module Search
|
|
3
|
+
class SpanNear
|
|
4
|
+
include Query
|
|
5
|
+
|
|
6
|
+
# @macro eson.query
|
|
7
|
+
short_name :span_near
|
|
8
|
+
|
|
9
|
+
attr_accessor :options
|
|
10
|
+
|
|
11
|
+
def initialize(options = {})
|
|
12
|
+
self.options = options
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def clauses(&block)
|
|
16
|
+
@clauses ||= SubQuery.new(args)
|
|
17
|
+
@clauses.send(context, &block)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def to_query_hash
|
|
21
|
+
result = {}
|
|
22
|
+
|
|
23
|
+
result[:clauses] = @clauses.to_query_hash
|
|
24
|
+
|
|
25
|
+
{name => result.merge(options)}
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Eson
|
|
2
|
+
module Search
|
|
3
|
+
class SpanNot
|
|
4
|
+
include Query
|
|
5
|
+
|
|
6
|
+
# @macro eson.query
|
|
7
|
+
short_name :span_not
|
|
8
|
+
|
|
9
|
+
def include(&block)
|
|
10
|
+
@include ||= SubQuery.new(args)
|
|
11
|
+
@include.send(context, &block)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def exclude(&block)
|
|
15
|
+
@exclude ||= SubQuery.new(args)
|
|
16
|
+
@exclude.send(context, &block)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def to_query_hash
|
|
20
|
+
result = {}
|
|
21
|
+
|
|
22
|
+
result[:include] = @include.to_query_hash
|
|
23
|
+
result[:exclude] = @exclude.to_query_hash
|
|
24
|
+
|
|
25
|
+
{name => result}
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Eson
|
|
2
|
+
module Search
|
|
3
|
+
class SpanOr
|
|
4
|
+
include Query
|
|
5
|
+
|
|
6
|
+
# @macro eson.query
|
|
7
|
+
short_name :span_or
|
|
8
|
+
|
|
9
|
+
attr_accessor :options
|
|
10
|
+
|
|
11
|
+
def initialize(options = {})
|
|
12
|
+
self.options = options
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def clauses(&block)
|
|
16
|
+
@clauses ||= SubQuery.new(args)
|
|
17
|
+
@clauses.send(context, &block)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def to_query_hash
|
|
21
|
+
result = {}
|
|
22
|
+
|
|
23
|
+
result[:clauses] = @clauses.to_query_hash
|
|
24
|
+
|
|
25
|
+
{name => result.merge(options)}
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Eson
|
|
2
|
+
module Search
|
|
3
|
+
class SpanTerm < FieldBased
|
|
4
|
+
include Query
|
|
5
|
+
|
|
6
|
+
# @macro eson.query
|
|
7
|
+
short_name :span_term
|
|
8
|
+
|
|
9
|
+
def to_query_hash
|
|
10
|
+
if field
|
|
11
|
+
{name => field.to_query_hash}
|
|
12
|
+
else
|
|
13
|
+
{name => options}
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Eson
|
|
2
|
+
module Search
|
|
3
|
+
class Statistical
|
|
4
|
+
include Facet
|
|
5
|
+
|
|
6
|
+
# @macro eson.facet
|
|
7
|
+
short_name :statistical
|
|
8
|
+
|
|
9
|
+
attr_accessor :options
|
|
10
|
+
|
|
11
|
+
def initialize(options)
|
|
12
|
+
self.options = options
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def to_query_hash
|
|
16
|
+
{name => options}
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Eson
|
|
2
|
+
module Search
|
|
3
|
+
class Term < FieldBased
|
|
4
|
+
include Query
|
|
5
|
+
include Filter
|
|
6
|
+
|
|
7
|
+
# @macro term
|
|
8
|
+
# Generates a `$1` filter, query, depending on context.
|
|
9
|
+
# {include:file:eson-dsl/examples/filters/$1.rb}
|
|
10
|
+
# {include:file:eson-dsl/examples/queries/$1.rb}
|
|
11
|
+
short_name :term
|
|
12
|
+
|
|
13
|
+
def to_query_hash
|
|
14
|
+
if field
|
|
15
|
+
{name => field.to_query_hash}
|
|
16
|
+
else
|
|
17
|
+
{name => options}
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Eson
|
|
2
|
+
module Search
|
|
3
|
+
class Terms
|
|
4
|
+
include Query
|
|
5
|
+
include Filter
|
|
6
|
+
include Facet
|
|
7
|
+
|
|
8
|
+
# @macro terms
|
|
9
|
+
# Generates a `$1` filter, facet or query, depending on context.
|
|
10
|
+
# {include:file:eson-dsl/examples/filters/$1.rb}
|
|
11
|
+
# {include:file:eson-dsl/examples/facet/$1.rb}
|
|
12
|
+
# {include:file:eson-dsl/examples/queries/$1.rb}
|
|
13
|
+
short_name :terms
|
|
14
|
+
|
|
15
|
+
attr_accessor :options, :field
|
|
16
|
+
|
|
17
|
+
def initialize(options = {})
|
|
18
|
+
self.options = options
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Eson
|
|
2
|
+
module Search
|
|
3
|
+
class TermsStats
|
|
4
|
+
include Facet
|
|
5
|
+
|
|
6
|
+
# @macro eson.facet
|
|
7
|
+
short_name :terms_stats
|
|
8
|
+
|
|
9
|
+
attr_accessor :options
|
|
10
|
+
|
|
11
|
+
def initialize(options)
|
|
12
|
+
self.options = options
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def to_query_hash
|
|
16
|
+
{name => options}
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Eson
|
|
2
|
+
module Search
|
|
3
|
+
class Text
|
|
4
|
+
#TODO: implement alternative forms like:
|
|
5
|
+
# {
|
|
6
|
+
# "text_phrase" : {
|
|
7
|
+
# "message" : "this is a test"
|
|
8
|
+
# }
|
|
9
|
+
#}
|
|
10
|
+
include Query
|
|
11
|
+
|
|
12
|
+
# @macro eson.query
|
|
13
|
+
short_name :text
|
|
14
|
+
|
|
15
|
+
attr_accessor :options
|
|
16
|
+
|
|
17
|
+
def initialize(options = {})
|
|
18
|
+
self.options = options
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Eson
|
|
2
|
+
module Search
|
|
3
|
+
class TopChildren
|
|
4
|
+
include Query
|
|
5
|
+
include Filter
|
|
6
|
+
include QueryGroup
|
|
7
|
+
|
|
8
|
+
# @macro top_children
|
|
9
|
+
# Generates a `$1` filter, query, depending on context.
|
|
10
|
+
# {include:file:eson-dsl/examples/filters/$1.rb}
|
|
11
|
+
# {include:file:eson-dsl/examples/queries/$1.rb}# @macro eson.query
|
|
12
|
+
short_name :top_children
|
|
13
|
+
|
|
14
|
+
attr_accessor :options
|
|
15
|
+
|
|
16
|
+
def initialize(type, options = {})
|
|
17
|
+
self.options = options.merge(:type => type)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def to_query_hash
|
|
21
|
+
{
|
|
22
|
+
name => {:query => super}.merge(options)
|
|
23
|
+
}
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Eson
|
|
2
|
+
module Search
|
|
3
|
+
class Type
|
|
4
|
+
include Filter
|
|
5
|
+
|
|
6
|
+
# @macro eson.filter
|
|
7
|
+
short_name :type
|
|
8
|
+
|
|
9
|
+
attr_accessor :type
|
|
10
|
+
|
|
11
|
+
def initialize(type)
|
|
12
|
+
self.type = type
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def to_query_hash
|
|
16
|
+
{:type => {:value => type}}
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Eson
|
|
2
|
+
module Search
|
|
3
|
+
class Wildcard < FieldBased
|
|
4
|
+
include Query
|
|
5
|
+
|
|
6
|
+
# @macro eson.query
|
|
7
|
+
short_name :wildcard
|
|
8
|
+
|
|
9
|
+
def to_query_hash
|
|
10
|
+
if field
|
|
11
|
+
{name => field.to_query_hash}
|
|
12
|
+
else
|
|
13
|
+
{name => options}
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
data/lib/eson-dsl.rb
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
require 'multi_json'
|
|
2
|
+
|
|
3
|
+
require 'eson/modules/query_plugin'
|
|
4
|
+
|
|
5
|
+
require 'eson/search/parametrized'
|
|
6
|
+
require 'eson/search/node'
|
|
7
|
+
require 'eson/search/query'
|
|
8
|
+
require 'eson/search/queries'
|
|
9
|
+
require 'eson/search/filter'
|
|
10
|
+
require 'eson/search/filters'
|
|
11
|
+
require 'eson/search/facet'
|
|
12
|
+
require 'eson/search/facets'
|
|
13
|
+
require 'eson/search/query_group'
|
|
14
|
+
require 'eson/search/field_based'
|
|
15
|
+
|
|
16
|
+
require 'eson/search/base_query'
|
|
17
|
+
require 'eson/search/sub_query'
|
|
18
|
+
require 'eson/search/bool'
|
|
19
|
+
require 'eson/search/query_field'
|
|
20
|
+
require 'eson/search/term'
|
|
21
|
+
require 'eson/search/wildcard'
|
|
22
|
+
require 'eson/search/terms'
|
|
23
|
+
require 'eson/search/ids'
|
|
24
|
+
require 'eson/search/match_all'
|
|
25
|
+
require 'eson/search/range'
|
|
26
|
+
require 'eson/search/constant_score'
|
|
27
|
+
require 'eson/search/custom_score'
|
|
28
|
+
require 'eson/search/text'
|
|
29
|
+
require 'eson/search/boosting'
|
|
30
|
+
require 'eson/search/dis_max'
|
|
31
|
+
require 'eson/search/field'
|
|
32
|
+
require 'eson/search/fuzzy_like_this'
|
|
33
|
+
require 'eson/search/fuzzy_like_this_field'
|
|
34
|
+
require 'eson/search/more_like_this'
|
|
35
|
+
require 'eson/search/more_like_this_field'
|
|
36
|
+
require 'eson/search/fuzzy'
|
|
37
|
+
require 'eson/search/has_child'
|
|
38
|
+
require 'eson/search/top_children'
|
|
39
|
+
require 'eson/search/prefix'
|
|
40
|
+
require 'eson/search/query_string'
|
|
41
|
+
require 'eson/search/and'
|
|
42
|
+
require 'eson/search/or'
|
|
43
|
+
require 'eson/search/not'
|
|
44
|
+
require 'eson/search/numeric_range'
|
|
45
|
+
require 'eson/search/missing'
|
|
46
|
+
require 'eson/search/exists'
|
|
47
|
+
require 'eson/search/type'
|
|
48
|
+
require 'eson/search/fquery'
|
|
49
|
+
require 'eson/search/histogram'
|
|
50
|
+
require 'eson/search/date_histogram'
|
|
51
|
+
require 'eson/search/query_facet'
|
|
52
|
+
require 'eson/search/filter_facet'
|
|
53
|
+
require 'eson/search/statistical'
|
|
54
|
+
require 'eson/search/terms_stats'
|
|
55
|
+
require 'eson/search/nested'
|
|
56
|
+
require 'eson/search/span_term'
|
|
57
|
+
require 'eson/search/span_or'
|
|
58
|
+
require 'eson/search/span_near'
|
|
59
|
+
require 'eson/search/span_not'
|
|
60
|
+
require 'eson/search/span_first'
|
|
61
|
+
require 'eson/search/geo_bounding_box'
|
|
62
|
+
require 'eson/search/geo_distance'
|
|
63
|
+
require 'eson/search/geo_distance_range'
|
|
64
|
+
require 'eson/search/geo_polygon'
|
data/log4j.properties
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
log4j.rootLogger=INFO, out
|
|
2
|
+
log4j.logger.jgroups=WARN
|
|
3
|
+
|
|
4
|
+
#log4j.logger.discovery=TRACE
|
|
5
|
+
#log4j.logger.cluster=TRACE
|
|
6
|
+
#log4j.logger.indices.cluster=DEBUG
|
|
7
|
+
#log4j.logger.index=TRACE
|
|
8
|
+
#log4j.logger.index.engine=DEBUG
|
|
9
|
+
#log4j.logger.index.shard=TRACE
|
|
10
|
+
#log4j.logger.index.cache=DEBUG
|
|
11
|
+
#log4j.logger.http=TRACE
|
|
12
|
+
#log4j.logger.monitor.jvm=DEBUG
|
|
13
|
+
#log4j.logger.cluster.action.shard=TRACE
|
|
14
|
+
#log4j.logger.index.gateway=TRACE
|
|
15
|
+
|
|
16
|
+
log4j.appender.out=org.apache.log4j.ConsoleAppender
|
|
17
|
+
log4j.appender.out.layout=org.apache.log4j.PatternLayout
|
|
18
|
+
log4j.appender.out.layout.ConversionPattern=[%d{ABSOLUTE}][%-5p][%-25c] %m%n
|