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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
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
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 :)
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:#{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       kraemer@webit.de
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.