Module: ActiveFedora::Indexing
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/active_fedora/indexing.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #solr_name(*args) ⇒ Object
-
#solrize_profile(solr_doc = Hash.new) ⇒ Object
:nodoc:.
-
#solrize_relationships(solr_doc = Hash.new) ⇒ Object
Serialize the datastream’s RDF relationships to solr.
-
#to_solr(solr_doc = Hash.new, opts = {}) ⇒ Object
Return a Hash representation of this object where keys in the hash are appropriate Solr field names.
-
#update_index ⇒ Object
Updates Solr index with self.
Instance Method Details
#solr_name(*args) ⇒ Object
29 30 31 |
# File 'lib/active_fedora/indexing.rb', line 29 def solr_name(*args) ActiveFedora::SolrService.solr_name(*args) end |
#solrize_profile(solr_doc = Hash.new) ⇒ Object
:nodoc:
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/active_fedora/indexing.rb', line 33 def solrize_profile(solr_doc = Hash.new) # :nodoc: profile_hash = { 'datastreams' => {} } if inner_object.respond_to? :profile inner_object.profile.each_pair do |property,value| if property =~ /Date/ value = Time.parse(value) unless value.is_a?(Time) value = value.xmlschema end profile_hash[property] = value end end self.datastreams.each_pair { |dsid,ds| profile_hash['datastreams'][dsid] = ds.solrize_profile } solr_doc[self.class.profile_solr_name] = profile_hash.to_json end |
#solrize_relationships(solr_doc = Hash.new) ⇒ Object
Serialize the datastream’s RDF relationships to solr
50 51 52 53 54 55 56 57 58 |
# File 'lib/active_fedora/indexing.rb', line 50 def solrize_relationships(solr_doc = Hash.new) relationships.each_statement do |statement| predicate = RelsExtDatastream.short_predicate(statement.predicate) literal = statement.object.kind_of?(RDF::Literal) val = literal ? statement.object.value : statement.object.to_str ::Solrizer::Extractor.insert_solr_field_value(solr_doc, solr_name(predicate, :symbol), val ) end return solr_doc end |
#to_solr(solr_doc = Hash.new, opts = {}) ⇒ Object
Return a Hash representation of this object where keys in the hash are appropriate Solr field names. If opts == true, the base object metadata and the RELS-EXT datastream will be omitted. This is mainly to support shelver, which calls .to_solr for each model an object subscribes to.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/active_fedora/indexing.rb', line 9 def to_solr(solr_doc = Hash.new, opts={}) unless opts[:model_only] c_time = create_date c_time = Time.parse(c_time) unless c_time.is_a?(Time) m_time = modified_date m_time = Time.parse(m_time) unless m_time.is_a?(Time) Solrizer.set_field(solr_doc, 'system_create', c_time, :stored_sortable) Solrizer.set_field(solr_doc, 'system_modified', m_time, :stored_sortable) Solrizer.set_field(solr_doc, 'object_state', state, :stored_sortable) Solrizer.set_field(solr_doc, 'active_fedora_model', self.class.inspect, :stored_sortable) solr_doc.merge!(SOLR_DOCUMENT_ID.to_sym => pid) solrize_profile(solr_doc) end datastreams.each_value do |ds| solr_doc = ds.to_solr(solr_doc) end solr_doc = solrize_relationships(solr_doc) unless opts[:model_only] solr_doc end |
#update_index ⇒ Object
Updates Solr index with self.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/active_fedora/indexing.rb', line 61 def update_index if defined?( Solrizer::Fedora::Solrizer ) #logger.info("Trying to solrize pid: #{pid}") solrizer = Solrizer::Fedora::Solrizer.new solrizer.solrize( self ) else SolrService.add(self.to_solr) SolrService.commit end end |