CloudSesame 0.6.8 → 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.
- checksums.yaml +4 -4
- data/.editorconfig +12 -0
- data/.gitignore +1 -1
- data/Gemfile.lock +13 -13
- data/Guardfile +1 -0
- data/cloud_sesame.gemspec +2 -2
- data/coverage/.last_run.json +1 -1
- data/coverage/.resultset.json +679 -591
- data/lib/cloud_sesame/config/credential.rb +6 -6
- data/lib/cloud_sesame/context.rb +0 -5
- data/lib/cloud_sesame/domain/base.rb +147 -128
- data/lib/cloud_sesame/domain/client.rb +25 -25
- data/lib/cloud_sesame/domain/client_module/caching/base.rb +19 -23
- data/lib/cloud_sesame/domain/client_module/caching/no_cache.rb +11 -11
- data/lib/cloud_sesame/domain/client_module/caching/rails_cache.rb +32 -28
- data/lib/cloud_sesame/domain/client_module/caching.rb +19 -28
- data/lib/cloud_sesame/domain/client_module/retry.rb +6 -6
- data/lib/cloud_sesame/domain/config.rb +6 -6
- data/lib/cloud_sesame/query/ast/abstract/multi_expression_operator.rb +37 -0
- data/lib/cloud_sesame/query/ast/abstract/operator.rb +27 -0
- data/lib/cloud_sesame/query/ast/abstract/single_expression_operator.rb +39 -0
- data/lib/cloud_sesame/query/ast/abstract/value.rb +88 -0
- data/lib/cloud_sesame/query/ast/and.rb +1 -1
- data/lib/cloud_sesame/query/ast/date_value.rb +19 -3
- data/lib/cloud_sesame/query/ast/literal.rb +13 -28
- data/lib/cloud_sesame/query/ast/near.rb +4 -4
- data/lib/cloud_sesame/query/ast/not.rb +6 -7
- data/lib/cloud_sesame/query/ast/numeric_value.rb +20 -12
- data/lib/cloud_sesame/query/ast/or.rb +1 -1
- data/lib/cloud_sesame/query/ast/phrase.rb +1 -1
- data/lib/cloud_sesame/query/ast/prefix.rb +1 -1
- data/lib/cloud_sesame/query/ast/range_value.rb +40 -39
- data/lib/cloud_sesame/query/ast/root.rb +2 -6
- data/lib/cloud_sesame/query/ast/string_value.rb +26 -0
- data/lib/cloud_sesame/query/ast/term.rb +1 -1
- data/lib/cloud_sesame/query/ast/value.rb +25 -54
- data/lib/cloud_sesame/query/builder.rb +83 -54
- data/lib/cloud_sesame/query/domain/block.rb +3 -1
- data/lib/cloud_sesame/query/dsl/applied_filter_query.rb +14 -23
- data/lib/cloud_sesame/query/dsl/field_accessors.rb +25 -22
- data/lib/cloud_sesame/query/dsl/field_array_methods.rb +1 -1
- data/lib/cloud_sesame/query/dsl/inspect_method.rb +31 -0
- data/lib/cloud_sesame/query/dsl/sort_methods.rb +5 -4
- data/lib/cloud_sesame/query/node/abstract.rb +1 -2
- data/lib/cloud_sesame/query/node/facet.rb +1 -5
- data/lib/cloud_sesame/query/node/filter_query.rb +15 -2
- data/lib/cloud_sesame/query/node/fuzziness.rb +4 -3
- data/lib/cloud_sesame/query/node/page.rb +2 -2
- data/lib/cloud_sesame/query/node/query.rb +4 -17
- data/lib/cloud_sesame/query/node/query_options.rb +6 -16
- data/lib/cloud_sesame/query/node/query_options_field.rb +3 -1
- data/lib/cloud_sesame/query/node/query_parser.rb +8 -10
- data/lib/cloud_sesame/query/node/request.rb +57 -31
- data/lib/cloud_sesame/query/node/sort.rb +25 -11
- data/lib/cloud_sesame.rb +15 -12
- data/lib/{abstract_object.rb → services/abstract_object.rb} +0 -0
- data/lib/services/class_specific.rb +44 -0
- data/lib/services/lazy_object.rb +19 -0
- data/spec/cloud_sesame/domain/base_spec.rb +26 -11
- data/spec/cloud_sesame/domain/client_module/caching/base_spec.rb +2 -1
- data/spec/cloud_sesame/domain/client_module/caching/no_cache_spec.rb +2 -3
- data/spec/cloud_sesame/domain/client_module/caching/rails_cache_spec.rb +6 -6
- data/spec/cloud_sesame/domain/client_module/caching_spec.rb +33 -32
- data/spec/cloud_sesame/query/ast/abstract/multi_expression_operator_spec.rb +67 -0
- data/spec/cloud_sesame/query/ast/abstract/operator_spec.rb +29 -0
- data/spec/cloud_sesame/query/ast/abstract/single_expression_operator_spec.rb +70 -0
- data/spec/cloud_sesame/query/ast/abstract/value_spec.rb +118 -0
- data/spec/cloud_sesame/query/ast/and_spec.rb +1 -1
- data/spec/cloud_sesame/query/ast/or_spec.rb +1 -1
- data/spec/cloud_sesame/query/ast/range_value_spec.rb +5 -11
- data/spec/cloud_sesame/query/builder_spec.rb +10 -4
- data/spec/cloud_sesame/query/domain/block_spec.rb +15 -8
- data/spec/cloud_sesame/query/dsl/{block_methods_spec.rb → block_styled_operators_spec.rb} +0 -0
- data/spec/cloud_sesame/query/dsl/field_accessors_spec.rb +88 -50
- data/spec/cloud_sesame/query/dsl/field_array_methods_spec.rb +0 -2
- data/spec/cloud_sesame/query/node/facet_spec.rb +1 -15
- data/spec/cloud_sesame/query/node/filter_query_spec.rb +16 -2
- data/spec/cloud_sesame/query/node/page_spec.rb +3 -2
- data/spec/cloud_sesame/query/node/query_options_spec.rb +1 -1
- data/spec/cloud_sesame/query/node/query_parser_spec.rb +1 -7
- data/spec/cloud_sesame/query/node/query_spec.rb +10 -28
- data/spec/cloud_sesame/query/node/sort_spec.rb +19 -28
- data/spec/cloud_sesame_spec.rb +2 -156
- data/spec/helpers/benchmark_helper.rb +12 -0
- data/spec/integration/filter_query_spec.rb +0 -0
- data/spec/profiling_spec.rb +155 -0
- data/spec/{abstract_object_spec.rb → services/abstract_object_spec.rb} +0 -0
- data/spec/services/class_specific_spec.rb +135 -0
- data/spec/spec_helper.rb +3 -0
- metadata +32 -22
- data/lib/active_support/core_ext/object/deep_dup.rb +0 -53
- data/lib/active_support/core_ext/object/duplicable.rb +0 -98
- data/lib/cloud_sesame/query/ast/multi_expression_operator.rb +0 -35
- data/lib/cloud_sesame/query/ast/operator.rb +0 -25
- data/lib/cloud_sesame/query/ast/single_expression_operator.rb +0 -35
- data/lib/cloud_sesame/query/scope.rb +0 -21
- data/profiler.rb +0 -91
- data/spec/cloud_sesame/query/ast/multi_expression_operator_spec.rb +0 -76
- data/spec/cloud_sesame/query/ast/operator_spec.rb +0 -29
- data/spec/cloud_sesame/query/ast/single_expression_operator_spec.rb +0 -78
- data/spec/context_spec.rb +0 -17
@@ -1,8 +1,8 @@
|
|
1
1
|
module CloudSesame
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
module Config
|
3
|
+
class Credential < ::AbstractObject
|
4
|
+
accept :access_key_id, as: [:access_key]
|
5
|
+
accept :secret_access_key, as: [:secret_key]
|
6
|
+
end
|
7
|
+
end
|
8
8
|
end
|
data/lib/cloud_sesame/context.rb
CHANGED
@@ -1,130 +1,149 @@
|
|
1
1
|
module CloudSesame
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
2
|
+
module Domain
|
3
|
+
class Base
|
4
|
+
extend Forwardable
|
5
|
+
|
6
|
+
def_delegators :client, :config, :caching_with
|
7
|
+
|
8
|
+
attr_reader :searchable
|
9
|
+
|
10
|
+
def self.definitions
|
11
|
+
@definitions ||= {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(searchable)
|
15
|
+
@searchable = searchable
|
16
|
+
@builder = Query::Builder.construct_class(searchable)
|
17
|
+
end
|
18
|
+
|
19
|
+
def builder
|
20
|
+
@builder.new context, searchable
|
21
|
+
end
|
22
|
+
|
23
|
+
def client
|
24
|
+
@client ||= Client.new searchable
|
25
|
+
end
|
26
|
+
|
27
|
+
def context
|
28
|
+
@context ||= Context.new
|
29
|
+
end
|
30
|
+
|
31
|
+
# DEFAULT CONTEXT METHODS
|
32
|
+
# =========================================
|
33
|
+
|
34
|
+
def default_size(value)
|
35
|
+
context_page[:size] = value.to_i
|
36
|
+
end
|
37
|
+
|
38
|
+
def define_sloppiness(value)
|
39
|
+
context_query[:sloppiness] = Query::Node::Sloppiness.new(value)
|
40
|
+
end
|
41
|
+
|
42
|
+
def define_fuzziness(&block)
|
43
|
+
context_query[:fuzziness] = Query::Node::Fuzziness.new(&block)
|
44
|
+
end
|
45
|
+
|
46
|
+
def field(name, options = {})
|
47
|
+
field_name = (options[:as] || name).to_sym
|
48
|
+
|
49
|
+
add_sort_alias(name, options) if options[:as]
|
50
|
+
add_query_options(field_name, options) if options[:query]
|
51
|
+
add_facet(field_name, options) if options[:facet]
|
52
|
+
add_field(name, options)
|
53
|
+
end
|
54
|
+
|
55
|
+
def scope(name, proc = nil, &block)
|
56
|
+
block = proc unless block_given?
|
57
|
+
filter_query_scopes[name.to_sym] = block if block
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def add_sort_alias(name, options)
|
63
|
+
context_sort_fields[name] = { as: options[:as] }
|
64
|
+
end
|
65
|
+
|
66
|
+
def add_query_options(name, options)
|
67
|
+
context_query_options[name] = to_hash(options.delete(:query))
|
68
|
+
end
|
69
|
+
|
70
|
+
def add_facet(name, options)
|
71
|
+
context_facet[name] = to_hash(options.delete(:facet))
|
72
|
+
end
|
73
|
+
|
74
|
+
def add_field(name, options)
|
75
|
+
options = merge_with_as_field options if options[:as]
|
76
|
+
options[:type] = set_type(options[:type])
|
77
|
+
create_accessor name
|
78
|
+
create_default_literal name, options
|
79
|
+
filter_query_fields[name] = options
|
80
|
+
end
|
81
|
+
|
82
|
+
def set_type(type)
|
83
|
+
Query::AST::Value.map_type(type)
|
84
|
+
end
|
85
|
+
|
86
|
+
def merge_with_as_field(options)
|
87
|
+
(existing = filter_query_fields.delete(options[:as])) ? existing.merge(options) : options
|
88
|
+
end
|
89
|
+
|
90
|
+
def create_accessor(name)
|
91
|
+
@builder.field_accessor.__define_accessor__(name)
|
92
|
+
end
|
93
|
+
|
94
|
+
def create_default_literal(name, options)
|
95
|
+
if (block = options.delete(:default))
|
96
|
+
caller = block.binding.eval "self"
|
97
|
+
node = Query::Domain::Literal.new(name, options, caller)._eval(&block)
|
98
|
+
filter_query_defaults << node if node
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def to_hash(options)
|
103
|
+
options.is_a?(Hash) ? options : {}
|
104
|
+
end
|
105
|
+
|
106
|
+
def method_missing(name, *args, &block)
|
107
|
+
builder.respond_to?(name) ? builder.send(name, *args, &block) :
|
108
|
+
searchable.respond_to?(name) ? searchable.send(name, *args, &block) :
|
109
|
+
super
|
110
|
+
end
|
111
|
+
|
112
|
+
# CONTEXT INITIALIZERS
|
113
|
+
# =========================================
|
114
|
+
|
115
|
+
def context_page
|
116
|
+
context[:page] ||= {}
|
117
|
+
end
|
118
|
+
|
119
|
+
def context_query
|
120
|
+
context[:query] ||= {}
|
121
|
+
end
|
122
|
+
|
123
|
+
def context_query_options
|
124
|
+
(context[:query_options] ||= {})[:fields] ||= {}
|
125
|
+
end
|
126
|
+
|
127
|
+
def context_facet
|
128
|
+
context[:facet] ||= {}
|
129
|
+
end
|
130
|
+
|
131
|
+
def context_sort_fields
|
132
|
+
(context[:sort] ||= {})[:fields] ||= {}
|
133
|
+
end
|
134
|
+
|
135
|
+
def filter_query_fields
|
136
|
+
(context[:filter_query] ||= {})[:fields] ||= {}
|
137
|
+
end
|
138
|
+
|
139
|
+
def filter_query_defaults
|
140
|
+
(context[:filter_query] ||= {})[:defaults] ||= []
|
141
|
+
end
|
142
|
+
|
143
|
+
def filter_query_scopes
|
144
|
+
(context[:filter_query] ||= {})[:scopes] ||= {}
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
end
|
130
149
|
end
|
@@ -1,38 +1,38 @@
|
|
1
1
|
require 'cloud_sesame/domain/client_module/caching'
|
2
2
|
|
3
3
|
module CloudSesame
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
module Domain
|
5
|
+
class Client
|
6
|
+
include ClientModule::Caching
|
7
7
|
|
8
|
-
|
8
|
+
attr_reader :searchable
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def self.configure
|
11
|
+
yield global_config if block_given?
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
def self.global_config
|
15
|
+
@global_config ||= Config.new
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
def initialize(searchable)
|
19
|
+
@searchable = searchable
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
def config
|
23
|
+
@config ||= Config.new self.class.global_config
|
24
|
+
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
def search(params)
|
27
|
+
executor.fetch params
|
28
|
+
end
|
29
29
|
|
30
|
-
|
30
|
+
private
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
def aws_client
|
33
|
+
@aws_client ||= LazyObject.new { ::Aws::CloudSearchDomain::Client.new config.to_hash }
|
34
|
+
end
|
35
35
|
|
36
|
-
|
37
|
-
|
36
|
+
end
|
37
|
+
end
|
38
38
|
end
|
@@ -1,30 +1,26 @@
|
|
1
1
|
module CloudSesame
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
module Domain
|
3
|
+
module ClientModule
|
4
|
+
module Caching
|
5
|
+
class Base
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
def initialize(client, searchable)
|
8
|
+
@client = client
|
9
|
+
@searchable = searchable
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def fetch(_params)
|
13
|
+
raise Error::Caching, "Caching Module needs #fetch method and accepts params"
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
raise Error::Caching, "Caching Module needs #fetch method and accepts params"
|
18
|
-
end
|
16
|
+
private
|
19
17
|
|
20
|
-
|
18
|
+
def search(params)
|
19
|
+
@client.search params
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
30
26
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
module CloudSesame
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
module Domain
|
3
|
+
module ClientModule
|
4
|
+
module Caching
|
5
|
+
class NoCache < Base
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
def fetch(params)
|
8
|
+
search params
|
9
|
+
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
15
|
end
|
@@ -1,38 +1,42 @@
|
|
1
1
|
require 'ostruct'
|
2
2
|
|
3
3
|
module CloudSesame
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
module Domain
|
5
|
+
module ClientModule
|
6
|
+
module Caching
|
7
|
+
class RailsCache < Base
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
def initialize(client, searchable)
|
10
|
+
ensure_environment_exists
|
11
|
+
super
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
def fetch(params)
|
15
|
+
Rails.cache.fetch(hexdigest(params)) do
|
16
|
+
results = search params
|
17
|
+
OpenStruct.new(
|
18
|
+
status: results.status,
|
19
|
+
hits: results.hits,
|
20
|
+
facets: results.facets
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
20
24
|
|
21
|
-
|
25
|
+
private
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
def hexdigest(params)
|
28
|
+
searchable_params = params.merge(searchable: @searchable)
|
29
|
+
Digest::MD5.hexdigest Marshal.dump(searchable_params)
|
30
|
+
end
|
27
31
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
32
|
+
def ensure_environment_exists
|
33
|
+
unless RailsCache.const_defined?(:Rails)
|
34
|
+
raise Error::Caching, "Rails environment cannot be found"
|
35
|
+
end
|
36
|
+
end
|
33
37
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
38
42
|
end
|
@@ -3,38 +3,29 @@ require_relative './caching/no_cache'
|
|
3
3
|
require_relative './caching/rails_cache'
|
4
4
|
|
5
5
|
module CloudSesame
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
module Domain
|
7
|
+
module ClientModule
|
8
|
+
module Caching
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
10
|
+
def caching_with(klass)
|
11
|
+
self.executor = klass.is_a?(Class) ? klass : module_get(klass)
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def executor
|
15
|
+
@executor ||= Caching::NoCache.new(aws_client, @searchable)
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
def executor=(executor)
|
19
|
+
@executor = executor.new(aws_client, @searchable)
|
20
|
+
end
|
22
21
|
|
23
|
-
|
22
|
+
private
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
def module_get(klass)
|
25
|
+
ClientModule::Caching.const_get klass, false
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
def unrecognized_caching_module
|
34
|
-
raise Error::Caching, "Unrecognized Caching Module"
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
40
31
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module CloudSesame
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
module Domain
|
3
|
+
class Config < CloudSesame::Config::Credential
|
4
|
+
accept :sigv4_region, as: [:region]
|
5
|
+
accept :endpoint, as: [:search_endpoint]
|
6
|
+
end
|
7
|
+
end
|
8
8
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module CloudSesame
|
2
|
+
module Query
|
3
|
+
module AST
|
4
|
+
module Abstract
|
5
|
+
class MultiExpressionOperator < Operator
|
6
|
+
|
7
|
+
def <<(object)
|
8
|
+
children << object
|
9
|
+
end
|
10
|
+
|
11
|
+
def applied(included = true)
|
12
|
+
children.map { |child| child.applied(included) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def children
|
16
|
+
@children ||= build_children
|
17
|
+
end
|
18
|
+
|
19
|
+
def compile
|
20
|
+
if !children.empty? && (compiled = children.compile) && !compiled.empty?
|
21
|
+
"(#{ symbol }#{ boost } #{ compiled })"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def build_children
|
28
|
+
(children = FieldArray.new)._scope = self
|
29
|
+
children
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module CloudSesame
|
2
|
+
module Query
|
3
|
+
module AST
|
4
|
+
module Abstract
|
5
|
+
class Operator
|
6
|
+
SYMBOL = nil
|
7
|
+
|
8
|
+
attr_reader :context, :options
|
9
|
+
|
10
|
+
def initialize(context, options = {})
|
11
|
+
@context = context
|
12
|
+
@options = options
|
13
|
+
end
|
14
|
+
|
15
|
+
def boost
|
16
|
+
" boost=#{ options[:boost] }" if options[:boost]
|
17
|
+
end
|
18
|
+
|
19
|
+
def symbol
|
20
|
+
self.class::SYMBOL
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|