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

Ticket #209 (closed enhancement: worksforme)

Opened 7 months ago

Last modified 6 months ago

:conditional_to_doc

Reported by: aaf Assigned to: jk
Priority: minor Milestone: later
Component: 0plugin Version:
Keywords: conditional_to_doc Cc:

Description

hi, I am working to use acts_as_ferret in a rails application. And I have a small problems, I have some entities which need to be indexed only in somme situation. So what do you thing about modifing the ActsAsFerret::LocalIndex?.add like that

def add(record)

unless Hash === record Ferret::Document === record

if record.respond_to?(:conditional_to_doc)

record = record.conditional_to_doc

else

record = record.to_doc

end

ferret_index << record if record

end alias << add

so we can implement in the model a function conditional_to_doc, to determine wether the model should be indexed or not .

def conditional_to_doc

if self.ok_ferret

self.to_doc

else

nil

end

end

or perhaps modifying to_doc, so it check for a function aaf_ok_to_index, with have to return true, if the indexing is permited. ie :

def to_doc

if self.respond_to?(:aaf_ok_to_index)

return unless self.aaf_ok_to_index

end logger.debug "creating doc for class: #{self.class.name}, id: #{self.id}" returning Ferret::Document.new do |doc|

# store the id of each item doc[:id] = self.id

# store the class name if configured to do so doc[:class_name] = self.class.name if aaf_configuration[:store_class_name]

# iterate through the fields and add them to the document aaf_configuration[:ferret_fields].each_pair do |field, config|

doc[field] = self.send("#{field}_to_ferret") unless config[:ignore]

end if aaf_configuration[:boost]

if self.respond_to?(aaf_configuration[:boost])

boost = self.send aaf_configuration[:boost] doc.boost = boost.to_i if boost

else

logger.error "boost option should point to an instance method: #{aaf_configuration[:boost]}"

end

end

end

end

what about that ?

Change History

04/12/08 06:18:49 changed by jk

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

Aaf already has support for conditional indexing with the :if option which allows you to specify a Proc to decide at runtime whether a record should be indexed or not.

See http://projects.jkraemer.net/acts_as_ferret/browser/trunk/demo/app/models/comment.rb for an example.

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