Hey guys, im trying to get my friends to come up at the top of the act
as ferret search. I would query the whole result set first, then move my
friends to the top, but the thing is, Im paginating my results and use
the offset and limit parameters in the multi_search() function.
Anyone know how to do this?
Thanks in advance…
On Tue, Oct 31, 2006 at 10:02:50AM +0100, Eric G. wrote:
Hey guys, im trying to get my friends to come up at the top of the act
as ferret search. I would query the whole result set first, then move my
friends to the top, but the thing is, Im paginating my results and use
the offset and limit parameters in the multi_search() function.
Anyone know how to do this?
We’d need some more info on how you store your friend-of-relationship,
and
how your index looks like (i.e. what fields does it contain).
cheers,
Jens
–
webit! Gesellschaft für neue Medien mbH www.webit.de
Dipl.-Wirtschaftsingenieur Jens Krämer [email protected]
Schnorrstraße 76 Tel +49 351 46766 0
D-01069 Dresden Fax +49 351 46766 66
ok for the user, for now i am only indexing the users full name, i have
class User < ActiveRecord::Base
acts_as_ferret :store_class_name => true, :fields => { :full_name =>
{ :boost
=> 3 }}
has_and_belongs_to_many :friends,:class_name=>“User”, :join_table=>
“friends_users”,:association_foreign_key => “friend_id”,
:after_add => :become_friend_to_friend,:after_remove=>
:remove_user_as_friend
so thats pretty much all there is there. The thing is Im calling the
search as a multisearch - User.multisearch(query,[ Book ], (with :limit
and :offset)).
Jens K. wrote:
On Tue, Oct 31, 2006 at 10:02:50AM +0100, Eric G. wrote:
Hey guys, im trying to get my friends to come up at the top of the act
as ferret search. I would query the whole result set first, then move my
friends to the top, but the thing is, Im paginating my results and use
the offset and limit parameters in the multi_search() function.
Anyone know how to do this?
We’d need some more info on how you store your friend-of-relationship,
and
how your index looks like (i.e. what fields does it contain).
cheers,
Jens
–
webit! Gesellschaft f�r neue Medien mbH www.webit.de
Dipl.-Wirtschaftsingenieur Jens Kr�mer [email protected]
Schnorrstra�e 76 Tel +49 351 46766 0
D-01069 Dresden Fax +49 351 46766 66
hey caspar, im having trouble understanding what you mean. Could you
show me some of your code? I dont know what you mean by sponsored
boolean flag and a sort field.
Any examples would be highly appreciatied.
Hi i have a similar thing in my search results. I have sponsored
listings appearing above other results. This is done with a simple
sponsored boolean flag and a sort field that orders by sponsored and
then score.
regards
caspar
Okay firstly the sponsored listings are what we call the paid for
premier style of listing in our site. In the listings db table there are
a few fields that describe the sponsored feature. Ferret is used to
index one of them which is a boolean called sponsored which simple
defines a listing as being sponsored. Ferret doesn’t know (as far as I’m
aware…) how to compare booleans so you need this declaration somewhere
in your model. Which tells ferret how to handle boolean comparrisons.
def false.<=>(o) o ? -1 : 0 end
def true.<=>(o) !o ? 1 : 0 end
Then it’s just a case of defining your sort fields and then using them
in your ferret search like so.
sort_fields = []
sort_fields << Ferret::Search::SortField.new(:sponsored, :reverse =>
:true)
sort_fields << Ferret::Search::SortField::SCORE
results = VoObject.find_by_contents(query,:sort
=>sort_fields,:offset=>page,:limit => RESULTS_PER_PAGE)
I’m a rank amateur when it comes to ruby/rails/ferret so please don’t
take this as the right/best way to do it, but it works for me.
Hope this helps.
Regards
Caspar