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.
person
has_many email_addresses
has_many phone_numbers
acts_as_ferret :fields => [:firstname, :lastname, :birth_date]
email_address
has_one person
acts_as_ferret :fields => [:email_address]
phone_number
has_one person
acts_as_ferret :fields => [:phone_number, :phone_type]
multi_search(options[:query], ["EmailAddress", "PhoneNumber"], {:limit
=> :all})
Is this the right way of doing this... or is there a better way?
on 25.06.2007 00:42
on 25.06.2007 13:49
Hi! On Mon, Jun 25, 2007 at 12:42:54AM +0200, Stephen Heuer wrote: > has_many email_addresses > > > > multi_search(options[:query], ["EmailAddress", "PhoneNumber"], {:limit > => :all}) > > Is this the right way of doing this... or is there a better way? Be sure to apply the :store_classname => true option to all your acts_as_ferret calls. Otherwise aaf cannot filter results by class. 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 kraemer@webit.de | www.webit.de Amtsgericht Dresden | HRB 15422 GF Sven Haubold, Hagen Malessa
on 25.06.2007 15:39
Hey, > 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. Stephen Heuer
on 25.06.2007 16:22
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
kraemer@webit.de | www.webit.de
Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa
on 25.06.2007 17:06
> 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: has_many :phone_numbers has_many :addresses has_many :email_addresses has_many :enrollments has_many :facilities_applications has_many :course_invoices has_many :refunds has_many :medications has_many :instructor_bios has_one :immunization has_one :administrator 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 26.06.2007 10:05
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. the corresponding ticket is there: http://projects.jkraemer.net/acts_as_ferret/ticket/96 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 kraemer@webit.de | www.webit.de Amtsgericht Dresden | HRB 15422 GF Sven Haubold, Hagen Malessa
on 26.06.2007 21:02
> the corresponding ticket is there: > http://projects.jkraemer.net/acts_as_ferret/ticket/96 Excellent, this works perfectly. Thanks, Stephen Heuer http://www.int42.org