I am trying to use acts_as_ferret’s multi_search to search across
multiple models, but i only want it to return one type of model.
for example i have a page that lists out people. on this page it shows
email addresses and phone numbers. I want to be able to search by any
fields directly from the person model and search the fields from the
email_address and phone_number models, but I only want to get back
people.
Be sure to apply the :store_classname => true option to all your
acts_as_ferret calls. Otherwise aaf cannot filter results by class.
Yep, I got :store_class_name => true in my models. The problem is
occurring when i do a search and i get back Person, EmailAddress, and
PhoneNumber objects that all match the query, but i only want back
Person objects. So, when i do a search for someone via their email i
don’t want to get back an EmailAddress object and a Person Object, Just
the Person Object that the EmailAddress is Associated.
On Mon, Jun 25, 2007 at 03:39:57PM +0200, Stephen Heuer wrote:
the Person Object that the EmailAddress is Associated.
Well, if you only want to retrieve Person Objects from your index, then
just index Person objects in the first place
Why don’t you just index the email address right along with the Person?
Do you ever need to find a single EmailAddress object? If not, just
don’t index them in their own index. Instead add a custom field to
Person’s acts_as_ferred statement for the email address value.
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
Why don’t you just index the email address right along with the Person?
Do you ever need to find a single EmailAddress object? If not, just
don’t index them in their own index. Instead add a custom field to
Person’s acts_as_ferred statement for the email address value.
I would index the email address right along with the person, but there
is a multiple association there. I would have to index a whole lot of
other data that I would like to be able to search through:
put that with the fact that I have over 50 models ( all with many
associations ) in my application of which at least half of need to be
searchable, and that turns into a large task.
I created a module that helps me generate functions for list views (
with sorting and searching ) that used mysql fulltext searching, but
when searching through ~100,000 records, it would take the app upwards
of 7 seconds to finish finding results. So I was rewriting it to work
with acts_as_ferret.
So I would assume that acts_as_ferret multi_search doesn’t have the
ability to be told that I only want one type of model even though i want
to search through multiple models (to get associations).
On Mon, Jun 25, 2007 at 05:06:39PM +0200, Stephen Heuer wrote:
has_many :phone_numbers
So I would assume that acts_as_ferret multi_search doesn’t have the
ability to be told that I only want one type of model even though i want
to search through multiple models (to get associations).
no, as aaf doesn’t store relationships between records there’s no way to
do this. However, given the fact your models all have a :person
relationship, you could easily filter your results after running the
search. However I wouldn’t suggest this, I’d really go for a single
Person index having all the information in it. For the has_many
relationships - just join the contents of all elements together and put
them into a single field.
What might ease your work with indexing all the related objects along
with the Person is a patch residing in aaf’s Trac. Unfortunately I
didn’t find the time to apply this to trunk yet, but it does exactly
what you want - just name the relationships as field names in your
:fields list.