Class: SunspotMatchers::OrderByMatcher

Inherits:
BaseMatcher show all
Defined in:
lib/sunspot_matchers/matchers.rb

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?

Constructor Details

This class inherits a constructor from SunspotMatchers::BaseMatcher

Instance Method Details

#argsObject



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_searchObject



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

Returns:

  • (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

Returns:

  • (Boolean)


244
245
246
# File 'lib/sunspot_matchers/matchers.rb', line 244

def field_wildcard?
  @args.first == any_param
end

#keys_to_compareObject



233
234
235
# File 'lib/sunspot_matchers/matchers.rb', line 233

def keys_to_compare
  [:sort]
end

#search_methodObject



229
230
231
# File 'lib/sunspot_matchers/matchers.rb', line 229

def search_method
  :order_by
end

#wildcard_matcher_for_keysObject



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