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,28 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
module Filter
|
4
|
+
module ClassMethods
|
5
|
+
def short_name(name)
|
6
|
+
define_method :name do
|
7
|
+
name
|
8
|
+
end
|
9
|
+
Filters.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 filter option")
|
24
|
+
self.options[name] = arg
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
module Filters
|
4
|
+
module FilterMethods
|
5
|
+
|
6
|
+
end
|
7
|
+
|
8
|
+
class FilterArray < Array
|
9
|
+
include FilterMethods
|
10
|
+
include Parametrized
|
11
|
+
|
12
|
+
def filters
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def define_filters
|
17
|
+
instance_exec(self, &Proc.new) if block_given?
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_query_hash
|
21
|
+
if length == 1
|
22
|
+
first.to_query_hash
|
23
|
+
else
|
24
|
+
map(&:to_query_hash)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
attr_accessor :filters
|
30
|
+
|
31
|
+
def filters
|
32
|
+
@filters ||= FilterArray.new(args)
|
33
|
+
|
34
|
+
if block_given?
|
35
|
+
@filters.define_filters(&Proc.new)
|
36
|
+
end
|
37
|
+
|
38
|
+
@filters
|
39
|
+
end
|
40
|
+
alias :filter :filters
|
41
|
+
|
42
|
+
def filters?
|
43
|
+
@filters && !(@filters.empty?)
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.register(name, klass)
|
47
|
+
FilterMethods.__send__(:define_method, name) do |*args, &block|
|
48
|
+
o = klass.new(*args)
|
49
|
+
o.context = :filter
|
50
|
+
o.args = self.args
|
51
|
+
o.instance_exec(o, &block) if block
|
52
|
+
filters << o
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_query_hash
|
57
|
+
others = super if defined?(super)
|
58
|
+
|
59
|
+
if filters?
|
60
|
+
{ :filter => filters.to_query_hash }.tap do |h|
|
61
|
+
h.merge!(others) if others
|
62
|
+
end
|
63
|
+
else
|
64
|
+
others
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
class FQuery
|
4
|
+
include Filter
|
5
|
+
include Queries
|
6
|
+
include QueryMethods
|
7
|
+
|
8
|
+
# @macro eson.filter
|
9
|
+
short_name :fquery
|
10
|
+
|
11
|
+
attr_accessor :options
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
self.options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_query_hash
|
18
|
+
{name => {:query => queries.to_query_hash}.merge!(options)}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
class Fuzzy
|
4
|
+
include Query
|
5
|
+
|
6
|
+
# @macro eson.query
|
7
|
+
short_name :fuzzy
|
8
|
+
|
9
|
+
attr_accessor :field
|
10
|
+
attr_accessor :options
|
11
|
+
|
12
|
+
def initialize(*args)
|
13
|
+
if args.length == 1
|
14
|
+
self.options = args.first
|
15
|
+
else
|
16
|
+
self.field = QueryField.new(*args)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_query_hash
|
21
|
+
if field
|
22
|
+
{name => field.to_query_hash}
|
23
|
+
else
|
24
|
+
{name => options}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
class FuzzyLikeThisField
|
4
|
+
include Query
|
5
|
+
|
6
|
+
# @macro eson.query
|
7
|
+
short_name :flt_field
|
8
|
+
|
9
|
+
attr_accessor :field
|
10
|
+
|
11
|
+
def initialize(field, options = {})
|
12
|
+
self.field = QueryField.new(field, options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_query_hash
|
16
|
+
{name => field.to_query_hash}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
class GeoBoundingBox
|
4
|
+
include Filter
|
5
|
+
|
6
|
+
# @macro eson.filter
|
7
|
+
short_name :geo_bounding_box
|
8
|
+
|
9
|
+
attr_accessor :field, :options
|
10
|
+
|
11
|
+
def initialize(field, options = {})
|
12
|
+
self.field = field
|
13
|
+
self.options = options
|
14
|
+
end
|
15
|
+
|
16
|
+
def top_left(location, *args)
|
17
|
+
unless args.empty?
|
18
|
+
location + args
|
19
|
+
end
|
20
|
+
options[:top_left] = location
|
21
|
+
end
|
22
|
+
|
23
|
+
def bottom_right(location, *args)
|
24
|
+
unless args.empty?
|
25
|
+
location + args
|
26
|
+
end
|
27
|
+
options[:bottom_right] = location
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_query_hash
|
31
|
+
{ name => {field => options } }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
class GeoDistance
|
4
|
+
include Filter
|
5
|
+
include Facet
|
6
|
+
|
7
|
+
# @macro geo_distance
|
8
|
+
# @yield a block defining options
|
9
|
+
# Generates a `$1` filter or facet, depending on context.
|
10
|
+
# {include:file:eson-dsl/examples/filters/$1.rb}
|
11
|
+
# {include:file:eson-dsl/examples/facets/$1.rb}
|
12
|
+
short_name :geo_distance
|
13
|
+
|
14
|
+
attr_accessor :field, :options
|
15
|
+
|
16
|
+
def initialize(field, options = {})
|
17
|
+
self.field = field
|
18
|
+
self.options = options
|
19
|
+
end
|
20
|
+
|
21
|
+
def lat(lat)
|
22
|
+
@lat = lat
|
23
|
+
end
|
24
|
+
|
25
|
+
def lon(lon)
|
26
|
+
@lon = lon
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_query_hash
|
30
|
+
{ name => options.merge({ field => {:lat => @lat, :lon => @lon } }) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
class GeoDistanceRange
|
4
|
+
include Filter
|
5
|
+
|
6
|
+
# @macro eson.filter
|
7
|
+
short_name :geo_distance_range
|
8
|
+
|
9
|
+
attr_accessor :field, :options
|
10
|
+
|
11
|
+
def initialize(field, options = {})
|
12
|
+
self.field = field
|
13
|
+
self.options = options
|
14
|
+
end
|
15
|
+
|
16
|
+
def lat(lat)
|
17
|
+
@lat = lat
|
18
|
+
end
|
19
|
+
|
20
|
+
def lon(lon)
|
21
|
+
@lon = lon
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_query_hash
|
25
|
+
{ name => options.merge({ field => {:lat => @lat, :lon => @lon } }) }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
class GeoPolygon
|
4
|
+
include Filter
|
5
|
+
|
6
|
+
# @macro eson.filter
|
7
|
+
short_name :geo_polygon
|
8
|
+
attr_accessor :field, :options
|
9
|
+
|
10
|
+
def initialize(field, options = {})
|
11
|
+
self.field = field
|
12
|
+
self.options = options
|
13
|
+
end
|
14
|
+
|
15
|
+
def points(points = nil)
|
16
|
+
if points
|
17
|
+
@points = points
|
18
|
+
else
|
19
|
+
@points ||= []
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def point(point)
|
24
|
+
points << point
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_query_hash
|
28
|
+
{ name => options.merge({ field => {:points => points} }) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
class HasChild
|
4
|
+
include Query
|
5
|
+
include Filter
|
6
|
+
|
7
|
+
include QueryGroup
|
8
|
+
|
9
|
+
# @macro has_child
|
10
|
+
# Generates a `$1` filter or query, depending on context.
|
11
|
+
# {include:file:eson-dsl/examples/filters/$1.rb}
|
12
|
+
# {include:file:eson-dsl/examples/queries/$1.rb}
|
13
|
+
short_name :has_child
|
14
|
+
|
15
|
+
attr_accessor :options
|
16
|
+
|
17
|
+
def initialize(type, options = {})
|
18
|
+
self.options = options.merge(:type => type)
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_query_hash
|
22
|
+
{
|
23
|
+
name => options.merge(:query => super)
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
class Histogram
|
4
|
+
include Facet
|
5
|
+
|
6
|
+
# @macro eson.facet
|
7
|
+
short_name :histogram
|
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,27 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
class Ids
|
4
|
+
include Filter
|
5
|
+
include Query
|
6
|
+
|
7
|
+
# @macro ids
|
8
|
+
# Generates a `$1` filter or 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 :ids
|
12
|
+
|
13
|
+
attr_accessor :options
|
14
|
+
|
15
|
+
def initialize(*args)
|
16
|
+
if args.length == 2
|
17
|
+
self.options = {
|
18
|
+
:type => args.first,
|
19
|
+
:values => args.last
|
20
|
+
}
|
21
|
+
else
|
22
|
+
self.options = args.first
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
class MatchAll
|
4
|
+
include Query
|
5
|
+
|
6
|
+
# @macro eson.query
|
7
|
+
short_name :match_all
|
8
|
+
|
9
|
+
attr_accessor :boost
|
10
|
+
|
11
|
+
def initialize(params = {})
|
12
|
+
self.boost = params.delete(:boost)
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_query_hash
|
16
|
+
param = boost ? {:boost => self.boost} : {}
|
17
|
+
{:match_all => param }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
class Missing
|
4
|
+
include Filter
|
5
|
+
|
6
|
+
# @macro eson.filter
|
7
|
+
short_name :missing
|
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
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
class MoreLikeThisField
|
4
|
+
include Query
|
5
|
+
|
6
|
+
# @macro eson.query
|
7
|
+
short_name :mlt_field
|
8
|
+
|
9
|
+
attr_accessor :field
|
10
|
+
|
11
|
+
def initialize(field, options = {})
|
12
|
+
self.field = QueryField.new(field, options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_query_hash
|
16
|
+
{name => field.to_query_hash}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
class Nested
|
4
|
+
include Query
|
5
|
+
include QueryGroup
|
6
|
+
|
7
|
+
# @macro eson.query
|
8
|
+
short_name :nested
|
9
|
+
|
10
|
+
attr_accessor :options
|
11
|
+
|
12
|
+
def initialize(options = {})
|
13
|
+
self.options = options
|
14
|
+
instance_exec(self, &Proc.new) if block_given?
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_query_hash
|
18
|
+
{
|
19
|
+
name => {:query => super}.merge(options)
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
module Node
|
4
|
+
attr_accessor :context
|
5
|
+
attr_accessor :args
|
6
|
+
attr_accessor :options
|
7
|
+
|
8
|
+
def param(name)
|
9
|
+
args[name] || (raise "Parameter #{name} not given")
|
10
|
+
end
|
11
|
+
|
12
|
+
def options
|
13
|
+
@options ||= {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_query_hash
|
17
|
+
values = options
|
18
|
+
|
19
|
+
if defined?(super)
|
20
|
+
values = values.merge(super)
|
21
|
+
end
|
22
|
+
|
23
|
+
{ name => values }
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
class Not
|
4
|
+
include Filters
|
5
|
+
include FilterMethods
|
6
|
+
include Filter
|
7
|
+
|
8
|
+
# @macro eson.filter
|
9
|
+
short_name 'not' # yard chokes on :not
|
10
|
+
|
11
|
+
attr_accessor :options
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
self.options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_query_hash
|
18
|
+
{ name => { :filter => filters.to_query_hash } }
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
class NumericRange
|
4
|
+
include Filter
|
5
|
+
|
6
|
+
# @macro eson.filter
|
7
|
+
short_name :numeric_range
|
8
|
+
|
9
|
+
attr_accessor :field
|
10
|
+
|
11
|
+
def initialize(field, options = {})
|
12
|
+
self.field = QueryField.new(field, options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_query_hash
|
16
|
+
{name => field.to_query_hash}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
class Or
|
4
|
+
include Filters
|
5
|
+
include FilterMethods
|
6
|
+
include Filter
|
7
|
+
|
8
|
+
# @macro eson.filter
|
9
|
+
short_name 'or' # yard chokes on :or
|
10
|
+
|
11
|
+
attr_accessor :options
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
self.options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_query_hash
|
18
|
+
{ name => filters.to_query_hash }
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
class Prefix < FieldBased
|
4
|
+
include Query
|
5
|
+
include Filter
|
6
|
+
|
7
|
+
# @macro prefix
|
8
|
+
# Generates a `$1` filter or 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 :prefix
|
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
|