Hi!

On Sat, Feb 03, 2007 at 01:00:49AM +0100, Gregg Pollack wrote:
> Hey guys,
> 
>     Simple question here.
> 
>     I have a single index of recipes, from which I'm looking at the
> following fields:  Name, Ingredient Text, Tags, and Description.
> 
>     The key is, I want to show all the results that come from Name,
> before I show any of the results from Ingredient Text, Tags, or
> Description.
> 
>     I tried doing this:
> 
> acts_as_ferret :fields => {
>    :name => {:boost => 9000, :store => :yes},
>    :ingredients => {:boost => 6000, :store => :yes},
>    :tags => {:boost => 3000, :store => :yes},
>    :description => {:boost => 1, :store => :yes}}
> 
>     I figured if I put huge boost on my fields, the "name" results would
> always come before ingredients (no matter what the score).

souunds reasonable.
 
>     Can anyone throw me any ideas on how one might do this?  Here is an
> explain of one of my first results.  Perhaps I need to change the
> rounding of my score?  I dunno.

Scores are always between 0 and 1. You might want to set some less
aggressive values for your boost values, it's more the relation between 
them that counts, than their absolute value. 

However that way you won't have a guarantee that the sorting will be 
as you intend. If this really is that important, run an explicit 
search only against the name field, and then one against all fields,
excluding the hits you got with the first search:

# get results where name fields match (might be good to escape at least
# '(' and ')' in query):
name_results = Recipe.find_by_contents(%{name:(#{query})})

# now get results where other fields match, but exclude those we already
# have:
ids = name_results.map(&:id).join ' OR '
other_results = Recipe.find_by_contents(%{#{query} -id:(#{ids})"})




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

Reply via email to