Stephen Heuer
2007-Jun-24 22:42 UTC
[Ferret-talk] I only want one type of model returned from a multi_search
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? -- Posted via http://www.ruby-forum.com/.
Jens Kraemer
2007-Jun-25 11:48 UTC
[Ferret-talk] I only want one type of model returned from a multi_search
Hi! On Mon, Jun 25, 2007 at 12:42:54AM +0200, Stephen Heuer wrote:> 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?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 at webit.de | www.webit.de Amtsgericht Dresden | HRB 15422 GF Sven Haubold, Hagen Malessa
Stephen Heuer
2007-Jun-25 13:39 UTC
[Ferret-talk] I only want one type of model returned from a multi_sear
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 -- Posted via http://www.ruby-forum.com/.
Jens Kraemer
2007-Jun-25 14:22 UTC
[Ferret-talk] I only want one type of model returned from a multi_sear
On Mon, Jun 25, 2007 at 03:39:57PM +0200, Stephen Heuer wrote:> 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.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 at webit.de | www.webit.de Amtsgericht Dresden | HRB 15422 GF Sven Haubold, Hagen Malessa
Stephen Heuer
2007-Jun-25 15:06 UTC
[Ferret-talk] I only want one type of model returned from a multi_sear
> 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). -- Posted via http://www.ruby-forum.com/.
Jens Kraemer
2007-Jun-26 08:04 UTC
[Ferret-talk] I only want one type of model returned from a multi_sear
On Mon, Jun 25, 2007 at 05:06:39PM +0200, Stephen Heuer wrote:> > > 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).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 at webit.de | www.webit.de Amtsgericht Dresden | HRB 15422 GF Sven Haubold, Hagen Malessa
Stephen Heuer
2007-Jun-26 19:02 UTC
[Ferret-talk] I only want one type of model returned from a multi_sear
> the corresponding ticket is there: > http://projects.jkraemer.net/acts_as_ferret/ticket/96Excellent, this works perfectly. Thanks, Stephen Heuer http://www.int42.org -- Posted via http://www.ruby-forum.com/.