Sorting issues, can anyone help me?

I have this model:

class Post < ActiveRecord::Base

acts_as_ferret :fields => { :title => {:boost => 2},
:description => {},
:url => {},
:rank_sort => {:index =>
:untokenized_omit_norms, :term_vector => :no},
:posted_at_sort => {:index =>
:untokenized_omit_norms, :term_vector => :no}
}, :remote => true

belongs_to :blog

def rank_sort
begin
return self.blog.rank_links.to_i
rescue
return nil
end
end

def posted_at_sort
begin
return self.posted_at.to_i
rescue
return nil
end
end

end

But when I try to sort by :rank_sort or :posted_at_sort it didn’t work,
see:

h,r = Post.full_text_search(“voltamos”, {:sort => Ferret::Search::SortField.new(:rank_sort, :reverse => false)} )[1].first.posted_at_sort
=> [1146857920]

h,r = Post.full_text_search(“voltamos”, {:sort => Ferret::Search::SortField.new(:rank_sort, :reverse => false)} )[1].last.posted_at_sort
=> [1085549830]

h,r = Post.full_text_search(“voltamos”, {:sort => Ferret::Search::SortField.new(:rank_sort, :reverse => true)} )[1].last.posted_at_sort
=> [1085549830]

h,r = Post.full_text_search(“voltamos”, {:sort => Ferret::Search::SortField.new(:rank_sort, :reverse => true)} )[1].first.posted_at_sort
=> [1146857920]

h,r = Post.full_text_search(“voltamos”, {:sort => Ferret::Search::SortField.new(:rank_sort, :reverse => :true)} )[1].first.posted_at_sort
=> [1146857920]

h,r = Post.full_text_search(“voltamos”, {:sort => Ferret::Search::SortField.new(:rank_sort, :reverse => :false)} )[1].first.posted_at_sort
=> [1146857920]

h,r = Post.full_text_search(“voltamos”, {:sort => Ferret::Search::SortField.new(“rank_sort”, :reverse => :false)} )[1].first.posted_at_sort
=> [1146857920]

h,r = Post.full_text_search(“voltamos”, {:sort => Ferret::Search::SortField.new(“rank_sort”, :reverse => false)} )[1].first.posted_at_sort
=> [1146857920]

h,r = Post.full_text_search(“voltamos”, {:sort => Ferret::Search::SortField.new(“rank_sort”, :reverse => true)} )[1].first.posted_at_sort
=> [1146857920]

h,r = Post.full_text_search(“voltamos”, {:sort => Ferret::Search::SortField.new(“rank_sort”, :reverse => :true)} )[1].first.posted_at_sort
=> [1146857920]

h,r = Post.full_text_search(“voltamos”, {:sort => Ferret::Search::SortField.new(“rank_sort”, :reverse => :yes)} )[1].first.posted_at_sort
=> [1146857920]

h,r = Post.full_text_search(“voltamos”, {:sort => Ferret::Search::SortField.new(“rank_sort”, :reverse => :no)} )[1].first.posted_at_sort
=> [1146857920]

h,r = Post.full_text_search(“voltamos”, {:sort => Ferret::Search::SortField.new(“rank_sort”, :reverse => :no)} )[1].last.posted_at_sort
=> [1085549830]

Can anyone help me with this?

[]s

Manoel

On Sat, Mar 31, 2007 at 03:45:40PM +0200, Manoel L. wrote:

:untokenized_omit_norms, :term_vector => :no}
}, :remote => true

belongs_to :blog

[…]

h,r = Post.full_text_search(“voltamos”, {:sort => Ferret::Search::SortField.new(“rank_sort”, :reverse => :no)} )[1].last.posted_at_sort
=> [1085549830]

First of all, use symbols for your field name (don’t know if that
solves the problem, but you should use symbols for fieldnames
everywhere).

Then, try to give an array of sort fieldsas value of the :sort
parameter, and specify the correct type for your integer fields. So to
sort by rank_sort, descending, do:

:sort => [ Ferret::Search::SortField.new(:rank_sort, :type => :integer,
:reverse => true) ]

Jens


Jens Krämer
webit! Gesellschaft für neue Medien mbH
Schnorrstraße 76 | 01069 Dresden
Telefon +49 351 46766-0 | Telefax +49 351 46766-66
[email protected] | www.webit.de

Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa

Jens, so this is the correct way to define the fields:

:rank_sort => {:index => :untokenized_omit_norms, :term_vector => :no}

since rank_sort is like this:

def rank_sort
return self.rank_links.to_i if !self.rank_links.blank? and
self.rank_links > 0
return 999999999
end

On Sun, Apr 01, 2007 at 07:21:16PM +0200, Manoel L. wrote:

Jens, so this is the correct way to define the fields:

:rank_sort => {:index => :untokenized_omit_norms, :term_vector => :no}

since rank_sort is like this:

def rank_sort
return self.rank_links.to_i if !self.rank_links.blank? and self.rank_links > 0
return 999999999
end

yeah, looks ok.

Jens


Jens Krämer
webit! Gesellschaft für neue Medien mbH
Schnorrstraße 76 | 01069 Dresden
Telefon +49 351 46766-0 | Telefax +49 351 46766-66
[email protected] | www.webit.de

Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa