On Fri, Apr 27, 2007 at 09:27:48AM -0400, andy mitlenatch wrote:
> Hello!
>
[..]
> I have a model, 'Book', that has associations to several other models,
> comments, tags, authors, etc.. I have implemented acts_as_ferret to search
> the Book model and the associations as follows:
>
[..]
> I can successfully search the Book model and all of its associations. Next,
> I would like to print out in which field/association the hit occurred. For
> example, I would like to print to the user whether the hit was in the book
> title, a tag, in a comment or in the collection of authors, as I am only
> printing the title of the book and some higher level details in the search
> results.
The information in which field a hit occured is not available from
Ferret results directly, so to find this out you'd have to re-run the
query against each of the fields in question for each record in your
result set (scope your search to exactly this record by using
"id:#{record.id}" as a part of your query).
Not a good solution, I must admit - might be easier (and faster) to run
separate queries for each field in the beginning and then manually merge
these results, preserving the information which field had the hit.
But beware of duplicates because of records having matches in multiple
fields. Also such records would score better if you only ran one query across
all fields - so maybe you would want to still do that to get exact
scores for sorting the results by relevancy...
I feel like there should be an easier way to do this, maybe somebody
else has a better idea?
Jens
--
Jens Krämer
webit! Gesellschaft für neue Medien mbH
Schnorrstraße 76 | 01069 Dresden
Telefon +49 351 46766-0 | Telefax +49 351 46766-66
[EMAIL PROTECTED] | www.webit.de
Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk