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



70
71
72
73
74
75
76
77
# File 'lib/acts_as_fulltextable.rb', line 70

def create_fulltext_record
  puts '=================='
  puts self.class.to_s
  puts self.id
  puts self.fulltext_value
  puts self.parent_id_value
  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



107
108
109
110
# File 'lib/acts_as_fulltextable.rb', line 107

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.



81
82
83
# File 'lib/acts_as_fulltextable.rb', line 81

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



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/acts_as_fulltextable.rb', line 87

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