eson-dsl 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (240) hide show
  1. data/LICENSE.md +20 -0
  2. data/README.md +179 -0
  3. data/Rakefile +30 -0
  4. data/TODO.md +1 -0
  5. data/eson-dsl.gemspec +21 -0
  6. data/examples/facets/date_histogram.rb +5 -0
  7. data/examples/facets/filter.rb +7 -0
  8. data/examples/facets/geo_distance.rb +14 -0
  9. data/examples/facets/histogram.rb +5 -0
  10. data/examples/facets/query.rb +7 -0
  11. data/examples/facets/range.rb +8 -0
  12. data/examples/facets/scoped.rb +17 -0
  13. data/examples/facets/statistical.rb +5 -0
  14. data/examples/facets/term_stats.rb +9 -0
  15. data/examples/facets/terms.rb +8 -0
  16. data/examples/filters/and.rb +11 -0
  17. data/examples/filters/and_without_keyword.rb +9 -0
  18. data/examples/filters/bool.rb +16 -0
  19. data/examples/filters/exists.rb +9 -0
  20. data/examples/filters/fquery.rb +11 -0
  21. data/examples/filters/geo_bounding_box.rb +8 -0
  22. data/examples/filters/geo_distance.rb +8 -0
  23. data/examples/filters/geo_distance_alternate.rb +9 -0
  24. data/examples/filters/geo_distance_range.rb +10 -0
  25. data/examples/filters/geo_polygon.rb +10 -0
  26. data/examples/filters/has_child.rb +9 -0
  27. data/examples/filters/ids.rb +8 -0
  28. data/examples/filters/missing.rb +9 -0
  29. data/examples/filters/not.rb +10 -0
  30. data/examples/filters/numeric_range.rb +9 -0
  31. data/examples/filters/or.rb +11 -0
  32. data/examples/filters/range.rb +5 -0
  33. data/examples/filters/type.rb +5 -0
  34. data/examples/queries/bool.rb +16 -0
  35. data/examples/queries/boosting.rb +12 -0
  36. data/examples/queries/constant_score.rb +9 -0
  37. data/examples/queries/constant_score_with_filter.rb +9 -0
  38. data/examples/queries/custom_score.rb +15 -0
  39. data/examples/queries/dis_max.rb +10 -0
  40. data/examples/queries/field.rb +5 -0
  41. data/examples/queries/filters_and_facets.rb +11 -0
  42. data/examples/queries/flt.rb +7 -0
  43. data/examples/queries/flt_field.rb +7 -0
  44. data/examples/queries/fuzzy.rb +5 -0
  45. data/examples/queries/fuzzy_complex.rb +5 -0
  46. data/examples/queries/has_child.rb +9 -0
  47. data/examples/queries/has_child_complex.rb +12 -0
  48. data/examples/queries/ids.rb +5 -0
  49. data/examples/queries/match_all.rb +5 -0
  50. data/examples/queries/mlt.rb +7 -0
  51. data/examples/queries/mlt_field.rb +7 -0
  52. data/examples/queries/nested.rb +12 -0
  53. data/examples/queries/prefix.rb +5 -0
  54. data/examples/queries/prefix_short.rb +5 -0
  55. data/examples/queries/query_string.rb +6 -0
  56. data/examples/queries/query_string_with_multiple_fields.rb +7 -0
  57. data/examples/queries/query_string_without_default_field.rb +5 -0
  58. data/examples/queries/range.rb +5 -0
  59. data/examples/queries/span_first.rb +7 -0
  60. data/examples/queries/span_near.rb +11 -0
  61. data/examples/queries/span_not.rb +8 -0
  62. data/examples/queries/span_or.rb +11 -0
  63. data/examples/queries/span_term.rb +5 -0
  64. data/examples/queries/term.rb +5 -0
  65. data/examples/queries/term_with_parameters.rb +5 -0
  66. data/examples/queries/terms.rb +5 -0
  67. data/examples/queries/text.rb +5 -0
  68. data/examples/queries/top_children.rb +7 -0
  69. data/examples/queries/wildcard.rb +5 -0
  70. data/examples/queries/wildcard_short.rb +5 -0
  71. data/lib/eson/modules/query_plugin.rb +44 -0
  72. data/lib/eson/search/and.rb +27 -0
  73. data/lib/eson/search/base_query.rb +39 -0
  74. data/lib/eson/search/bool.rb +51 -0
  75. data/lib/eson/search/boosting.rb +45 -0
  76. data/lib/eson/search/constant_score.rb +21 -0
  77. data/lib/eson/search/custom_score.rb +19 -0
  78. data/lib/eson/search/date_histogram.rb +13 -0
  79. data/lib/eson/search/dis_max.rb +22 -0
  80. data/lib/eson/search/exists.rb +18 -0
  81. data/lib/eson/search/facet.rb +39 -0
  82. data/lib/eson/search/facets.rb +37 -0
  83. data/lib/eson/search/field.rb +16 -0
  84. data/lib/eson/search/field_based.rb +24 -0
  85. data/lib/eson/search/filter.rb +28 -0
  86. data/lib/eson/search/filter_facet.rb +13 -0
  87. data/lib/eson/search/filters.rb +69 -0
  88. data/lib/eson/search/fquery.rb +22 -0
  89. data/lib/eson/search/fuzzy.rb +29 -0
  90. data/lib/eson/search/fuzzy_like_this.rb +16 -0
  91. data/lib/eson/search/fuzzy_like_this_field.rb +20 -0
  92. data/lib/eson/search/geo_bounding_box.rb +35 -0
  93. data/lib/eson/search/geo_distance.rb +34 -0
  94. data/lib/eson/search/geo_distance_range.rb +29 -0
  95. data/lib/eson/search/geo_polygon.rb +32 -0
  96. data/lib/eson/search/has_child.rb +29 -0
  97. data/lib/eson/search/histogram.rb +20 -0
  98. data/lib/eson/search/ids.rb +27 -0
  99. data/lib/eson/search/match_all.rb +21 -0
  100. data/lib/eson/search/missing.rb +21 -0
  101. data/lib/eson/search/more_like_this.rb +16 -0
  102. data/lib/eson/search/more_like_this_field.rb +20 -0
  103. data/lib/eson/search/nested.rb +24 -0
  104. data/lib/eson/search/node.rb +28 -0
  105. data/lib/eson/search/not.rb +23 -0
  106. data/lib/eson/search/numeric_range.rb +20 -0
  107. data/lib/eson/search/or.rb +23 -0
  108. data/lib/eson/search/parametrized.rb +15 -0
  109. data/lib/eson/search/prefix.rb +22 -0
  110. data/lib/eson/search/queries.rb +65 -0
  111. data/lib/eson/search/query.rb +28 -0
  112. data/lib/eson/search/query_facet.rb +16 -0
  113. data/lib/eson/search/query_field.rb +33 -0
  114. data/lib/eson/search/query_group.rb +34 -0
  115. data/lib/eson/search/query_string.rb +20 -0
  116. data/lib/eson/search/range.rb +26 -0
  117. data/lib/eson/search/span_first.rb +27 -0
  118. data/lib/eson/search/span_near.rb +29 -0
  119. data/lib/eson/search/span_not.rb +29 -0
  120. data/lib/eson/search/span_or.rb +29 -0
  121. data/lib/eson/search/span_term.rb +18 -0
  122. data/lib/eson/search/statistical.rb +20 -0
  123. data/lib/eson/search/sub_query.rb +7 -0
  124. data/lib/eson/search/term.rb +22 -0
  125. data/lib/eson/search/terms.rb +22 -0
  126. data/lib/eson/search/terms_stats.rb +20 -0
  127. data/lib/eson/search/text.rb +23 -0
  128. data/lib/eson/search/top_children.rb +28 -0
  129. data/lib/eson/search/type.rb +20 -0
  130. data/lib/eson/search/wildcard.rb +18 -0
  131. data/lib/eson-dsl.rb +64 -0
  132. data/log4j.properties +18 -0
  133. data/test/search/facet_test.rb +92 -0
  134. data/test/search/facets/date_histogram.documents +1 -0
  135. data/test/search/facets/date_histogram.mapping +1 -0
  136. data/test/search/facets/date_histogram.rb +13 -0
  137. data/test/search/facets/geo_distance.documents +1 -0
  138. data/test/search/facets/geo_distance.mapping +8 -0
  139. data/test/search/facets/geo_distance.rb +1 -0
  140. data/test/search/facets/histogram.documents +1 -0
  141. data/test/search/facets/histogram.rb +13 -0
  142. data/test/search/facets/query.documents +1 -0
  143. data/test/search/facets/query.rb +14 -0
  144. data/test/search/facets/range.documents +1 -0
  145. data/test/search/facets/range.rb +17 -0
  146. data/test/search/facets/scoped.documents +1 -0
  147. data/test/search/facets/scoped.json +1 -0
  148. data/test/search/facets/scoped.mapping +9 -0
  149. data/test/search/facets/statistical.documents +1 -0
  150. data/test/search/facets/statistical.rb +12 -0
  151. data/test/search/facets/tag_facet.documents +1 -0
  152. data/test/search/facets/tag_facet.rb +14 -0
  153. data/test/search/facets/terms.rb +14 -0
  154. data/test/search/facets/terms_stats.documents +1 -0
  155. data/test/search/facets/terms_stats.json +1 -0
  156. data/test/search/facets/terms_stats.rb +13 -0
  157. data/test/search/filters/and.rb +15 -0
  158. data/test/search/filters/bool.json +1 -0
  159. data/test/search/filters/bool.rb +27 -0
  160. data/test/search/filters/exists.json +1 -0
  161. data/test/search/filters/exists.rb +1 -0
  162. data/test/search/filters/filter_query.rb +14 -0
  163. data/test/search/filters/geo_bounding_box_hash.documents +1 -0
  164. data/test/search/filters/geo_bounding_box_hash.json +1 -0
  165. data/test/search/filters/geo_bounding_box_hash.mapping +8 -0
  166. data/test/search/filters/geo_distance_hash.documents +1 -0
  167. data/test/search/filters/geo_distance_hash.json +1 -0
  168. data/test/search/filters/geo_distance_hash.mapping +8 -0
  169. data/test/search/filters/geo_distance_range_hash.documents +1 -0
  170. data/test/search/filters/geo_distance_range_hash.json +1 -0
  171. data/test/search/filters/geo_distance_range_hash.mapping +8 -0
  172. data/test/search/filters/geo_polygon_hash.documents +1 -0
  173. data/test/search/filters/geo_polygon_hash.json +1 -0
  174. data/test/search/filters/geo_polygon_hash.mapping +8 -0
  175. data/test/search/filters/has_child.blog.mapping +1 -0
  176. data/test/search/filters/has_child.blog_tag.mapping +1 -0
  177. data/test/search/filters/has_child.rb +15 -0
  178. data/test/search/filters/ids.rb +14 -0
  179. data/test/search/filters/missing.rb +1 -0
  180. data/test/search/filters/not.rb +16 -0
  181. data/test/search/filters/numeric_range.documents +1 -0
  182. data/test/search/filters/numeric_range.rb +1 -0
  183. data/test/search/filters/or.rb +15 -0
  184. data/test/search/filters/range.rb +16 -0
  185. data/test/search/filters/type.json +1 -0
  186. data/test/search/filters/type.rb +1 -0
  187. data/test/search/filters_test.rb +166 -0
  188. data/test/search/queries/bool.json +1 -0
  189. data/test/search/queries/bool.rb +21 -0
  190. data/test/search/queries/boosting.json +1 -0
  191. data/test/search/queries/boosting.rb +17 -0
  192. data/test/search/queries/constant_score.rb +10 -0
  193. data/test/search/queries/constant_score_filter.rb +10 -0
  194. data/test/search/queries/custom_score.documents +1 -0
  195. data/test/search/queries/custom_score.rb +14 -0
  196. data/test/search/queries/dis_max.rb +15 -0
  197. data/test/search/queries/field.rb +7 -0
  198. data/test/search/queries/filters_and_facets.documents +1 -0
  199. data/test/search/queries/filters_and_facets.json +1 -0
  200. data/test/search/queries/flt.rb +9 -0
  201. data/test/search/queries/flt_field.rb +10 -0
  202. data/test/search/queries/fuzzy_complex.rb +5 -0
  203. data/test/search/queries/fuzzy_simple.rb +5 -0
  204. data/test/search/queries/has_child.blog.mapping +1 -0
  205. data/test/search/queries/has_child.blog_tag.mapping +1 -0
  206. data/test/search/queries/has_child.rb +10 -0
  207. data/test/search/queries/has_child_complex.blog.mapping +1 -0
  208. data/test/search/queries/has_child_complex.blog_tag.mapping +1 -0
  209. data/test/search/queries/has_child_complex.rb +17 -0
  210. data/test/search/queries/ids.rb +1 -0
  211. data/test/search/queries/match_all.rb +1 -0
  212. data/test/search/queries/mlt.json +1 -0
  213. data/test/search/queries/mlt.rb +9 -0
  214. data/test/search/queries/mlt_field.rb +10 -0
  215. data/test/search/queries/nested.json +1 -0
  216. data/test/search/queries/nested.mapping +9 -0
  217. data/test/search/queries/phrase_prefix.rb +8 -0
  218. data/test/search/queries/prefix.rb +1 -0
  219. data/test/search/queries/prefix_short.rb +1 -0
  220. data/test/search/queries/query_string.rb +8 -0
  221. data/test/search/queries/query_string_with_multiple_fields.rb +9 -0
  222. data/test/search/queries/query_string_without_default_field.rb +7 -0
  223. data/test/search/queries/range.rb +11 -0
  224. data/test/search/queries/span_near.json +1 -0
  225. data/test/search/queries/span_not.json +1 -0
  226. data/test/search/queries/span_or.json +1 -0
  227. data/test/search/queries/span_term.json +1 -0
  228. data/test/search/queries/term.json +1 -0
  229. data/test/search/queries/term.rb +1 -0
  230. data/test/search/queries/terms.rb +1 -0
  231. data/test/search/queries/text.json +1 -0
  232. data/test/search/queries/text.rb +8 -0
  233. data/test/search/queries/top_children.blog.mapping +1 -0
  234. data/test/search/queries/top_children.blog_tag.mapping +1 -0
  235. data/test/search/queries/top_children.rb +11 -0
  236. data/test/search/queries/wildcard.rb +1 -0
  237. data/test/search/queries/wildcard_short.rb +1 -0
  238. data/test/search/query_test.rb +311 -0
  239. data/test/test_config.rb +157 -0
  240. 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,13 @@
1
+ module Eson
2
+ module Search
3
+ class FilterFacet
4
+ include Facet
5
+ include Filters
6
+ include FilterMethods
7
+
8
+ # @macro eson.facet
9
+ short_name :filter
10
+
11
+ end
12
+ end
13
+ 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,16 @@
1
+ module Eson
2
+ module Search
3
+ class FuzzyLikeThis
4
+ include Query
5
+
6
+ # @macro eson.query
7
+ short_name :flt
8
+
9
+ attr_accessor :options
10
+
11
+ def initialize(options = {})
12
+ self.options = options
13
+ end
14
+ end
15
+ end
16
+ 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,16 @@
1
+ module Eson
2
+ module Search
3
+ class MoreLikeThis
4
+ include Query
5
+
6
+ # @macro eson.query
7
+ short_name :mlt
8
+
9
+ attr_accessor :options
10
+
11
+ def initialize(options = {})
12
+ self.options = options
13
+ end
14
+ end
15
+ end
16
+ 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,15 @@
1
+ module Eson
2
+ module Search
3
+ module Parametrized
4
+ attr_accessor :args
5
+
6
+ def initialize(args)
7
+ self.args = args
8
+ end
9
+
10
+ def param(name)
11
+ args[name] || (raise "Parameter #{name} not given")
12
+ end
13
+ end
14
+ end
15
+ 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