Max Williams
2008-Apr-14 15:58 UTC
[Ferret-talk] find_with_ferret :multi not working for me (latest version) (apologies if this was already posted)
First of all, sorry if this appears in the list twice - i was awaiting moderation all day and then finally joined the list properly and sent this direct. Previously, for all my ferret searches, i was using find_by_contents, like this: @stuff = LearningObject.find_by_contents("trumpet", #ferret options {:multi => [TeachingObject, LearningObject, Lesson, Course], :page => 1, :per_page => 15 }, #find options {} ) That all worked fine. We''ve upgraded to the latest ferret/a_a_f, though, which no longer uses find_by_contents: i believe we''re supposed to use find_with_ferret instead. However, if i do the equivalent, with find_by_contents replaced with find_with_ferret, then the ''multi'' part doesn''t work: i get the same results as if i didn''t pass multi at all. Looking in the API ( http://projects.jkraemer.net/rdoc/acts_as_ferret/ ), it looks like find_with_ferret doesn''t take a :multi option, so i''m in the dark over how to do multi-model searches now. My ferret-indexed classes all have ":store_class_name => true", which i read was necessary for multi searches. Can anyone help please? (To make life a bit more complicated, two of the classes extend one of the others, and i''d like a ferret search on the superclass to return results from both subclasses. However, i''d settle right now for just having a multi-model search that works) thanks Max Williams -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/ferret-talk/attachments/20080414/9c7ffd3f/attachment.html
Jens Kraemer
2008-Apr-14 20:24 UTC
[Ferret-talk] find_with_ferret :multi not working for me (latest version) (apologies if this was already posted)
Hi! what you''re experiencing is a result of the recent refactorings I did to the aaf code base. Sorry for the inconvenience this has caused you - I didn''t find the time to document this properly yet. I moved the multi search functionality from the class level methods (like find_with_ferret) into the ActsAsFerret namespace. It has always been a bit inconsistent calling find_with_ferret on one class, passing in any other classes to search in via the :multi option. To get multi search back, you should use ActsAsFerret::find like this: @stuff = ActsAsFerret::find( "trumpet", [TeachingObject, LearningObject, Lesson, Course], { :page => 1, :per_page => 15 }, {} # find options ) Cheers, Jens -- Jens Kr?mer Finkenlust 14, 06449 Aschersleben, Germany VAT Id DE251962952 http://www.jkraemer.net/ - Blog http://www.omdb.org/ - The new free film database
Max Williams
2008-Apr-15 08:50 UTC
[Ferret-talk] find_with_ferret :multi not working for me (latest version) (apologies if this was already posted)
Hi Jens That works great, thanks a lot! And thanks generally for a_a_f, it''s invaluable for us. max On 14/04/2008, Jens Kraemer <jk at jkraemer.net> wrote:> > Hi! > > what you''re experiencing is a resultH of the recent refactorings I did to > the aaf code base. Sorry for the inconvenience this has caused you - I > didn''t find the time to document this properly yet. > > I moved the multi search functionality from the class level methods > (like find_with_ferret) into the ActsAsFerret namespace. It has always > been a bit inconsistent calling find_with_ferret on one class, passing > in any other classes to search in via the :multi option. > > To get multi search back, you should use ActsAsFerret::find like this: > > @stuff = ActsAsFerret::find( > "trumpet", > > [TeachingObject, LearningObject, Lesson, Course], > { :page => 1, :per_page => 15 }, > {} # find options > > ) > > > Cheers, > Jens > > > -- > Jens Kr?mer > Finkenlust 14, 06449 Aschersleben, Germany > VAT Id DE251962952 > http://www.jkraemer.net/ - Blog > http://www.omdb.org/ - The new free film database > _______________________________________________ > Ferret-talk mailing list > Ferret-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/ferret-talk >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/ferret-talk/attachments/20080415/cfd38ccf/attachment.html
Max Williams
2008-Apr-15 10:12 UTC
[Ferret-talk] find_with_ferret :multi not working for me (latest version) (apologies if this was already posted)
I just remembered the second part of my last question... I have a superclass, Resource, which has two subclasses, TeachingObject and LearningObject. All the records that are saved are one of the subclasses. However, i''d like to be able to do a ferret search on Resource and get both kinds of subclass, like when i do Resource.find(), which returns both kinds. I''m having problems with the index though: TeachingObject and LearningObject both have :store_class_name => true, and they have their own indexes. When i try to build the index for Resource, it crashes with the following trace, whether i have :store_class_name => true set for Resource or not. Any ideas, anyone? thanks, max NoMethodError: You have a nil object when you didn''t expect it! The error occurred while evaluating nil.each_pair from /home/jars/rails/lesson_planner/branches/bundles/vendor/plugins/acts_as_ferret/lib/instance_methods.rb:130:in `to_doc'' from /home/jars/rails/lesson_planner/branches/bundles/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/core_ext/object/misc.rb:28:in `returning'' from /home/jars/rails/lesson_planner/branches/bundles/vendor/plugins/acts_as_ferret/lib/instance_methods.rb:124:in `to_doc'' from /home/jars/rails/lesson_planner/branches/bundles/vendor/plugins/acts_as_ferret/lib/bulk_indexer.rb:19:in `index_records'' from /home/jars/rails/lesson_planner/branches/bundles/vendor/plugins/acts_as_ferret/lib/bulk_indexer.rb:19:in `each'' from /home/jars/rails/lesson_planner/branches/bundles/vendor/plugins/acts_as_ferret/lib/bulk_indexer.rb:19:in `index_records'' from /home/jars/rails/lesson_planner/branches/bundles/vendor/plugins/acts_as_ferret/lib/bulk_indexer.rb:29:in `measure_time'' from /home/jars/rails/lesson_planner/branches/bundles/vendor/plugins/acts_as_ferret/lib/bulk_indexer.rb:18:in `index_records'' from /home/jars/rails/lesson_planner/branches/bundles/vendor/plugins/acts_as_ferret/lib/ferret_extensions.rb:52:in `index_model'' from /home/jars/rails/lesson_planner/branches/bundles/vendor/plugins/acts_as_ferret/lib/class_methods.rb:79:in `records_for_rebuild'' from /home/jars/rails/lesson_planner/branches/bundles/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in `transaction'' from /home/jars/rails/lesson_planner/branches/bundles/vendor/rails/activerecord/lib/active_record/transactions.rb:80:in `transaction'' from /home/jars/rails/lesson_planner/branches/bundles/vendor/plugins/acts_as_ferret/lib/class_methods.rb:74:in `records_for_rebuild'' from /home/jars/rails/lesson_planner/branches/bundles/vendor/plugins/acts_as_ferret/lib/ferret_extensions.rb:51:in `index_model'' from /home/jars/rails/lesson_planner/branches/bundles/vendor/plugins/acts_as_ferret/lib/ferret_extensions.rb:39:in `index_models'' from /home/jars/rails/lesson_planner/branches/bundles/vendor/plugins/acts_as_ferret/lib/ferret_extensions.rb:39:in `each'' from /home/jars/rails/lesson_planner/branches/bundles/vendor/plugins/acts_as_ferret/lib/ferret_extensions.rb:39:in `index_models'' from /home/jars/rails/lesson_planner/branches/bundles/vendor/plugins/acts_as_ferret/lib/local_index.rb:54:in `rebuild_index'' from /home/jars/rails/lesson_planner/branches/bundles/vendor/plugins/acts_as_ferret/lib/class_methods.rb:28:in `rebuild_index'' -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/ferret-talk/attachments/20080415/b8a7c56e/attachment-0001.html