Module: ActiveFedora::Indexing
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
34 35 36 |
# File 'lib/active_fedora/indexing.rb', line 34 def solr_name(*args) ActiveFedora::SolrService.solr_name(*args) end |
#solrize_profile(solr_doc = Hash.new) ⇒ Object
:nodoc:
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/active_fedora/indexing.rb', line 38 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
55 56 57 58 59 60 61 62 63 |
# File 'lib/active_fedora/indexing.rb', line 55 def solrize_relationships(solr_doc = Hash.new) relationships.each_statement do |statement| predicate = Predicates.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.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/active_fedora/indexing.rb', line 14 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.merge! ds.to_solr() end solr_doc = solrize_relationships(solr_doc) unless opts[:model_only] solr_doc end |
#update_index ⇒ Object
Updates Solr index with self.
66 67 68 69 70 71 72 73 74 |
# File 'lib/active_fedora/indexing.rb', line 66 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, softCommit: true) end end |