def self.included(base)
base.class_eval do
class_inheritable_array :sphinx_indexes, :sphinx_facets
extend ThinkingSphinx::ActiveRecord::ClassMethods
class << self
attr_accessor :sphinx_index_blocks
def set_sphinx_primary_key(attribute)
@sphinx_primary_key_attribute = attribute
end
def primary_key_for_sphinx
@sphinx_primary_key_attribute || primary_key
end
def sphinx_index_options
sphinx_indexes.last.options
end
def to_crc32
self.name.to_crc32
end
def to_crc32s
(subclasses << self).collect { |klass| klass.to_crc32 }
end
def sphinx_database_adapter
ThinkingSphinx::AbstractAdapter.detect(self)
end
def sphinx_name
self.name.underscore.tr(':/\\', '_')
end
def reset_subclasses_with_thinking_sphinx
reset_subclasses_without_thinking_sphinx
ThinkingSphinx.reset_context!
end
alias_method_chain :reset_subclasses, :thinking_sphinx
private
def defined_indexes?
@defined_indexes
end
def defined_indexes=(value)
@defined_indexes = value
end
def sphinx_delta?
self.sphinx_indexes.any? { |index| index.delta? }
end
end
end
::ActiveRecord::Associations::HasManyAssociation.send(
:include, ThinkingSphinx::ActiveRecord::HasManyAssociation
)
::ActiveRecord::Associations::HasManyThroughAssociation.send(
:include, ThinkingSphinx::ActiveRecord::HasManyAssociation
)
end