ghost
October 16, 2006, 5:25pm
1
Hi I think this is a very easy question but here goes:
I want to sort my results by a boolean field and then by score, I
thought this would be a default configuration but apparently not.
sort_fields = []
sort_fields << Ferret::Search::SortField.new(:sponsored, :reverse =>
:true)
that is my current code, how do iu alter it so that the results are then
sorted by highest score first?
thanks very much.
regards
caspar
ghost
October 16, 2006, 8:23pm
2
On 10/17/06, Caspar Bl [email protected] wrote:
Hi I think this is a very easy question but here goes:
I want to sort my results by a boolean field and then by score, I
thought this would be a default configuration but apparently not.
> [this] is my current code, how do iu alter it so that the results are then
> sorted by highest score first?
>
> sort_fields = []
> sort_fields <
> :true)
sort_fields << Ferret::Search::SortField::SCORE
sort = Ferret::Search::Sort.new(sort_fields)
You can pass the array of SortFields as the :sort parameter or even a
sort string (“sponsored DESC, SCORE”).
Cheers,
Dave
ghost
May 18, 2007, 7:53pm
3
sort_fields << Ferret::Search::SortField::SCORE
sort = Ferret::Search::Sort.new(sort_fields)
You can pass the array of SortFields as the :sort parameter or even a
sort string (“sponsored DESC, SCORE”).
maybe i’m just a total noob, but where can i put this?
here’s my search mothod …
@results = Record.multi_search(params[:search_terms], [ Link, Post
], {:limit => :all})
hope that makes any sense
Jon
ghost
May 18, 2007, 8:05pm
4
On Fri, May 18, 2007 at 07:53:39PM +0200, Jon D. wrote:
here’s my search mothod …
@results = Record.multi_search(params[:search_terms], [ Link, Post
], {:limit => :all})
the :sort option belongs to the same hash as :limit.
here’s a sample from the aaf unit tests:
sorting = [ Ferret::Search::SortField.new(:id) ]
result = Content.multi_search(‘*:title OR *:comment’,
[Comment],
:sort => sorting)
note that I don’t use the Sort class at all, an Array of SortFields is
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
ghost
May 21, 2007, 11:01am
5
On Fri, May 18, 2007 at 08:56:07PM +0200, Jon D. wrote:
here’s a sample from the aaf unit tests:
sorry i’m so lame… i though we were sorting by score? my results
don’t seem to change when i put that in there.
my fault, I just cut’n’pasted the code from the test.
replace the
sorting = …
line with:
sorting = [ Ferret::Search::SortField::SCORE ]
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
ghost
May 18, 2007, 8:56pm
6
Jens K. wrote:
On Fri, May 18, 2007 at 07:53:39PM +0200, Jon D. wrote:
here’s my search mothod …
@results = Record.multi_search(params[:search_terms], [ Link, Post
], {:limit => :all})
the :sort option belongs to the same hash as :limit.
here’s a sample from the aaf unit tests:
sorting = [ Ferret::Search::SortField.new(:id) ]
result = Content.multi_search(’*:title OR *:comment’,
[Comment],
:sort => sorting)
note that I don’t use the Sort class at all, an Array of SortFields is
ok.
sorry i’m so lame… i though we were sorting by score? my results
don’t seem to change when i put that in there.
Jon
ghost
May 21, 2007, 9:02pm
7
Jens K. wrote:
my fault, I just cut’n’pasted the code from the test.
replace the
sorting = …
line with:
sorting = [ Ferret::Search::SortField::SCORE ]
so i must be giving you a headache. when i put this in
sort = [ Ferret::Search::SortField::SCORE ]
it works just fine, but if i put this in
sort = [ Ferret::Search::SortField::SCORE(:reverse => true) ]
i get
undefined method `SCORE’ for Ferret::Search::SortField:Class
there’s probably something really really simple that i missed.
here’s the whole function for reference.
sort = [ Ferret::Search::SortField::SCORE(:reverse => true) ]
@results = Site.multi_search(params[:search_terms], [ Link, Post ],
{:limit => :all, :sort => sort })
ghost
May 21, 2007, 9:14pm
8
Hey …
try SCORE_REV instead of SCORE [1] …
Ben
[1] http://ferret.davebalmain.com/api/classes/Ferret/Search/
SortField.html
ghost
May 21, 2007, 9:24pm
9
Benjamin K. wrote:
Hey …
try SCORE_REV instead of SCORE [1] …
Ben
[1] http://ferret.davebalmain.com/api/classes/Ferret/Search/
SortField.html
I tried that and seemed not to have any effect. does
Ferret::Search::SortField::SCORE reference the same thing as
result.ferret_score ?
ghost
May 21, 2007, 10:00pm
10
Benjamin K. wrote:
did you try SortField.new(:score, :type => float, :reverse => true) ?
the score-sorting and the ferret_score should be the same …
Ben
that produces an error, first for the ‘float’ portion, then it says
Cannot sort by field “score”. It doesn’t exist in the index.
maybe i’m missing something in the Model… but if i just put
result.ferret_score, that works just fine… thanks for your help
jon
ghost
May 21, 2007, 9:40pm
11
On May 21, 2007, at 21:24, Jon D. wrote:
try SCORE_REV instead of SCORE [1] …
Ben
[1] http://ferret.davebalmain.com/api/classes/Ferret/Search/
SortField.html
I tried that and seemed not to have any effect. does
Ferret::Search::SortField::SCORE reference the same thing as
result.ferret_score ?
that might be a bug… ? i never tried SCORE_REV …
did you try SortField.new(:score, :type => float, :reverse => true) ?
the score-sorting and the ferret_score should be the same …
Ben