Forum: Ferret [AAF] Determine matching field in a search result

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
7e6f970116176f8c098e4c43a67d98bb?d=identicon&s=25 pumpkin (Guest)
on 2007-02-09 14:05
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

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

Thank you :)
C9dd93aa135988cabf9183d3210665ca?d=identicon&s=25 Jens Kraemer (Guest)
on 2007-02-09 15:12
(Received via mailing list)
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:#{} +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.


webit! Gesellschaft für neue Medien mbH
Dipl.-Wirtschaftsingenieur Jens Krämer
Schnorrstraße 76                         Tel +49 351 46766  0
D-01069 Dresden                          Fax +49 351 46766 66
This topic is locked and can not be replied to.