eson-dsl 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MethodReference.md +53 -0
- data/README.md +59 -113
- data/Rakefile +2 -2
- data/eson-dsl.gemspec +2 -1
- data/examples/queries/custom_boost_factor.rb +9 -0
- data/examples/queries/custom_filters_score.rb +15 -0
- data/examples/queries/custom_filters_score_with_script.rb +15 -0
- data/examples/queries/filtered.rb +8 -0
- data/examples/queries/indices.rb +12 -0
- data/examples/queries/match.rb +7 -0
- data/examples/queries/multi_match.rb +5 -0
- data/examples/queries/text.rb +2 -0
- data/lib/compat.rb +15 -0
- data/lib/eson-dsl.rb +35 -0
- data/lib/eson/modules/query_plugin.rb +4 -2
- data/lib/eson/search/and.rb +1 -5
- data/lib/eson/search/base_query.rb +5 -8
- data/lib/eson/search/bool.rb +2 -5
- data/lib/eson/search/boosting.rb +1 -4
- data/lib/eson/search/custom_boost_factor.rb +19 -0
- data/lib/eson/search/custom_filters_score.rb +42 -0
- data/lib/eson/search/date_histogram.rb +0 -2
- data/lib/eson/search/facet.rb +10 -5
- data/lib/eson/search/facets.rb +2 -1
- data/lib/eson/search/field_based.rb +1 -1
- data/lib/eson/search/filter.rb +1 -0
- data/lib/eson/search/filtered.rb +15 -0
- data/lib/eson/search/geo_distance.rb +2 -5
- data/lib/eson/search/has_child.rb +3 -5
- data/lib/eson/search/ids.rb +2 -4
- data/lib/eson/search/indices.rb +48 -0
- data/lib/eson/search/match.rb +10 -0
- data/lib/eson/search/multi_match.rb +21 -0
- data/lib/eson/search/prefix.rb +2 -4
- data/lib/eson/search/query.rb +1 -0
- data/lib/eson/search/term.rb +2 -4
- data/lib/eson/search/terms.rb +3 -5
- data/lib/eson/search/top_children.rb +2 -4
- data/test/search/facets/scoped.json +1 -1
- data/test/search/filters/and.rb +7 -11
- data/test/search/filters/bool.json +1 -1
- data/test/search/filters/bool.rb +17 -22
- data/test/search/filters/geo_bounding_box_hash.json +1 -1
- data/test/search/filters/geo_distance_hash.json +1 -1
- data/test/search/filters/geo_distance_range_hash.json +1 -1
- data/test/search/filters/geo_polygon_hash.json +1 -1
- data/test/search/filters/has_child.rb +7 -11
- data/test/search/filters/ids.rb +7 -11
- data/test/search/filters/not.rb +5 -9
- data/test/search/filters/or.rb +7 -11
- data/test/search/filters/range.rb +6 -11
- data/test/search/filters/type.json +1 -1
- data/test/search/filters/type.rb +1 -1
- data/test/search/filters_test.rb +2 -2
- data/test/search/queries/custom_boost_factor.json +10 -0
- data/test/search/queries/custom_filters_score.json +21 -0
- data/test/search/queries/filtered.rb +1 -0
- data/test/search/queries/filters_and_facets.json +1 -1
- data/test/search/queries/indices.json +13 -0
- data/test/search/queries/match.json +1 -0
- data/test/search/queries/multi_match.json +8 -0
- data/test/search/query_test.rb +70 -15
- metadata +29 -9
- data/TODO.md +0 -1
@@ -11,7 +11,7 @@ module Eson
|
|
11
11
|
|
12
12
|
def call(*args)
|
13
13
|
if query.respond_to?(:to_query_hash)
|
14
|
-
self.
|
14
|
+
self.parameters = query.to_query_hash
|
15
15
|
end
|
16
16
|
|
17
17
|
super(*args)
|
@@ -29,7 +29,9 @@ module Eson
|
|
29
29
|
[protocol::Search,
|
30
30
|
protocol::Count,
|
31
31
|
protocol::DeleteByQuery,
|
32
|
-
protocol::Percolate
|
32
|
+
protocol::Percolate,
|
33
|
+
protocol::Explain,
|
34
|
+
protocol::Validate]
|
33
35
|
end
|
34
36
|
|
35
37
|
def handle_block(&block)
|
data/lib/eson/search/and.rb
CHANGED
@@ -5,11 +5,7 @@ module Eson
|
|
5
5
|
include FilterMethods
|
6
6
|
include Filter
|
7
7
|
|
8
|
-
|
9
|
-
# @macro and
|
10
|
-
# @yield the block describing all subfilters
|
11
|
-
# Generates a `$1` filter.
|
12
|
-
# {include:file:eson-dsl/examples/filters/$1.rb}
|
8
|
+
# @!macro eson.filter
|
13
9
|
short_name 'and'
|
14
10
|
|
15
11
|
attr_accessor :options
|
@@ -18,14 +18,11 @@ module Eson
|
|
18
18
|
end
|
19
19
|
|
20
20
|
if filters && !filters.empty?
|
21
|
-
|
22
|
-
:
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
}
|
27
|
-
}
|
28
|
-
}
|
21
|
+
if filters.length > 1
|
22
|
+
hash[:filter] = {:and => filter.to_query_hash}
|
23
|
+
else
|
24
|
+
hash[:filter] = filter.to_query_hash
|
25
|
+
end
|
29
26
|
end
|
30
27
|
|
31
28
|
if facets.length > 0
|
data/lib/eson/search/bool.rb
CHANGED
@@ -4,11 +4,8 @@ module Eson
|
|
4
4
|
include Filter
|
5
5
|
include Query
|
6
6
|
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# Generates a `$1` filter or query, depending on context.
|
10
|
-
# {include:file:eson-dsl/examples/filters/$1.rb}
|
11
|
-
# {include:file:eson-dsl/examples/queries/$1.rb}
|
7
|
+
# @!macro eson.filter
|
8
|
+
# @!macro eson.query
|
12
9
|
short_name :bool
|
13
10
|
|
14
11
|
attr_accessor :options, :conditions
|
data/lib/eson/search/boosting.rb
CHANGED
@@ -4,10 +4,7 @@ module Eson
|
|
4
4
|
include Query
|
5
5
|
|
6
6
|
##
|
7
|
-
#
|
8
|
-
# @yield the block describing all subqueries
|
9
|
-
# Generates a `$1` query.
|
10
|
-
# {include:file:eson-dsl/examples/queries/$1.rb}
|
7
|
+
# @!macro eson.query
|
11
8
|
short_name :boosting
|
12
9
|
|
13
10
|
attr_accessor :options, :conditions
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
class CustomBoostFactor
|
4
|
+
|
5
|
+
include Queries
|
6
|
+
include Query
|
7
|
+
|
8
|
+
# @macro eson.query
|
9
|
+
short_name :custom_boost_factor
|
10
|
+
|
11
|
+
attr_accessor :options
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
self.options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
class CustomFiltersScore
|
4
|
+
include Queries
|
5
|
+
include Query
|
6
|
+
|
7
|
+
# @!macro eson.query
|
8
|
+
short_name :custom_filters_score
|
9
|
+
|
10
|
+
attr_accessor :options, :filters
|
11
|
+
|
12
|
+
def initialize(options = {})
|
13
|
+
self.options = options
|
14
|
+
self.filters = []
|
15
|
+
end
|
16
|
+
|
17
|
+
def filters(&block)
|
18
|
+
instance_exec(self, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def filter(options, &block)
|
22
|
+
sub = SubQuery.new(args)
|
23
|
+
|
24
|
+
@filters << [options, sub]
|
25
|
+
|
26
|
+
sub.send(context, &block)
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_query_hash
|
30
|
+
result = {}
|
31
|
+
|
32
|
+
result[:query] = queries.to_query_hash
|
33
|
+
result[:filters] = @filters.map do |options, filter|
|
34
|
+
{:filter => filter.to_query_hash}.merge!(options)
|
35
|
+
end
|
36
|
+
|
37
|
+
{name => result.merge(options)}
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/eson/search/facet.rb
CHANGED
@@ -3,6 +3,7 @@ module Eson
|
|
3
3
|
module Facet
|
4
4
|
module ClassMethods
|
5
5
|
def short_name(name)
|
6
|
+
name = name.to_sym
|
6
7
|
define_method :name do
|
7
8
|
name
|
8
9
|
end
|
@@ -18,16 +19,20 @@ module Eson
|
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
|
-
attr_accessor :args
|
22
|
+
attr_accessor :args, :scope_name
|
22
23
|
|
23
24
|
def param(name)
|
24
25
|
args[name] || (raise "Parameter #{name} not given")
|
25
26
|
end
|
26
27
|
|
27
28
|
def scope(query, name)
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
case query
|
30
|
+
when Nested, HasChild
|
31
|
+
query.options[:_scope] = name
|
32
|
+
self.scope_name = name
|
33
|
+
else
|
34
|
+
raise "Cannot scope unless Query is a Nested or HasChild Query"
|
35
|
+
end
|
31
36
|
end
|
32
37
|
|
33
38
|
def method_missing(name, arg)
|
@@ -36,4 +41,4 @@ module Eson
|
|
36
41
|
end
|
37
42
|
end
|
38
43
|
end
|
39
|
-
end
|
44
|
+
end
|
data/lib/eson/search/facets.rb
CHANGED
data/lib/eson/search/filter.rb
CHANGED
@@ -4,11 +4,8 @@ module Eson
|
|
4
4
|
include Filter
|
5
5
|
include Facet
|
6
6
|
|
7
|
-
# @macro
|
8
|
-
#
|
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}
|
7
|
+
# @macro eson.filter
|
8
|
+
# @macro eson.facet
|
12
9
|
short_name :geo_distance
|
13
10
|
|
14
11
|
attr_accessor :field, :options
|
@@ -6,10 +6,8 @@ module Eson
|
|
6
6
|
|
7
7
|
include QueryGroup
|
8
8
|
|
9
|
-
# @macro
|
10
|
-
#
|
11
|
-
# {include:file:eson-dsl/examples/filters/$1.rb}
|
12
|
-
# {include:file:eson-dsl/examples/queries/$1.rb}
|
9
|
+
# @macro eson.filter
|
10
|
+
# @macro eson.facet
|
13
11
|
short_name :has_child
|
14
12
|
|
15
13
|
attr_accessor :options
|
@@ -26,4 +24,4 @@ module Eson
|
|
26
24
|
|
27
25
|
end
|
28
26
|
end
|
29
|
-
end
|
27
|
+
end
|
data/lib/eson/search/ids.rb
CHANGED
@@ -4,10 +4,8 @@ module Eson
|
|
4
4
|
include Filter
|
5
5
|
include Query
|
6
6
|
|
7
|
-
# @macro
|
8
|
-
#
|
9
|
-
# {include:file:eson-dsl/examples/filters/$1.rb}
|
10
|
-
# {include:file:eson-dsl/examples/queries/$1.rb}
|
7
|
+
# @macro eson.filter
|
8
|
+
# @macro eson.query
|
11
9
|
short_name :ids
|
12
10
|
|
13
11
|
attr_accessor :options
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
class Indices
|
4
|
+
include Query
|
5
|
+
|
6
|
+
# @macro eson.query
|
7
|
+
short_name :indices
|
8
|
+
|
9
|
+
attr_accessor :indices, :no_match_val, :query_val
|
10
|
+
|
11
|
+
def initialize(*indices)
|
12
|
+
self.indices = indices
|
13
|
+
end
|
14
|
+
|
15
|
+
def query(&block)
|
16
|
+
self.query_val ||= SubQuery.new(args)
|
17
|
+
self.query_val.send(context, &Proc.new)
|
18
|
+
end
|
19
|
+
|
20
|
+
def no_match_query(no_match_val = nil)
|
21
|
+
if no_match_val
|
22
|
+
self.no_match_val = no_match_val
|
23
|
+
elsif block_given?
|
24
|
+
self.no_match_val ||= SubQuery.new(args)
|
25
|
+
self.no_match_val.send(context, &Proc.new)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_query_hash
|
30
|
+
options = {
|
31
|
+
:indices => indices,
|
32
|
+
:query => self.query_val.to_query_hash,
|
33
|
+
}
|
34
|
+
|
35
|
+
if no_match_val
|
36
|
+
if no_match_val.respond_to? :to_query_hash
|
37
|
+
no_match = no_match_val.to_query_hash
|
38
|
+
else
|
39
|
+
no_match = no_match_val
|
40
|
+
end
|
41
|
+
options.merge!(:no_match_query => no_match)
|
42
|
+
end
|
43
|
+
|
44
|
+
{ name => options }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Eson
|
2
|
+
module Search
|
3
|
+
class MultiMatch
|
4
|
+
include Query
|
5
|
+
|
6
|
+
# @macro eson.query
|
7
|
+
short_name :multi_match
|
8
|
+
|
9
|
+
attr_accessor :options, :query
|
10
|
+
|
11
|
+
def initialize(query, options = {})
|
12
|
+
self.options = options
|
13
|
+
self.query = query
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_query_hash
|
17
|
+
{:multi_match => {:query => query}.merge!(options)}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/eson/search/prefix.rb
CHANGED
@@ -4,10 +4,8 @@ module Eson
|
|
4
4
|
include Query
|
5
5
|
include Filter
|
6
6
|
|
7
|
-
# @macro
|
8
|
-
#
|
9
|
-
# {include:file:eson-dsl/examples/filters/$1.rb}
|
10
|
-
# {include:file:eson-dsl/examples/queries/$1.rb}
|
7
|
+
# @macro eson.filter
|
8
|
+
# @macro eson.facet
|
11
9
|
short_name :prefix
|
12
10
|
|
13
11
|
def to_query_hash
|
data/lib/eson/search/query.rb
CHANGED
data/lib/eson/search/term.rb
CHANGED
@@ -4,10 +4,8 @@ module Eson
|
|
4
4
|
include Query
|
5
5
|
include Filter
|
6
6
|
|
7
|
-
# @macro
|
8
|
-
#
|
9
|
-
# {include:file:eson-dsl/examples/filters/$1.rb}
|
10
|
-
# {include:file:eson-dsl/examples/queries/$1.rb}
|
7
|
+
# @macro eson.filter
|
8
|
+
# @macro eson.facet
|
11
9
|
short_name :term
|
12
10
|
|
13
11
|
def to_query_hash
|
data/lib/eson/search/terms.rb
CHANGED
@@ -5,11 +5,9 @@ module Eson
|
|
5
5
|
include Filter
|
6
6
|
include Facet
|
7
7
|
|
8
|
-
# @macro
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# {include:file:eson-dsl/examples/facet/$1.rb}
|
12
|
-
# {include:file:eson-dsl/examples/queries/$1.rb}
|
8
|
+
# @macro eson.filter
|
9
|
+
# @macro eson.query
|
10
|
+
# @macro eson.facet
|
13
11
|
short_name :terms
|
14
12
|
|
15
13
|
attr_accessor :options, :field
|
@@ -5,10 +5,8 @@ module Eson
|
|
5
5
|
include Filter
|
6
6
|
include QueryGroup
|
7
7
|
|
8
|
-
# @macro
|
9
|
-
#
|
10
|
-
# {include:file:eson-dsl/examples/filters/$1.rb}
|
11
|
-
# {include:file:eson-dsl/examples/queries/$1.rb}# @macro eson.query
|
8
|
+
# @macro eson.filter
|
9
|
+
# @macro eson.query
|
12
10
|
short_name :top_children
|
13
11
|
|
14
12
|
attr_accessor :options
|
@@ -1 +1 @@
|
|
1
|
-
{"query":{"nested":{"query":{"filtered":{"query":{"match_all":{}},"filter":{"range":{"age":{"from":10,"to":20}}}}},"path":"obj1","score_mode":"avg","_scope":"my_scope"}},"facets":{"hist1":{"histogram":{"field":"age","interval":2,"scope":"my_scope"}}}
|
1
|
+
{"query":{"nested":{"query":{"filtered":{"query":{"match_all":{}},"filter":{"range":{"age":{"from":10,"to":20}}}}},"path":"obj1","score_mode":"avg","_scope":"my_scope"}},"facets":{"hist1":{"histogram":{"field":"age","interval":2},"scope":"my_scope"}}}
|