Is there a way I can get ferret to give the highest ranking to an exact term match? The problem I have right now is that I am searching both title and body fields, so even if I boost the title field, if the body has more instances of the query, then it gets pushed up in rank. I would like for ferret to put exact matches (of the title field) at the very top of the pile, so if I do a search for say "color", the results look like this ? Color ? Color Theory ? Color Management Right now the order is like this ? Color Theory ? Color Management ? Color Because the first two articles have more instances in the body field. Is this possible?
On Wed, May 02, 2007 at 01:34:30PM +0200, Steven Garcia wrote:> Is there a way I can get ferret to give the highest ranking to an > exact term match? > > The problem I have right now is that I am searching both title and > body fields, so even if I boost the title field, if the body has more > instances of the query, then it gets pushed up in rank. > > I would like for ferret to put exact matches (of the title field) at > the very top of the pile, so if I do a search for say "color", the > results look like this > > ? Color > ? Color Theory > ? Color Management > > Right now the order is like this > > ? Color Theory > ? Color Management > ? Color > > Because the first two articles have more instances in the body field. > > Is this possible?If setting the boost for the title field really high (and the one for the body really low, maybe even below 1) doesn''t help, you could run the query twice, once against the title field only, and once against the body. 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
Setting the boost as you specified didn''t work. How would I set up two queries? My code: http://pastie.caboo.se/58230
On Wed, May 02, 2007 at 02:17:19PM +0200, Steven Garcia wrote:> Setting the boost as you specified didn''t work. > > How would I set up two queries? > > My code: http://pastie.caboo.se/58230that should do the trick: class Search attr_accessor :query def initialize(query) @query = query end def do_search returning [] do |results| results << Term.multi_search("title:(#{query})", [Article, Term]) results << Term.multi_search("#{query} -title:(#{query})", [Article, Term]) end end end 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
For better compatibility with the code using your search model use aaf''s SearchResults class: def do_search title_results = Term.multi_search( "title:(#{query})", [Article, Term] ) body_results = Term.multi_search( "#{query} -title:(#{query})", [Article, Term] ) new ActsAsFerret::SearchResults( title_results + body_results, title_results.total_hits + body_results.total_hits ) end 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
I tried using the do_search method you suggested and get this error: undefined method `SearchResults'' for ActsAsFerret:Module On May 8, 2007, at 5:16 AM, Jens Kraemer wrote:> def do_search > title_results = Term.multi_search( "title:(#{query})", > [Article, Term] ) > body_results = Term.multi_search( "#{query} -title:(#{query})", > [Article, Term] ) > new ActsAsFerret::SearchResults( title_results + body_results, > title_results.total_hits + > body_results.total_hits ) > end-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/ferret-talk/attachments/20070610/ca469f81/attachment.html
On Sun, Jun 10, 2007 at 06:22:44PM -0700, Steven Garcia wrote:> I tried using the do_search method you suggested and get this error: > > undefined method `SearchResults'' for ActsAsFerret:Modulemy fault, correct syntax of course is ActsAsFerret::SearchResults.new(...) 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