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 W.

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

Hi Jens

That works great, thanks a lot!

And thanks generally for a_a_f, it’s invaluable for us.

max

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:inreturning’
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:inindex_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:inindex_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:inindex_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:inrecords_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:intransaction’
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:inindex_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:ineach’
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:inrebuild_index’
from
/home/jars/rails/lesson_planner/branches/bundles/vendor/plugins/acts_as_ferret/lib/class_methods.rb:28:in
`rebuild_index’

Jens Krämer wrote:

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

Hi Jens,

i’ve been searching on the very same issue all afternoon.

using find_with_ferret gave the :store_class_name error (although all my
models have got :store_class_name => true, as specified in the ferret
gotchas).

acts_as_ferret({:fields => { :title => {:store => :yes},
:description => {:store => :yes}},
:store_class_name => true})

I’ve got revision 338 from the stable trunk, and i work under rails
2.0.2

now i’m sorry to say the find tip doesn’t work for me either ! Is it a
later revision? What to do for now in the stable version ?

ActsAsFerret::find(options[:q], options[:models], {:offset => offset,
:limit => limit},{})
gives
undefined method `find’ for ActsAsFerret:Module

Any tip would be greatly appreciated …
Thank you,

Elise