Module: Solrsan::Search
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/solrsan/search.rb,
lib/solrsan/search.rb,
lib/solrsan/indexer.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #as_solr_document ⇒ Object
- #destroy_index_document ⇒ Object
- #id_value ⇒ Object
- #indexed_fields ⇒ Object
- #solr_id_value ⇒ Object
- #solr_index(opts = {:add_attributes => {:commitWithin => 10}}) ⇒ Object
Instance Method Details
#as_solr_document ⇒ Object
5 6 7 |
# File 'lib/solrsan/indexer.rb', line 5 def as_solr_document self.attributes end |
#destroy_index_document ⇒ Object
28 29 30 |
# File 'lib/solrsan/indexer.rb', line 28 def destroy_index_document self.class.destroy_index_document(self) end |
#id_value ⇒ Object
32 33 34 35 36 |
# File 'lib/solrsan/indexer.rb', line 32 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 |
#indexed_fields ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/solrsan/indexer.rb', line 9 def indexed_fields raise "Object has have a valid as_solr_document defined" if as_solr_document.nil? doc = {:type => self.class.solr_type, :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
38 39 40 |
# File 'lib/solrsan/indexer.rb', line 38 def solr_id_value "#{self.class.solr_type}-#{id_value.to_s}" end |
#solr_index(opts = {:add_attributes => {:commitWithin => 10}}) ⇒ Object
24 25 26 |
# File 'lib/solrsan/indexer.rb', line 24 def solr_index(opts={:add_attributes => {:commitWithin => 10}}) self.class.solr_index(self, opts) end |