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 -- Posted via http://www.ruby-forum.com/.
On 10/17/06, Caspar Bl <waspfactory at gmail.com> 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. ><rearranged email>> [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 << Ferret::Search::SortField.new(:sponsored, :reverse => > :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
> 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 -- Posted via http://www.ruby-forum.com/.
On Fri, May 18, 2007 at 07:53:39PM +0200, Jon Druse wrote:> > > 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})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 kraemer at webit.de | www.webit.de Amtsgericht Dresden | HRB 15422 GF Sven Haubold, Hagen Malessa
Jens Kraemer wrote:> On Fri, May 18, 2007 at 07:53:39PM +0200, Jon Druse 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 -- Posted via http://www.ruby-forum.com/.
On Fri, May 18, 2007 at 08:56:07PM +0200, Jon Druse wrote:> Jens Kraemer wrote: > > On Fri, May 18, 2007 at 07:53:39PM +0200, Jon Druse 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. :-)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 kraemer at webit.de | www.webit.de Amtsgericht Dresden | HRB 15422 GF Sven Haubold, Hagen Malessa
Jens Kraemer 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 }) -- Posted via http://www.ruby-forum.com/.
Hey .. try SCORE_REV instead of SCORE [1] .. :-) Ben [1] http://ferret.davebalmain.com/api/classes/Ferret/Search/ SortField.html
Benjamin Krause wrote:> Hey .. > > try SCORE_REV instead of SCORE [1] .. :-) > > Ben > > [1] http://ferret.davebalmain.com/api/classes/Ferret/Search/ > SortField.htmlI tried that and seemed not to have any effect. does Ferret::Search::SortField::SCORE reference the same thing as result.ferret_score ? -- Posted via http://www.ruby-forum.com/.
On May 21, 2007, at 21:24, Jon Druse 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
Benjamin Krause wrote:> > did you try SortField.new(:score, :type => float, :reverse => true) ? > > the score-sorting and the ferret_score should be the same .. > > Benthat 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 -- Posted via http://www.ruby-forum.com/.