Class: SunspotMatchers::OrderByMatcher
Instance Method Summary
collapse
Methods inherited from BaseMatcher
#actual_params, #actual_search, #compare_key, #compare_multi_value, #compare_single_value, #comparison_matcher_for_key, #comparison_params, #differences, #field, #filter_values, #initialize, #match?, #missing_param_error_message, #query_params_for_search, #search_tuple, #search_types, #unexpected_match_error_message, #wildcard?
Instance Method Details
#args ⇒ Object
252
253
254
255
|
# File 'lib/sunspot_matchers/matchers.rb', line 252
def args
return @args unless direction_wildcard?
@args[0...-1] + [:asc]
end
|
#build_comparison_search ⇒ Object
257
258
259
260
261
262
263
264
265
266
267
|
# File 'lib/sunspot_matchers/matchers.rb', line 257
def build_comparison_search
if field_wildcard?
@comparison_params = {:sort => any_param}
elsif direction_wildcard?
super
@comparison_params = comparison_params
@comparison_params[:sort].gsub!("asc", any_param)
else
super
end
end
|
#direction_wildcard? ⇒ Boolean
248
249
250
|
# File 'lib/sunspot_matchers/matchers.rb', line 248
def direction_wildcard?
@args.length == 2 && @args.last == any_param
end
|
#field_wildcard? ⇒ Boolean
244
245
246
|
# File 'lib/sunspot_matchers/matchers.rb', line 244
def field_wildcard?
@args.first == any_param
end
|
#keys_to_compare ⇒ Object
233
234
235
|
# File 'lib/sunspot_matchers/matchers.rb', line 233
def keys_to_compare
[:sort]
end
|
#search_method ⇒ Object
229
230
231
|
# File 'lib/sunspot_matchers/matchers.rb', line 229
def search_method
:order_by
end
|
#wildcard_matcher_for_keys ⇒ Object
237
238
239
240
241
242
|
# File 'lib/sunspot_matchers/matchers.rb', line 237
def wildcard_matcher_for_keys
return {:sort => /./} if field_wildcard?
param = comparison_params[:sort]
regex = Regexp.new(param.gsub(any_param, '.*'))
{:sort => regex}
end
|