[AAF] Determine matching field in a search result

I was wondering if it was possible to determine which field caused the
match to occur (or contributed the most to the score) in a search
result.

For example, if I had a record

{ :name => ‘pumpkin’, :age => -5, :address => ‘Via Mandriola’ }

and I did a search for ‘Mandriola’, is it possible for acts_as_ferret to
tell me that the match actually came from the :address field? In some
cases there will be several matching fields, but I feel it should be
possible.

Thank you :slight_smile:

On Fri, Feb 09, 2007 at 02:05:48PM +0100, pumpkin wrote:

cases there will be several matching fields, but I feel it should be
possible.

I know of no way to do this via Ferret’s API, so aaf doesn’t support
this either. You can run explain on a query, but that more or less does
the searching again and generates a textual output that shows how the
score has been calculated.

However, if you only want to know which field the hit came from, just do
a search for “+id:#{record.id} +address:#{query}” and repeat that for
every other field you have indexed. If you call total_hits and not
find_by_contents with these queries and check if the result is 0 or 1,
this even should be quite fast.

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