# Does sort work for strings work?

**URL:** <https://www.ruby-forum.com/t/does-sort-work-for-strings-work/124163>\
**Category:** Ferret\
**Created:** [December 25, 2007, 10:55pm UTC](https://www.ruby-forum.com/t/does-sort-work-for-strings-work/124163 "2007-12-25T22:55:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bunny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3d9bf3/32.png) [@bunny](https://www.ruby-forum.com/u/bunny)\
**Post date:** [December 25, 2007, 10:55pm UTC](https://www.ruby-forum.com/t/does-sort-work-for-strings-work/124163/1 "2007-12-25T22:55:26Z")

</div>

Hi,

I am trying to get sorting working. I have had success with numbers  
but when I try to sort my string fields nothing happens. I am using  
the following code:

options = {}  
s = Search::SortField.new(‘object\_title’, :reverse =\> false)  
options[:sort] = s  
@index.search\_each(“my query”,options) do |id, score|  
puts “–\>Document #{id} found with a score of #{score}”  
p @index[id].load  
end

output:

–\>Document 0 found with a score of 0.0534844100475311  
{:date=\>“2004-01-01”, :object\_title=\>“This is the first  
title”, :title=\>“1”, :page=\>“1”, :object\_content=\>“This is the first  
content”}  
–\>Document 1 found with a score of 0.0534844100475311  
{:date=\>“2005-01-01”, :object\_title=\>“This is the second  
title”, :title=\>“2”, :page=\>“1”, :object\_content=\>“This is the second  
content”}  
–\>Document 2 found with a score of 0.0534844100475311  
{:date=\>“2006-01-01”, :object\_title=\>“This is the third  
title”, :title=\>“3”, :page=\>“1”, :object\_content=\>“This is the third  
content”}  
–\>Document 3 found with a score of 0.0534844100475311  
{:date=\>“2007-01-01”, :object\_title=\>“This is the fourth  
title”, :title=\>“4”, :page=\>“1”, :object\_content=\>“This is the fourth  
content”}  
–\>Document 4 found with a score of 0.0534844100475311  
{:date=\>“2008-01-01”, :object\_title=\>“This is the fifth  
title”, :title=\>“5”, :page=\>“1”, :object\_content=\>“This is the fifth  
content”}

Notice it is not sorted by object\_title! Any help would be greatly  
appreciated.

Benjamin

---

<div class="post-metadata">

**Author:** ![bunny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3d9bf3/32.png) [@bunny](https://www.ruby-forum.com/u/bunny)\
**Post date:** [December 27, 2007, 11:30pm UTC](https://www.ruby-forum.com/t/does-sort-work-for-strings-work/124163/2 "2007-12-27T23:30:24Z")

</div>

Hey …

see  
[http://ferret.davebalmain.com/trac/wiki/FAQ%3ASearching#HowcanIsorttheresults](http://ferret.davebalmain.com/trac/wiki/FAQ%3ASearching#HowcanIsorttheresults)

Hope that helps 🙂

Ben

On 2007-12-25, at 22:53, Benjamin A. wrote:

> ```
> puts "-->Document #{id} found with a score of #{score}"
> 
> ```
> 
> {:date=\>“2005-01-01”, :object\_title=\>"This is the second  
> –\>Document 4 found with a score of 0.0534844100475311  
> removed\_email\_address@domain.invalid  
> [http://rubyforge.org/mailman/listinfo/ferret-talk](http://rubyforge.org/mailman/listinfo/ferret-talk)

## Gruss Ben

Benjamin K.

> **[Willkommen @ omdb](https://www.omdb.org/de/us)**
>
> Willkommen bei omdb, die freie Filmdatenbank, an der jeder mitarbeiten kann. In der Open Media Database findest du Einträge zu tausenden Filmen, Serien und Schauspielern.

removed\_email\_address@domain.invalid
