Does sort work for strings work?

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

Hey …

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

Hope that helps :slight_smile:

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
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk

Gruss
Ben

Benjamin K.


[email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs