Module: ActsAsFulltextable::FulltextableInstanceMethods

Defined in:
lib/acts_as_fulltextable.rb

Instance Method Summary collapse

Instance Method Details

#create_fulltext_recordObject

Creates the fulltext_row record for self



67
68
69
# File 'lib/acts_as_fulltextable.rb', line 67

def create_fulltext_record
  FulltextRow.create(:fulltextable_type => self.class.to_s, :fulltextable_id => self.id, :value => self.fulltext_value, :parent_id => self.parent_id_value) if eval self.class.fulltext_options[:conditions]
end

#fulltext_valueObject

Returns self’s value created by concatenating fulltext fields for its class



99
100
101
102
# File 'lib/acts_as_fulltextable.rb', line 99

def fulltext_value
  full_value = self.class.fulltext_fields.map {|f| self.send(f)}.join("\n")
  full_value
end

#parent_id_valueObject

Returns the parent_id value or nil if it wasn’t set.



73
74
75
# File 'lib/acts_as_fulltextable.rb', line 73

def parent_id_value
  self.class.fulltext_options[:parent_id].nil? ? nil : self.send(self.class.fulltext_options[:parent_id])
end

#update_fulltext_recordObject

Updates self’s fulltext_row record



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/acts_as_fulltextable.rb', line 79

def update_fulltext_record
  if eval self.class.fulltext_options[:conditions]
    if self.class.fulltext_options[:check_for_changes]
      row = FulltextRow.find_by_fulltextable_type_and_fulltextable_id(self.class.to_s, self.id) 
      # If we haven't got a row for the record, yet, create it instead of updating it.
      if row.nil?
        self.create_fulltext_record
        return
      end
    end
    FulltextRow.update_all(["value = ?, parent_id = ?", self.fulltext_value, self.parent_id_value], ["fulltextable_type = ? AND fulltextable_id = ?", self.class.to_s, self.id]) if !(self.class.fulltext_options[:check_for_changes]) || (row.value != self.fulltext_value) || (self.parent_id_value != row.parent_id)
  else

    row = FulltextRow.find_by_fulltextable_type_and_fulltextable_id(self.class.to_s, self.id)
    row.destroy unless row.nil?
  end
end