Skip to content

Commit 275f522

Browse files
committed
Merge branch 'excluded-end-range'
2 parents 5f769ba + 0b5160c commit 275f522

File tree

2 files changed

+32
-21
lines changed

2 files changed

+32
-21
lines changed

sunspot/lib/sunspot/query/restriction.rb

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ class <<self
77
# available to the DSL.
88
#
99
# ==== Returns
10-
#
10+
#
1111
# Array:: Collection of restriction class names
1212
#
1313
def names
1414
constants - abstract_constants
1515
end
1616

17-
#
17+
#
1818
# Convenience method to access a restriction class by an underscored
1919
# symbol or string
2020
#
@@ -35,7 +35,7 @@ def abstract_constants
3535
end
3636
end
3737

38-
#
38+
#
3939
# Subclasses of this class represent restrictions that can be applied to
4040
# a Sunspot query. The Sunspot::DSL::Restriction class presents a builder
4141
# API for instances of this class.
@@ -57,7 +57,7 @@ def initialize(negated, field, value)
5757
@negated, @field, @value = negated, field, value
5858
end
5959

60-
#
60+
#
6161
# A hash representing this restriction in solr-ruby's parameter format.
6262
# All restriction implementations must respond to this method; however,
6363
# the base implementation delegates to the #to_positive_boolean_phrase method, so
@@ -72,7 +72,7 @@ def to_params
7272
{ :fq => [to_filter_query] }
7373
end
7474

75-
#
75+
#
7676
# Return the boolean phrase associated with this restriction object.
7777
# Differentiates between positive and negated boolean phrases depending
7878
# on whether this restriction is negated.
@@ -88,7 +88,7 @@ def to_boolean_phrase
8888
@field.local_params(value) : value
8989
end
9090

91-
#
91+
#
9292
# Boolean phrase representing this restriction in the positive. Subclasses
9393
# may choose to implement this method rather than #to_params; however,
9494
# this method delegates to the abstract #to_solr_conditional method, which
@@ -105,7 +105,7 @@ def to_positive_boolean_phrase
105105
"#{Util.escape(@field.indexed_name)}:#{to_solr_conditional}"
106106
end
107107

108-
#
108+
#
109109
# Boolean phrase representing this restriction in the negated. Subclasses
110110
# may choose to implement this method, but it is not necessary, as the
111111
# base implementation delegates to #to_positive_boolean_phrase.
@@ -118,14 +118,14 @@ def to_negated_boolean_phrase
118118
"-#{to_positive_boolean_phrase}"
119119
end
120120

121-
#
121+
#
122122
# Whether this restriction should be negated from its original meaning
123123
#
124124
def negated? #:nodoc:
125125
!!@negated
126126
end
127127

128-
#
128+
#
129129
# Return a new restriction that is the negated version of this one. It
130130
# is used by disjunction denormalization.
131131
#
@@ -184,7 +184,7 @@ def to_solr_conditional
184184
end
185185
end
186186

187-
#
187+
#
188188
# Results must have field with value equal to given value. If the value
189189
# is nil, results must have no value for the given field.
190190
#
@@ -213,7 +213,7 @@ def to_solr_conditional
213213
end
214214
end
215215

216-
#
216+
#
217217
# Results must have field with value less than given value
218218
#
219219
class LessThan < Base
@@ -230,7 +230,7 @@ def to_solr_conditional
230230
end
231231
end
232232

233-
#
233+
#
234234
# Results must have field with value less or equal to than given value
235235
#
236236
class LessThanOrEqualTo < Base
@@ -247,7 +247,7 @@ def to_solr_conditional
247247
end
248248
end
249249

250-
#
250+
#
251251
# Results must have field with value greater than given value
252252
#
253253
class GreaterThan < Base
@@ -264,7 +264,7 @@ def to_solr_conditional
264264
end
265265
end
266266

267-
#
267+
#
268268
# Results must have field with value greater than or equal to given value
269269
#
270270
class GreaterThanOrEqualTo < Base
@@ -281,7 +281,7 @@ def to_solr_conditional
281281
end
282282
end
283283

284-
#
284+
#
285285
# Results must have field with value in given range
286286
#
287287
class Between < Base
@@ -294,11 +294,15 @@ def solr_value(value = @value)
294294
end
295295

296296
def to_solr_conditional
297-
"[#{solr_value(@value.first)} TO #{solr_value(@value.last)}]"
297+
if @value.exclude_end?
298+
"[#{solr_value(@value.first)} TO #{solr_value(@value.last)}}"
299+
else
300+
"[#{solr_value(@value.first)} TO #{solr_value(@value.last)}]"
301+
end
298302
end
299303
end
300304

301-
#
305+
#
302306
# Results must have field with value included in given collection
303307
#
304308
class AnyOf < Base
@@ -339,7 +343,7 @@ def negated?
339343
super
340344
end
341345
end
342-
346+
343347
private
344348

345349
def to_solr_conditional
@@ -351,7 +355,7 @@ def to_solr_conditional
351355
end
352356
end
353357

354-
#
358+
#
355359
# Results must have a field with a value that begins with the argument.
356360
# Most useful for strings, but in theory will work with anything.
357361
#

sunspot/spec/api/query/scope_examples.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
'expire_date_d:1983\-07\-08T00\:00\:00Z'
3535
)
3636
end
37-
37+
3838
it 'scopes by exact match with boolean' do
3939
search do
4040
with :featured, false
@@ -63,6 +63,13 @@
6363
expect(connection).to have_last_search_including(:fq, 'average_rating_ft:{3\.0 TO *}')
6464
end
6565

66+
it 'scopes by between match with excluded end float range' do
67+
search do
68+
with(:average_rating).between 2.0...3.0
69+
end
70+
expect(connection).to have_last_search_including(:fq, 'average_rating_ft:[2\.0 TO 3\.0}')
71+
end
72+
6673
it 'scopes by short-form between match with integers' do
6774
search do
6875
with :blog_id, 2..4
@@ -125,7 +132,7 @@
125132
end
126133
expect(connection).to have_last_search_including(:fq, '-average_rating_ft:{3\.0 TO *}')
127134
end
128-
135+
129136
it 'scopes by not between match with shorthand' do
130137
search do
131138
without(:blog_id, 2..4)

0 commit comments

Comments
 (0)