# File lib/acts_as_indexed/class_methods.rb, line 20
    def acts_as_indexed(options = {})
      class_eval do
        extend ActsAsIndexed::SingletonMethods
      end
      include ActsAsIndexed::InstanceMethods

      after_create  :add_to_index
      before_update :update_index
      after_destroy :remove_from_index

      # scope for Rails 3.x, named_scope for Rails 2.x.
      if self.respond_to?(:where)
        scope :with_query, lambda { |query| where("#{table_name}.#{primary_key} IN (?)", search_index(query, {}, {:ids_only => true})) }
      else
        named_scope :with_query, lambda { |query| { :conditions => ["#{table_name}.#{primary_key} IN (?)", search_index(query, {}, {:ids_only => true}) ] } }
      end

      cattr_accessor :aai_config, :aai_fields

      self.aai_fields = options.delete(:fields)
      raise(ArgumentError, 'no fields specified') if self.aai_fields.nil? || self.aai_fields.empty?

      self.aai_config = ActsAsIndexed.configuration.dup
      self.aai_config.if_proc = options.delete(:if)
      options.each do |k, v|
        self.aai_config.send("#{k}=", v)
      end

      # Add the Rails environment and this model's name to the index file path.
      self.aai_config.index_file = self.aai_config.index_file.join(Rails.env, self.name.underscore)
    end