Module: Solrsam::Search::InstanceMethods
- Defined in:
- lib/solrsam/indexer.rb
Instance Method Summary collapse
- #as_solr_document ⇒ Object
- #destroy_index_document ⇒ Object
- #id_value ⇒ Object
- #index ⇒ Object
- #indexed_fields ⇒ Object
- #solr_id_value ⇒ Object
Instance Method Details
#as_solr_document ⇒ Object
6 7 8 |
# File 'lib/solrsam/indexer.rb', line 6 def as_solr_document self.attributes end |
#destroy_index_document ⇒ Object
29 30 31 |
# File 'lib/solrsam/indexer.rb', line 29 def destroy_index_document self.class.destroy_index_document(self) end |
#id_value ⇒ Object
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 |
#index ⇒ Object
25 26 27 |
# File 'lib/solrsam/indexer.rb', line 25 def index self.class.index(self) end |
#indexed_fields ⇒ Object
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_value ⇒ Object
39 40 41 |
# File 'lib/solrsam/indexer.rb', line 39 def solr_id_value "#{self.class.class_name}-#{id_value.to_s}" end |