Ruby Forum Ferret > Which field(s) matched?

Posted by Robert Hulme (Guest)
on 26.03.2008 05:21
(Received via mailing list)
Is there a way to discover which fields in a document matched the search
that was performed?

I've just started with Ferret, but so far I can only get back the ids of
the documents that were matched (along with the score).

I'm aware there is a highlighting method, but I was hoping for something
computer readable (unless I'm misunderstanding what data can be gained
from that method).

Thanks
-Rob
Posted by Mark Reginald James (Guest)
on 10.04.2008 17:40
(Received via mailing list)
Robert Hulme wrote:
> Is there a way to discover which fields in a document matched the search 
> that was performed?
> 
> I've just started with Ferret, but so far I can only get back the ids of 
> the documents that were matched (along with the score).
> 
> I'm aware there is a highlighting method, but I was hoping for something 
> computer readable (unless I'm misunderstanding what data can be gained 
> from that method).

I've implemented a field_scores hash that can be returned along with
each document and aggregate score. It's only currently working in
Ferret 0.11.4.
Posted by Robert Hulme (Guest)
on 14.04.2008 11:43
(Received via mailing list)
> I've implemented a field_scores hash that can be returned along with
> each document and aggregate score. It's only currently working in
> Ferret 0.11.4.
Could you please give a code example of how to do a query and get the
field_scores hash?

I have Ferret 0.11.6.

-Rob
Posted by Mark Reginald James (Guest)
on 15.04.2008 04:27
(Received via mailing list)
Robert Hulme wrote:
>> I've implemented a field_scores hash that can be returned along with
>> each document and aggregate score. It's only currently working in
>> Ferret 0.11.4.
> Could you please give a code example of how to do a query and get the 
> field_scores hash?
> 
> I have Ferret 0.11.6.

Rob, FerretResult objects are given a ferret_field_scores attribute,
which is an array (not a hash, as I said above) of field_score objects,
in order of decreasing score. Field_score objects have "field" and
"score" attributes.

You specify which fields you want to see the field scores for by adding
the field_info option :field_score => :yes.

You can use field_scores to display an extract of the field that best
matches the user's query:

@result.highlight @query, :field => 
@result.ferret_field_scores.first.field

It'd take some work to port it to Ferret 0.11.6, though I will do
this soon.