To edit pages or tickets please login with username/password: aaf/aaf

Ticket #2 (closed defect: fixed)

Opened 3 years ago

Last modified 2 years ago

smart+question

Reported by: nick Assigned to: somebody
Priority: minor Milestone:
Component: 0plugin Version:
Keywords: Cc:

Description

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],

Change History

03/20/06 16:57:35 changed by anonymous

  • type changed from defect to enhancement.

03/25/06 13:16:46 changed by jk@jkraemer.net

  • status changed from new to closed.
  • resolution set to fixed.

Patch applied, thank you!

10/07/06 20:16:27 changed by Margarett

  • type changed from enhancement to defect.
  • summary changed from [PATCH] Allow custom data fields to smart+question.

10/08/06 15:55:02 changed by Richard

10/23/06 02:07:02 changed by Jeames

To edit pages or tickets please login with username/password: aaf/aaf