Module: Solrsam::Search::InstanceMethods

Defined in:
lib/solrsam/indexer.rb

Instance Method Summary collapse

Instance Method Details

#as_solr_documentObject



6
7
8
# File 'lib/solrsam/indexer.rb', line 6

def as_solr_document
   self.attributes
end

#destroy_index_documentObject



29
30
31
# File 'lib/solrsam/indexer.rb', line 29

def destroy_index_document
  self.class.destroy_index_document(self)
end

#id_valueObject



33
34
35
36
37
# File 'lib/solrsam/indexer.rb', line 33

def id_value
  item_id = self.attributes[:_id] || self.attributes[:id] || self.id
  raise "Object must have an id attribute defined before being indexed" if item_id.nil?
  item_id
end

#indexObject



25
26
27
# File 'lib/solrsam/indexer.rb', line 25

def index
  self.class.index(self)
end

#indexed_fieldsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/solrsam/indexer.rb', line 10

def indexed_fields
  raise "Object has have a valid as_solr_document defined" if as_solr_document.nil?

  doc = {:type => self.class.class_name, :db_id => id_value, :id => solr_id_value}

  initial_document_fields = as_solr_document.reject{|k,v| k == :id || k == :_id}
  converted_fields = initial_document_fields.reduce({}) do |acc, tuple|
    value = tuple[1]
    value = value.to_time.utc.xmlschema if value.respond_to?(:utc) || value.is_a?(Date)
    acc[tuple[0]] = value
    acc 
  end
  doc.merge(converted_fields)
end

#solr_id_valueObject



39
40
41
# File 'lib/solrsam/indexer.rb', line 39

def solr_id_value
  "#{self.class.class_name}-#{id_value.to_s}"
end