Class | Ferret::Search::SortField
In: | ext/r_search.c
Parent: | Object

## Summary

A SortField is used to sort the result-set of a search be the contents of a field. The following types of sort_field are available;

- :auto
- :integer
- :float
- :string
- :byte
- :doc_id
- :score

The type of the SortField is set by passing it as a parameter to the constructor. The +:auto+ type specifies that the SortField should detect the sort type by looking at the data in the field. This is the default :type value although it is recommended that you explicitly specify the fields type.

## Example

      title_sf = SortField.new(:title, :type => :string)
      rating_sf = SortField.new(:rating, :type => float, :reverse => true)

Note 1: Care should be taken when using the :auto sort-type since numbers will occur before other strings in the index so if you are sorting a field with both numbers and strings (like a title field which might have "24" and "Prison Break") then the sort_field will think it is sorting integers when it really should be sorting strings.

Note 2: When sorting by integer, integers are only 4 bytes so anything larger will cause strange sorting behaviour.

### Methods

comparator name new reverse? to_s type

### Constants

SCORE | = | Data_Wrap_Struct(cSortField, NULL, &frt_deref_free, (SortField *)&SORT_FIELD_SCORE)
SCORE_REV | = | Data_Wrap_Struct(cSortField, NULL, &frt_deref_free, (SortField *)&SORT_FIELD_SCORE_REV)
DOC_ID | = | Data_Wrap_Struct(cSortField, NULL, &frt_deref_free, (SortField *)&SORT_FIELD_DOC)
DOC_ID_REV | = | Data_Wrap_Struct(cSortField, NULL, &frt_deref_free, (SortField *)&SORT_FIELD_DOC_REV)

### Public Class methods

SortField.new(field, options = {}) → sort_field

Create a new SortField which can be used to sort the result-set by the value in field `field`.

### Options

:type:

Default: +:auto+. Specifies how a field should be sorted. Choose from one of; +:auto+, +:integer+, +:float+, +:string+, +:byte+, +:doc_id+ or +:score+. +:auto+ will check the datatype of the field by trying to parse it into either a number or a float before settling on a string sort. String sort is locale dependent and works for multibyte character sets like UTF-8 if you have your locale set correctly.

:reverse Default: false. Set to true if you want to reverse the

                    sort.

### Public Instance methods

sort_field.comparator → symbol

TODO: currently unsupported

sort_field.name → symbol

Returns the name of the field to be sorted.

sort_field.reverse? → bool

Return true if the field is to be reverse sorted. This attribute is set when you create the sort_field.

sort_field.to_s → string

Return a human readable string describing this `sort_field`.

sort_field.type → symbol

Return the type of sort. Should be one of; +:auto+, +:integer+, +:float+, +:string+, +:byte+, +:doc_id+ or +:score+.

[Validate]