### Home Classes Methods

### In Files

- ext/r_search.c

### Parent

Object

### Methods

- ::new
- #fields
- #to_s

### Files

- MIT-LICENSE
- README
- TODO
- TUTORIAL

### Class/Module Index

Quicksearch

- Ferret
- Ferret::Analysis
- Ferret::Analysis::Analyzer
- Ferret::Analysis::AsciiLetterAnalyzer
- Ferret::Analysis::AsciiLetterTokenizer
- Ferret::Analysis::AsciiLowerCaseFilter
- Ferret::Analysis::AsciiStandardAnalyzer
- Ferret::Analysis::AsciiStandardTokenizer
- Ferret::Analysis::AsciiWhiteSpaceAnalyzer
- Ferret::Analysis::AsciiWhiteSpaceTokenizer
- Ferret::Analysis::HyphenFilter
- Ferret::Analysis::LetterAnalyzer
- Ferret::Analysis::LetterTokenizer
- Ferret::Analysis::LowerCaseFilter
- Ferret::Analysis::MappingFilter
- Ferret::Analysis::PerFieldAnalyzer
- Ferret::Analysis::RegExpAnalyzer
- Ferret::Analysis::RegExpTokenizer
- Ferret::Analysis::StandardAnalyzer
- Ferret::Analysis::StandardTokenizer
- Ferret::Analysis::StemFilter
- Ferret::Analysis::StopFilter
- Ferret::Analysis::Token
- Ferret::Analysis::TokenStream
- Ferret::Analysis::WhiteSpaceAnalyzer
- Ferret::Analysis::WhiteSpaceTokenizer
- Ferret::BlankSlate
- Ferret::BoostMixin
- Ferret::Browser
- Ferret::Browser::Controller
- Ferret::Browser::Delegator
- Ferret::Browser::DocumentController
- Ferret::Browser::ErrorController
- Ferret::Browser::HelpController
- Ferret::Browser::HomeController
- Ferret::Browser::TermController
- Ferret::Browser::TermVectorController
- Ferret::Browser::ViewHelper
- Ferret::Document
- Ferret::Field
- Ferret::FieldSymbol
- Ferret::FieldSymbolMethods
- Ferret::FileNotFoundError
- Ferret::Index
- Ferret::Index::FieldInfo
- Ferret::Index::FieldInfos
- Ferret::Index::Index
- Ferret::Index::IndexReader
- Ferret::Index::IndexWriter
- Ferret::Index::LazyDoc
- Ferret::Index::LazyDoc::LazyDocData
- Ferret::Index::TermDocEnum
- Ferret::Index::TermEnum
- Ferret::Index::TermVector
- Ferret::Index::TermVector::TVOffsets
- Ferret::Index::TermVector::TVTerm
- Ferret::ParseError
- Ferret::QueryParser
- Ferret::QueryParser::QueryParseException
- Ferret::Search
- Ferret::Search::BooleanQuery
- Ferret::Search::BooleanQuery::BooleanClause
- Ferret::Search::ConstantScoreQuery
- Ferret::Search::Explanation
- Ferret::Search::Filter
- Ferret::Search::FilteredQuery
- Ferret::Search::FuzzyQuery
- Ferret::Search::Hit
- Ferret::Search::MatchAllQuery
- Ferret::Search::MultiSearcher
- Ferret::Search::MultiTermQuery
- Ferret::Search::PhraseQuery
- Ferret::Search::PrefixQuery
- Ferret::Search::Query
- Ferret::Search::QueryFilter
- Ferret::Search::RangeFilter
- Ferret::Search::RangeQuery
- Ferret::Search::Searcher
- Ferret::Search::Sort
- Ferret::Search::SortField
- Ferret::Search::Spans
- Ferret::Search::Spans::SpanFirstQuery
- Ferret::Search::Spans::SpanMultiTermQuery
- Ferret::Search::Spans::SpanNearQuery
- Ferret::Search::Spans::SpanNotQuery
- Ferret::Search::Spans::SpanOrQuery
- Ferret::Search::Spans::SpanPrefixQuery
- Ferret::Search::Spans::SpanTermQuery
- Ferret::Search::TermQuery
- Ferret::Search::TopDocs
- Ferret::Search::TypedRangeFilter
- Ferret::Search::TypedRangeQuery
- Ferret::Search::WildcardQuery
- Ferret::StateError
- Ferret::Store
- Ferret::Store::Directory
- Ferret::Store::FSDirectory
- Ferret::Store::Lock
- Ferret::Store::Lock::LockError
- Ferret::Store::RAMDirectory
- Ferret::Utils
- Ferret::Utils::BitVector
- Ferret::Utils::MultiMapper
- Ferret::Utils::PriorityQueue
- WEBrick
- WEBrick::FerretBrowserHandler
- Date
- DateTime
- FileUtils
- Float
- Integer
- String
- Symbol
- Time

No matching classes.

# Ferret::Search::Sort

## Summary

A Sort object is used to combine and apply a list of SortFields. The SortFields are applied in the order they are added to the SortObject.

## Example

Here is how you would create a Sort object that sorts first by rating and then by title;

    sf_rating = SortField.new(:rating, :type => :float, :reverse => true)
    sf_title = SortField.new(:title, :type => :string)
    sort = Sort.new([sf_rating, sf_title])

Remember that the :type parameter for SortField is set to :auto be default be I strongly recommend you specify a :type value.

### Constants

INDEX_ORDER
RELEVANCE

### Public Class Methods

new(sort_fields = [SortField::SCORE, SortField::DOC_ID], reverse = false) → Sort click to toggle source

Create a new Sort object. If `reverse` is true, all sort_fields will be reversed so if any of them are already reversed the will be turned back to their natural order again. By default

    static VALUE
    frb_sort_init(int argc, VALUE *argv, VALUE self)
    {
        int i;
        VALUE rfields, rreverse;
        bool reverse = false;
        bool has_sfd = false;
        GET_SORT();
        switch (rb_scan_args(argc, argv, "02", &rfields, &rreverse)) {
            case 2: reverse = RTEST(rreverse);
            case 1:
                    if (TYPE(rfields) == T_ARRAY) {
                        int i;
                        for (i = 0; i < RARRAY_LEN(rfields); i++) {
                            frb_sort_add(sort, RARRAY_PTR(rfields)[i], reverse);
                        }
                    } else {
                        frb_sort_add(sort, rfields, reverse);
                    }
                    for (i = 0; i < sort->size; i++) {
                        if (sort->sort_fields[i] == &SORT_FIELD_DOC) has_sfd = true;
                    }
                    if (!has_sfd) {
                        sort_add_sort_field(sort, (SortField *)&SORT_FIELD_DOC);
                    }
                    break;
            case 0:
                    sort_add_sort_field(sort, (SortField *)&SORT_FIELD_SCORE);
                    sort_add_sort_field(sort, (SortField *)&SORT_FIELD_DOC);
        }

        return self;
    }

### Public Instance Methods

fields → Array click to toggle source

Returns an array of the SortFields held by the Sort object.

    static VALUE
    frb_sort_get_fields(VALUE self)
    {
        GET_SORT();
        VALUE rfields = rb_ary_new2(sort->size);
        int i;
        for (i = 0; i < sort->size; i++) {
            rb_ary_store(rfields, i, object_get(sort->sort_fields[i]));
        }
        return rfields;
    }

to_s → string click to toggle source

Returns a human readable string representing the sort object.

    static VALUE
    frb_sort_to_s(VALUE self)
    {
        GET_SORT();
        char *str = sort_to_s(sort);
        VALUE rstr = rb_str_new2(str);
        free(str);
        return rstr;
    }

[Validate]

Generated with the Darkfish Rdoc Generator 2.