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!

On 2/24/07, [email protected] [email protected] 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/