Module: ActsAsFulltextable::ClassMethods
- Defined in:
- lib/acts_as_fulltextable.rb
Instance Method Summary collapse
-
#acts_as_fulltextable(*attr_names) ⇒ Object
Makes a model searchable.
Instance Method Details
#acts_as_fulltextable(*attr_names) ⇒ Object
Makes a model searchable. Takes a list of fields to use to create the index. It also take an option (:check_for_changes, which defaults to true) to tell the engine wether it should check if the value of a given instance has changed before it actually updates the associated fulltext row. If option :parent_id is not nulled, it is used as the field to be used as the parent of the record, which is useful if you want to limit your queries to a scope. If option :conditions is given, it should be a string containing a ruby expression that equates to true or nil/false. Records are tested with this condition and only those that return true add/update the FullTextRow. A record returning false that is already in FullTextRow is removed.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/acts_as_fulltextable.rb', line 18 def acts_as_fulltextable(*attr_names) configuration = { :check_for_changes => true, :parent_id => nil, :conditions => "true" } configuration.update(attr_names.pop) while attr_names.last.is_a?(Hash) configuration[:fields] = attr_names.flatten.uniq.compact class_attribute :fulltext_options self. = configuration extend FulltextableClassMethods include FulltextableInstanceMethods self.send('after_create', :create_fulltext_record) self.send('after_update', :update_fulltext_record) self.send('has_one', :fulltext_row, :as => :fulltextable, :dependent => :delete) end |