Module: Flare::ActiveRecord::InstanceMethods

Defined in:
lib/flare/active_record.rb

Instance Method Summary collapse

Instance Method Details

#solr_destroyObject



108
109
110
# File 'lib/flare/active_record.rb', line 108

def solr_destroy
  Flare.session.remove!(self)
end

#solr_document_idObject



100
101
102
# File 'lib/flare/active_record.rb', line 100

def solr_document_id
  "#{self.class.name}:#{self.id}"
end

#solr_saveObject



104
105
106
# File 'lib/flare/active_record.rb', line 104

def solr_save
  Flare.session.index!(self)
end

#to_solr_docObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/flare/active_record.rb', line 77

def to_solr_doc
  doc = {
    :fields => { :id => solr_document_id, :type => self.class.name },
    :attributes => {}
  }

  solr_index[:fields].each do |field|
    value = send(field[:source])
    # Need to convert dates to utc xmlschema.
    #TODO: move this translation to rsolr gem
    if value.respond_to?(:utc)
      value = value.utc.xmlschema
    end
    doc[:fields][field[:name]] = value
  end
  
  solr_index[:attributes].each do |key, value|
    doc[:attributes][key] = value.kind_of?(Symbol) ? send(value) : value
  end
  
  doc
end