I found myself with several models that belong to another "category" model. The category model did nothing but store a category name, but I wanted to be able to search on this in the belonging models. I don't think there's any way to do this associated stuff properly, but it seems like an easy/good solution is to just add the category name as an additional field to the other indexes.
This is just a very minor patch so you can specify a field that doesn't actually exist, and it will look for matching method instead. So now, in a model, I can specify:
acts_as_ferret(:fields => [:category_name])
def category_name
category.name
end
--- lib/acts_as_ferret.rb (revision 16)
+++ lib/acts_as_ferret.rb (working copy)
@@ -101,7 +101,7 @@
default_opts.update(options) if options.is_a?(Hash)
fields_for_ferret << field
define_method("#{field}_to_ferret".to_sym) do
- val = self[field] || self.instance_variable_get("@#{field.to_s}".to_sym)
+ val = self[field] || self.instance_variable_get("@#{field.to_s}".to_sym) || self.method(field).call
logger.debug("Adding field #{field} with value '#{val}' to index")
Ferret::Document::Field.new(field.to_s, val,
default_opts[:store],