thomasvmatthew-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Feb-23 21:06 UTC
Ferret search results breakdown
Hi, I''m building an application that is going to be making heavy use of all the ferret search options, i.e. boolean, proximity, etc. I was wondering if ferret has a way of providing a full search report, for example, for each document hit give the terms that were found in that document and how many times each was hit. Thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 2/24/07, thomasvmatthew-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <thomasvmatthew-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, I''m building an application that is going to be making heavy use > of all the ferret search options, i.e. boolean, proximity, etc. I was > wondering if ferret has a way of providing a full search report, for > example, for each document hit give the terms that were found in that > document and how many times each was hit. > > Thanks!The Index#explain method is probably what you want; http://ferret.davebalmain.com/api/classes/Ferret/Index/Index.html#M000038 Although the output may be a bit hard to understand. If you want to create your own reports, here is an example; require ''rubygems'' require ''ferret'' class Ferret::I def report(query, doc_num) return '''' unless query = process_query(query) report = '''' term_vectors = reader.term_vectors(doc_num) query.terms(searcher).each do |term| term_vector = term_vectors[term.field].terms.select {|tp| tp.text == term.text} count = term_vector.size > 0 ? term_vector.first.positions.size : 0 report << "#{term.field}:#{term.text} - occured #{count} times\n" end report end end i = Ferret::I.new(:analyzer => Ferret::Analysis::WhiteSpaceAnalyzer.new) i << { :one => """Hi, I''m building an application that is going to be making heavy use of all the ferret search options, i.e. boolean, proximity, etc. I was wondering if ferret has a way of providing a full search report, for example, for each document hit give the terms that were found in that document and how many times each was hit.""", :two => """Where lipstick is concerned, the important thing is not color, but to accept God''s final word on where your lips end. - Jerry Seinfeld""", :three => """The forceps of our minds are clumsy forceps, and crush the truth a little in taking hold of it. - HG Wells""" } puts "Explain => " puts i.explain(''the building all'', 0) puts "" puts "Report => " puts i.report(''the building all'', 0) -- Dave Balmain http://www.davebalmain.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---