stretchy 0.4.0 → 0.4.1

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.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.ruby-version +1 -0
  4. data/lib/stretchy/boosts/base.rb +2 -3
  5. data/lib/stretchy/boosts/field_decay_boost.rb +23 -19
  6. data/lib/stretchy/boosts/filter_boost.rb +6 -3
  7. data/lib/stretchy/boosts/random_boost.rb +7 -4
  8. data/lib/stretchy/builders/boost_builder.rb +1 -1
  9. data/lib/stretchy/builders/filter_builder.rb +55 -0
  10. data/lib/stretchy/builders/match_builder.rb +41 -43
  11. data/lib/stretchy/builders/query_builder.rb +37 -0
  12. data/lib/stretchy/builders/shell_builder.rb +53 -0
  13. data/lib/stretchy/builders/where_builder.rb +88 -159
  14. data/lib/stretchy/builders.rb +3 -0
  15. data/lib/stretchy/clauses/base.rb +33 -78
  16. data/lib/stretchy/clauses/boost_clause.rb +10 -10
  17. data/lib/stretchy/clauses/boost_match_clause.rb +3 -3
  18. data/lib/stretchy/clauses/boost_where_clause.rb +5 -5
  19. data/lib/stretchy/clauses/match_clause.rb +5 -24
  20. data/lib/stretchy/clauses/where_clause.rb +23 -42
  21. data/lib/stretchy/errors/validation_error.rb +17 -0
  22. data/lib/stretchy/errors.rb +1 -1
  23. data/lib/stretchy/filters/and_filter.rb +5 -1
  24. data/lib/stretchy/filters/base.rb +2 -2
  25. data/lib/stretchy/filters/bool_filter.rb +10 -4
  26. data/lib/stretchy/filters/exists_filter.rb +5 -1
  27. data/lib/stretchy/filters/geo_filter.rb +13 -7
  28. data/lib/stretchy/filters/not_filter.rb +5 -2
  29. data/lib/stretchy/filters/or_filter.rb +4 -1
  30. data/lib/stretchy/filters/query_filter.rb +5 -1
  31. data/lib/stretchy/filters/range_filter.rb +10 -5
  32. data/lib/stretchy/filters/terms_filter.rb +8 -2
  33. data/lib/stretchy/queries/base.rb +2 -2
  34. data/lib/stretchy/queries/bool_query.rb +12 -0
  35. data/lib/stretchy/queries/filtered_query.rb +8 -3
  36. data/lib/stretchy/queries/function_score_query.rb +25 -32
  37. data/lib/stretchy/queries/match_query.rb +10 -3
  38. data/lib/stretchy/results/base.rb +9 -23
  39. data/lib/stretchy/types/base.rb +2 -2
  40. data/lib/stretchy/types/geo_point.rb +15 -6
  41. data/lib/stretchy/types/range.rb +24 -6
  42. data/lib/stretchy/utils/logger.rb +10 -5
  43. data/lib/stretchy/utils/validation.rb +77 -0
  44. data/lib/stretchy/utils.rb +1 -1
  45. data/lib/stretchy/version.rb +1 -1
  46. data/lib/stretchy.rb +3 -0
  47. data/lib/stretchy_validations.rb +10 -0
  48. data/lib/validation/rule/decay.rb +20 -0
  49. data/lib/validation/rule/distance.rb +20 -0
  50. data/lib/validation/rule/field.rb +22 -0
  51. data/lib/validation/rule/inclusion.rb +33 -0
  52. data/lib/validation/rule/latitude.rb +21 -0
  53. data/lib/validation/rule/longitude.rb +22 -0
  54. data/lib/validation/rule/one_of.rb +22 -0
  55. data/lib/validation/rule/required.rb +26 -0
  56. data/lib/validation/rule/responds_to.rb +23 -0
  57. data/lib/validation/rule/type.rb +41 -0
  58. data/stretchy.gemspec +2 -0
  59. metadata +48 -5
  60. data/lib/stretchy/errors/contract_error.rb +0 -5
  61. data/lib/stretchy/utils/contract.rb +0 -120
@@ -2,194 +2,123 @@ module Stretchy
2
2
  module Builders
3
3
  class WhereBuilder
4
4
 
5
- attr_accessor :terms, :antiterms, :shouldterms, :shouldnotterms,
6
- :exists, :antiexists, :shouldexists, :shouldnotexists,
7
- :ranges, :antiranges, :shouldranges, :shouldnotranges,
8
- :geos, :antigeos, :shouldgeos, :shouldnotgeos
5
+ extend Forwardable
9
6
 
10
- def initialize(options = {})
11
- @terms = Hash.new { [] }
12
- @antiterms = Hash.new { [] }
13
- @shouldterms = Hash.new { [] }
14
- @shouldnotterms = Hash.new { [] }
15
-
16
- @ranges = {}
17
- @antiranges = {}
18
- @shouldranges = {}
19
- @shouldnotranges = {}
20
-
21
- @geos = {}
22
- @antigeos = {}
23
- @shouldgeos = {}
24
- @shouldnotgeos = {}
25
-
26
- @exists = []
27
- @antiexists = []
28
- @shouldexists = []
29
- @shouldnotexists = []
30
- end
31
-
32
- def build
33
- if use_bool?
34
- bool_filter
35
- elsif musts?
36
- and_filter
37
- elsif must_nots?
38
- not_filter
39
- else
40
- nil
41
- end
42
- end
43
-
44
- def musts?
45
- @terms.any? || @exists.any? || @ranges.any? || @geos.any?
46
- end
7
+ attr_accessor :must, :must_not, :should, :should_not
47
8
 
48
- def must_nots?
49
- @antiterms.any? || @antiexists.any? ||
50
- @antiranges.any? || @antigeos.any?
9
+ def initialize(options = {})
10
+ @must = FilterBuilder.new
11
+ @must_not = FilterBuilder.new(inverse: true)
12
+ @should = FilterBuilder.new(should: true)
13
+ @should_not = FilterBuilder.new(inverse: true, should: true)
51
14
  end
52
15
 
53
- def shoulds?
54
- @shouldterms.any? ||
55
- @shouldranges.any? ||
56
- @shouldgeos.any? ||
57
- @shouldexists.any?
16
+ def any?
17
+ must.any? || must_not.any? || should.any? || should_not.any?
58
18
  end
59
19
 
60
- def should_nots?
61
- @shouldnotterms.any? ||
62
- @shouldnotranges.any? ||
63
- @shouldnotgeos.any? ||
64
- @shouldnotexists.any?
20
+ def use_bool?
21
+ (must.any? && must_not.any?) || should.any? || should_not.any?
65
22
  end
66
23
 
67
- def use_bool?
68
- (musts? && must_nots?) || shoulds? || should_nots?
24
+ def add_param(field, param, options = {})
25
+ case param
26
+ when nil
27
+ builder_from_options(options.merge(inverse: !options[:inverse])).add_exists(field)
28
+ when ::Range, Types::Range
29
+ builder_from_options(options).add_range(field, param)
30
+ else
31
+ builder_from_options(options).add_terms(field, param)
32
+ end
69
33
  end
70
34
 
71
- def any?
72
- musts? || must_nots? || shoulds? || should_nots?
35
+ def add_geo(field, distance, options = {})
36
+ if options[:geo_point]
37
+ geo_point = Types::GeoPoint.new(options[:geo_point])
38
+ else
39
+ geo_point = Types::GeoPoint.new(options)
40
+ end
41
+
42
+ builder_from_options(options).add_geo(field, distance, geo_point)
73
43
  end
74
44
 
75
- def bool_filter
76
- Stretchy::Filters::BoolFilter.new(
77
- must: build_filters(
78
- terms: @terms,
79
- exists: @exists,
80
- ranges: @ranges,
81
- geos: @geos
82
- ),
83
- must_not: build_filters(
84
- terms: @antiterms,
85
- exists: @antiexists,
86
- ranges: @antiranges,
87
- geos: @antigeos
88
- ),
89
- should: build_should
90
- )
45
+ def add_range(field, options = {})
46
+ builder_from_options(options).add_range(field, options)
91
47
  end
92
48
 
93
- def and_filter
94
- filter = nil
95
- filters = build_filters(
96
- terms: @terms,
97
- exists: @exists,
98
- ranges: @ranges,
99
- geos: @geos
100
- )
101
- if filters.count > 1
102
- filter = Stretchy::Filters::AndFilter.new(filters)
49
+ def to_filter
50
+ if use_bool?
51
+ bool_filter
52
+ elsif must.any?
53
+ and_filter
54
+ elsif must_not.any?
55
+ not_filter
103
56
  else
104
- filter = filters.first
57
+ nil
105
58
  end
106
- filter
107
59
  end
108
60
 
109
- def not_filter
110
- filter = build_filters(
111
- terms: @antiterms,
112
- exists: @antiexists,
113
- ranges: @antiranges,
114
- geos: @antigeos
115
- )
116
- filter = Stretchy::Filters::OrFilter.new(filter) if filter.count > 1
117
- Stretchy::Filters::NotFilter.new(filter)
118
- end
61
+ private
119
62
 
120
- def build_should
121
- if shoulds? && should_nots?
122
- Stretchy::Filters::BoolFilter.new(
123
- must: build_filters(
124
- terms: @shouldterms,
125
- exists: @shouldexists,
126
- ranges: @shouldranges,
127
- geos: @shouldgeos
128
- ),
129
- must_not: build_filters(
130
- terms: @shouldnotterms,
131
- exists: @shouldnotexists,
132
- ranges: @shouldnotranges,
133
- geos: @shouldnotgeos
134
- )
135
- )
136
- elsif should_nots?
137
- filters = build_filters(
138
- terms: @shouldnotterms,
139
- exists: @shouldnotexists,
140
- ranges: @shouldnotranges,
141
- geos: @shouldnotgeos
142
- )
143
- if filters.count > 1
144
- filters = Stretchy::Filters::OrFilter.new(filters)
63
+ def builder_from_options(options = {})
64
+ return must unless options.is_a?(Hash)
65
+ if options[:inverse] && options[:should]
66
+ should_not
67
+ elsif options[:inverse]
68
+ must_not
69
+ elsif options[:should]
70
+ should
145
71
  else
146
- filters = filters.first
72
+ must
147
73
  end
148
-
149
- Stretchy::Filters::NotFilter.new(filters)
150
- else
151
- filters = build_filters(
152
- terms: @shouldterms,
153
- exists: @shouldexists,
154
- ranges: @shouldranges,
155
- geos: @shouldgeos
156
- )
157
- filters = Stretchy::Filters::AndFilter.new(filters) if filters.count > 1
158
- filters
159
74
  end
160
- end
161
75
 
162
- def build_filters(options = {})
163
- filters = []
164
- terms = Hash(options[:terms])
165
- ranges = Hash(options[:ranges])
166
- geos = Hash(options[:geos])
167
- near_fields = Hash(options[:near_fields])
168
- exists = Array(options[:exists])
169
-
170
- terms.each do |field, values|
171
- filters << Stretchy::Filters::TermsFilter.new(field, values)
76
+ def bool_filter
77
+ Stretchy::Filters::BoolFilter.new(
78
+ must: must.to_filters,
79
+ must_not: must_not.to_filters,
80
+ should: build_should
81
+ )
172
82
  end
173
-
174
- filters += exists.map do |field|
175
- Stretchy::Filters::ExistsFilter.new(field)
83
+
84
+ def and_filter
85
+ filter = nil
86
+ filters = must.to_filters
87
+ if filters.count > 1
88
+ filter = Stretchy::Filters::AndFilter.new(filters)
89
+ else
90
+ filter = filters.first
91
+ end
92
+ filter
176
93
  end
177
94
 
178
- filters += ranges.map do |field, value|
179
- Stretchy::Filters::RangeFilter.new(field: field, stretchy_range: value)
95
+ def not_filter
96
+ filter = must_not.to_filters
97
+ filter = Stretchy::Filters::OrFilter.new(filter) if filter.count > 1
98
+ Stretchy::Filters::NotFilter.new(filter)
180
99
  end
181
100
 
182
- filters += geos.map do |field, values|
183
- Stretchy::Filters::GeoFilter.new(
184
- field: field,
185
- distance: values[:distance],
186
- geo_point: values[:geo_point],
187
- lat: values[:lat],
188
- lng: values[:lng]
189
- )
101
+ def build_should
102
+ if should.any? && should_not.any?
103
+ Stretchy::Filters::BoolFilter.new(
104
+ must: should.to_filters,
105
+ must_not: should_not.to_filters
106
+ )
107
+ elsif should_not.any?
108
+ filters = should_not.to_filters
109
+ if filters.count > 1
110
+ filters = Stretchy::Filters::OrFilter.new(filters)
111
+ else
112
+ filters = filters.first
113
+ end
114
+
115
+ Stretchy::Filters::NotFilter.new(filters)
116
+ else
117
+ filters = should.to_filters
118
+ filters = Stretchy::Filters::AndFilter.new(filters) if filters.count > 1
119
+ filters
120
+ end
190
121
  end
191
- filters
192
122
  end
193
- end
194
123
  end
195
124
  end
@@ -1,3 +1,6 @@
1
+ require 'stretchy/builders/shell_builder'
2
+ require 'stretchy/builders/filter_builder'
3
+ require 'stretchy/builders/query_builder'
1
4
  require 'stretchy/builders/boost_builder'
2
5
  require 'stretchy/builders/match_builder'
3
6
  require 'stretchy/builders/where_builder'
@@ -16,11 +16,7 @@ module Stretchy
16
16
 
17
17
  extend Forwardable
18
18
 
19
- DEFAULT_LIMIT = 30
20
- DEFAULT_OFFSET = 0
21
-
22
- attr_accessor :match_builder, :where_builder, :boost_builder,
23
- :aggregate_builder, :inverse, :type, :index_name
19
+ attr_reader :base
24
20
 
25
21
  delegate [:request, :response, :results, :ids, :hits,
26
22
  :took, :shards, :total, :max_score, :total_pages] => :query_results
@@ -39,33 +35,16 @@ module Stretchy
39
35
  # @option base_or_opts [String] :index The Elastic index to query
40
36
  # @option base_or_opts [String] :type The Lucene type to query on
41
37
  # @option base_or_opts [true, false] :inverse Whether we are in a `not` context
42
- def initialize(base_or_opts = nil, options = {})
43
- if base_or_opts && !base_or_opts.is_a?(Hash)
44
- base = base_or_opts
45
- @index_name = base.index_name
46
- @type = base.type
47
- @match_builder = base.match_builder
48
- @where_builder = base.where_builder
49
- @boost_builder = base.boost_builder
50
- @aggregate_builder = base.aggregate_builder
51
- @inverse = options[:inverse]
52
- @limit = base.get_limit
53
- @offset = base.get_offset
54
- @explain = base.get_explain
55
- @fields = base.get_fields
38
+ def initialize(base = nil, options = {})
39
+ if base.is_a?(Builders::ShellBuilder)
40
+ @base = base
41
+ elsif base.nil?
42
+ @base = Builders::ShellBuilder.new
56
43
  else
57
- options = Hash(base_or_opts).merge(options)
58
- @index_name = options[:index] || Stretchy.index_name
59
- @type = options[:type]
60
- @match_builder = Stretchy::Builders::MatchBuilder.new
61
- @where_builder = Stretchy::Builders::WhereBuilder.new
62
- @boost_builder = Stretchy::Builders::BoostBuilder.new
63
- @aggregate_builder = {}
64
- @inverse = options[:inverse]
65
- @limit = DEFAULT_LIMIT
66
- @offset = DEFAULT_OFFSET
67
- @fields = nil
44
+ @base = Builders::ShellBuilder.new(base)
68
45
  end
46
+ @base.index ||= options[:index] || Stretchy.index_name
47
+ @base.type = options[:type] if options[:type]
69
48
  end
70
49
 
71
50
  #
@@ -78,7 +57,7 @@ module Stretchy
78
57
  #
79
58
  # @return [self]
80
59
  def limit(num)
81
- @limit = num
60
+ base.limit = num
82
61
  self
83
62
  end
84
63
 
@@ -87,7 +66,7 @@ module Stretchy
87
66
  #
88
67
  # @return [Integer] Value of `@limit`
89
68
  def get_limit
90
- @limit
69
+ base.limit
91
70
  end
92
71
  alias :limit_value :get_limit
93
72
 
@@ -101,7 +80,7 @@ module Stretchy
101
80
  #
102
81
  # @return [self]
103
82
  def offset(num)
104
- @offset = num
83
+ base.offset = num
105
84
  self
106
85
  end
107
86
  alias :per_page :offset
@@ -111,7 +90,7 @@ module Stretchy
111
90
  #
112
91
  # @return [Integer] Offset for query
113
92
  def get_offset
114
- @offset
93
+ base.offset
115
94
  end
116
95
 
117
96
  #
@@ -121,8 +100,8 @@ module Stretchy
121
100
  #
122
101
  # @return [self] Allows continuing the query chain
123
102
  def page(num, options = {})
124
- @limit = options[:limit] || options[:per_page] || @limit
125
- @offset = [(num - 1), 0].max.ceil * @limit
103
+ base.limit = options[:limit] || options[:per_page] || get_limit
104
+ base.offset = [(num - 1), 0].max.ceil * get_limit
126
105
  self
127
106
  end
128
107
 
@@ -131,7 +110,7 @@ module Stretchy
131
110
  #
132
111
  # @return [Integer] (offset / limit).ceil
133
112
  def get_page
134
- (@offset.to_f / @limit).ceil + 1
113
+ base.page
135
114
  end
136
115
  alias :current_page :get_page
137
116
 
@@ -150,8 +129,8 @@ module Stretchy
150
129
  #
151
130
  # @return [self] Allows continuing the query chain
152
131
  def fields(*args)
153
- @fields ||= []
154
- @fields += args.flatten if args.any?
132
+ base.fields ||= []
133
+ base.fields += args.flatten if args.any?
155
134
  self
156
135
  end
157
136
 
@@ -160,7 +139,7 @@ module Stretchy
160
139
  #
161
140
  # @return [Array] List of fields in the current query
162
141
  def get_fields
163
- @fields
142
+ base.fields
164
143
  end
165
144
 
166
145
  #
@@ -171,12 +150,12 @@ module Stretchy
171
150
  #
172
151
  # @return [self] Allows continuing the query chain
173
152
  def explain
174
- @explain = true
153
+ base.explain = true
175
154
  self
176
155
  end
177
156
 
178
157
  def get_explain
179
- !!@explain
158
+ !!base.explain
180
159
  end
181
160
 
182
161
  #
@@ -192,7 +171,7 @@ module Stretchy
192
171
  #
193
172
  # @see http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html Elastic Docs - Match Query
194
173
  def match(options = {})
195
- MatchClause.new(self, options)
174
+ MatchClause.new(base, options)
196
175
  end
197
176
  alias :fulltext :match
198
177
 
@@ -207,7 +186,7 @@ module Stretchy
207
186
  #
208
187
  # @see WhereClause#initialize
209
188
  def where(options = {})
210
- WhereClause.new(self, options)
189
+ WhereClause.new(base, options)
211
190
  end
212
191
  alias :filter :where
213
192
 
@@ -227,7 +206,7 @@ module Stretchy
227
206
  #
228
207
  # @see http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html Elastic Docs - Function Score Query
229
208
  def boost
230
- BoostClause.new(self)
209
+ BoostClause.new(base)
231
210
  end
232
211
 
233
212
  #
@@ -245,11 +224,11 @@ module Stretchy
245
224
  #
246
225
  # @return [Base] A {WhereClause}, or a {MatchClause} if only a string
247
226
  # is given (ie, doing a full-text search across the whole document)
248
- def not(opts_or_string = {}, opts = {})
227
+ def not(opts_or_string = {})
249
228
  if opts_or_string.is_a?(Hash)
250
- WhereClause.new(self).not(opts_or_string)
229
+ WhereClause.new(base).not(opts_or_string)
251
230
  else
252
- MatchClause.new(self).not(opts_or_string)
231
+ MatchClause.new(base).not(opts_or_string)
253
232
  end
254
233
  end
255
234
 
@@ -271,11 +250,11 @@ module Stretchy
271
250
  # @see http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html Elastic Docs - Bool Query
272
251
  #
273
252
  # @see http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-filter.html Elastic Docs - Bool Filter
274
- def should(opts_or_string = {}, opts = {})
253
+ def should(opts_or_string = {})
275
254
  if opts_or_string.is_a?(Hash)
276
- WhereClause.new(self).should(opts_or_string)
255
+ WhereClause.new(base).should(opts_or_string)
277
256
  else
278
- MatchClause.new(self).should(opts_or_string)
257
+ MatchClause.new(base).should(opts_or_string)
279
258
  end
280
259
  end
281
260
 
@@ -286,13 +265,13 @@ module Stretchy
286
265
  #
287
266
  # @return [self] Allows continuing the query chain
288
267
  def aggregations(opts = {})
289
- @aggregate_builder = @aggregate_builder.merge(opts)
268
+ base.aggregate_builder = base.aggregate_builder.merge(opts)
290
269
  self
291
270
  end
292
271
  alias :aggs :aggregations
293
272
 
294
273
  def get_aggregations
295
- @aggregate_builder
274
+ base.aggregate_builder
296
275
  end
297
276
  alias :get_aggs :get_aggregations
298
277
 
@@ -304,30 +283,6 @@ module Stretchy
304
283
  !!@inverse
305
284
  end
306
285
 
307
- #
308
- # Compiles the internal representation of your filters,
309
- # full-text queries, and boosts into the JSON to be
310
- # passed to Elastic. If you want to know exactly what
311
- # your query generated, you can call this method.
312
- #
313
- # @return [Hash] the query hash to be compiled to json
314
- # and sent to Elastic
315
- def to_search
316
- return @to_search if @to_search
317
-
318
- @to_search = if @where_builder.any?
319
- Stretchy::Queries::FilteredQuery.new(
320
- query: @match_builder.build,
321
- filter: @where_builder.build
322
- )
323
- else
324
- @match_builder.build
325
- end
326
-
327
- @to_search = @boost_builder.build(@to_search) if @boost_builder.any?
328
- @to_search = @to_search.to_search
329
- end
330
-
331
286
  #
332
287
  # The Results object for this query, which handles
333
288
  # sending the search request and providing convienent
@@ -335,7 +290,7 @@ module Stretchy
335
290
  #
336
291
  # @return [Results::Base] The results returned from Elastic
337
292
  def query_results
338
- @query_results ||= Stretchy::Results::Base.new(self)
293
+ @query_results ||= Stretchy::Results::Base.new(base)
339
294
  end
340
295
 
341
296
  end
@@ -45,7 +45,7 @@ module Stretchy
45
45
  #
46
46
  # @return [BoostMatchClause] query with boost match state
47
47
  def match(options = {})
48
- BoostMatchClause.new(self, options)
48
+ BoostMatchClause.new(base, options)
49
49
  end
50
50
  alias :fulltext :match
51
51
 
@@ -60,7 +60,7 @@ module Stretchy
60
60
  # @return [BoostWhereClause] Query state with boost filters applied
61
61
  #
62
62
  def where(options = {})
63
- BoostWhereClause.new(self, options)
63
+ BoostWhereClause.new(base, options)
64
64
  end
65
65
  alias :filter :where
66
66
 
@@ -125,8 +125,8 @@ module Stretchy
125
125
 
126
126
  options[:origin] = Stretchy::Types::GeoPoint.new(options)
127
127
  end
128
- @boost_builder.functions << Stretchy::Boosts::FieldDecayBoost.new(options)
129
- Base.new(self)
128
+ base.boost_builder.functions << Stretchy::Boosts::FieldDecayBoost.new(options)
129
+ Base.new(base)
130
130
  end
131
131
  alias :geo :near
132
132
 
@@ -141,8 +141,8 @@ module Stretchy
141
141
  #
142
142
  # @see http://www.elastic.co/guide/en/elasticsearch/guide/master/random-scoring.html Elastic Docs - Random Scoring
143
143
  def random(*args)
144
- @boost_builder.functions << Stretchy::Boosts::RandomBoost.new(*args)
145
- Base.new(self)
144
+ base.boost_builder.functions << Stretchy::Boosts::RandomBoost.new(*args)
145
+ Base.new(base)
146
146
  end
147
147
 
148
148
  #
@@ -152,7 +152,7 @@ module Stretchy
152
152
  #
153
153
  # @return [self] Boost context with overall boost applied
154
154
  def all(num)
155
- @boost_builder.overall_boost = num
155
+ base.boost_builder.overall_boost = num
156
156
  self
157
157
  end
158
158
 
@@ -163,7 +163,7 @@ module Stretchy
163
163
  #
164
164
  # @return [self] Boost context with maximum score applied
165
165
  def max(num)
166
- @boost_builder.max_boost = num
166
+ base.boost_builder.max_boost = num
167
167
  self
168
168
  end
169
169
 
@@ -175,7 +175,7 @@ module Stretchy
175
175
  #
176
176
  # @return [self] Boost context with score mode applied
177
177
  def score_mode(mode)
178
- @boost_builder.score_mode = mode
178
+ base.boost_builder.score_mode = mode
179
179
  self
180
180
  end
181
181
 
@@ -187,7 +187,7 @@ module Stretchy
187
187
  #
188
188
  # @return [self] Boost context with boost mode applied
189
189
  def boost_mode(mode)
190
- @boost_builder.boost_mode = mode
190
+ base.boost_builder.boost_mode = mode
191
191
  self
192
192
  end
193
193
 
@@ -72,7 +72,7 @@ module Stretchy
72
72
  #
73
73
  # @return [WhereClause] Query with where clause applied
74
74
  def where(*args)
75
- WhereClause.new(self, *args)
75
+ WhereClause.new(base, *args)
76
76
  end
77
77
 
78
78
  #
@@ -89,7 +89,7 @@ module Stretchy
89
89
  #
90
90
  # @return [MatchClause] Base context with match queries applied
91
91
  def match(*args)
92
- MatchClause.new(self, *args)
92
+ MatchClause.new(base, *args)
93
93
  end
94
94
 
95
95
  private
@@ -98,7 +98,7 @@ module Stretchy
98
98
  weight = options.delete(:weight)
99
99
  clause = MatchClause.tmp(options)
100
100
  boost = clause.to_boost(weight)
101
- @boost_builder.functions << boost if boost
101
+ base.boost_builder.functions << boost if boost
102
102
  end
103
103
 
104
104
  end
@@ -40,7 +40,7 @@ module Stretchy
40
40
  #
41
41
  # @return [WhereClause] Query with where clause applied
42
42
  def where(*args)
43
- WhereClause.new(self, *args)
43
+ WhereClause.new(base, *args)
44
44
  end
45
45
 
46
46
  #
@@ -57,7 +57,7 @@ module Stretchy
57
57
  #
58
58
  # @return [MatchClause] Base context with match queries applied
59
59
  def match(*args)
60
- MatchClause.new(self, *args)
60
+ MatchClause.new(base, *args)
61
61
  end
62
62
 
63
63
  #
@@ -73,7 +73,7 @@ module Stretchy
73
73
  # @return [Base] Query in base context with range boost applied
74
74
  def range(*args)
75
75
  where_function(:range, *args)
76
- Base.new(self)
76
+ Base.new(base)
77
77
  end
78
78
 
79
79
  #
@@ -93,7 +93,7 @@ module Stretchy
93
93
  # @return [Base] Query in base context with geo filter boost applied
94
94
  def geo(*args)
95
95
  where_function(:geo, *args)
96
- Base.new(self)
96
+ Base.new(base)
97
97
  end
98
98
 
99
99
  private
@@ -115,7 +115,7 @@ module Stretchy
115
115
  end
116
116
  boost = clause.to_boost(weight)
117
117
 
118
- @boost_builder.functions << boost if boost
118
+ base.boost_builder.functions << boost if boost
119
119
  end
120
120
  end
121
121
  end