Forum: Ferret Sorting the Result

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
53bfdeaf60a203c7e40f90117e2b2ca6?d=identicon&s=25 P L Patodia (Guest)
on 2006-03-01 16:19
The document describes
search(query, options)
sort: An array of SortFields describing how to sort the results.

I have created index with two fields: 'file' and 'content'

When I give SortField name as 'file' while searching, it results into

The exact command given by me:
index.search_each("sleepless AND dreams", :num_docs => 100, :sort =>
    do |doc, score|

My question is how do I give field name for sorting.

Thanks and Regards,

P L Patodia
22580f640e491f0920a192610d1df393?d=identicon&s=25 Tom Davies (Guest)
on 2006-03-01 16:22
(Received via mailing list)
I believe your sort field needs to be a Ferret::Search::SortField

Here is how I am sorting (with two fields).  You might be able to do
it without the array and just passing in a Ferret::Search::SortField
to :sort.  I haven't tried that though.

    sort_fields = []
    sort_fields <<'created_at')
    sort_fields <<'url')
    INDEX.search_each(query, {:sort => sort_fields}) do |doc, score|

B5e329ffa0cc78efbfc7ae2d084c149f?d=identicon&s=25 David Balmain (Guest)
on 2006-03-02 02:59
(Received via mailing list)
On 3/2/06, Tom Davies <> wrote:
> Tom

You may also want to specify the sort type. For example;

     include Ferret::Search
     sort_fields = []
     sort_fields <<'created_at',
                                          :sort_type =>
     sort_fields <<'url',
                                          :sort_type =>
     INDEX.search_each(query, {:sort => sort_fields}) do |doc, score|

Although, now that I think about it, it would be nice if you could
just pass the search method a string or array of strings. Expect to
see this functionality in the future.

This topic is locked and can not be replied to.