# Ferret - sorting results by score

**URL:** <https://www.ruby-forum.com/t/ferret-sorting-results-by-score/118570>\
**Category:** Rails\
**Created:** [October 29, 2007, 2:34am UTC](https://www.ruby-forum.com/t/ferret-sorting-results-by-score/118570 "2007-10-29T02:34:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c57346/32.png) [@sjames](https://www.ruby-forum.com/u/sjames)\
**Post date:** [October 29, 2007, 2:34am UTC](https://www.ruby-forum.com/t/ferret-sorting-results-by-score/118570/1 "2007-10-29T02:34:13Z")

</div>

I am trying to figure out how to sort my results by the score Ferret is  
returning. From the results of a search, I use the ids to then look  
up their corresponding records in the database. The reason for this is  
that the database records contain more information than I am storing in  
the index. Any ideas? Code example below. Thanks in advance!

def index  
if (params[:q])  
@search\_results = Array.new

```
  index = FerretConfig::INDEX
  index.search_each(params[:q]) do |doc, score|
    @search_results << index[doc][:id]
  end

  @quotes = Quote.find(@search_results)
end

```

end
