Method: Scrivito::ObjSearchEnumerator#order

Defined in:
app/cms/scrivito/obj_search_enumerator.rb

#order(field_name) ⇒ Scrivito::ObjSearchEnumerator #order(field_and_direction) ⇒ Scrivito::ObjSearchEnumerator

Orders the results by field_name.

Applicable to the attribute types string, enum, integer, float and date.

There is a precision limit when sorting string values: Only the first 50 characters of a string are guaranteed to be considered when sorting search results.

Examples:

Sorting descending

Obj.all.order(_last_changed: :desc)

Overloads:

  • #order(field_name) ⇒ Scrivito::ObjSearchEnumerator

    Parameters:

    • field_name (Symbol, String)

      This parameter specifies the field by which the hits are sorted (e.g. :_path).

  • #order(field_and_direction) ⇒ Scrivito::ObjSearchEnumerator

    Parameters:

    • field_and_direction (Hash)

      The field name and sort direction can be specfied as the key and value of a hash. Valid directions are :asc and :desc. The default is :asc.

Returns:



362
363
364
365
366
367
368
369
370
371
372
373
# File 'app/cms/scrivito/obj_search_enumerator.rb', line 362

def order(field_name)
  field_name, direction = if field_name.is_a?(Hash)
    field_name.to_a.first
  else
    [field_name, :asc]
  end

  options[:sort_by] = field_name
  options[:sort_order] = direction.to_sym

  self
end