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_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
Download in other formats:
To edit pages or tickets please login with username/password: aaf/aaf
|