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. Care should be taken however 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 sort by string.

Example

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

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

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

TODO: currently unsupported

Returns the name of the field to be sorted.

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

Return a human readable string describing this sort_field.

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

[Validate]