Module: ActiveFedora::Indexing::ClassMethods

Defined in:
lib/active_fedora/indexing.rb

Instance Method Summary collapse

Instance Method Details

#descendant_uris(uri) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/active_fedora/indexing.rb', line 111

def descendant_uris(uri)
  resource = Ldp::Resource::RdfSource.new(ActiveFedora.fedora.connection, uri)
  # GET could be slow if it's a big resource, we're using HEAD to avoid this problem,
  # but this causes more requests to Fedora.
  return [] unless resource.head.rdf_source?
  immediate_descendant_uris = resource.graph.query(predicate: ::RDF::Vocab::LDP.contains).map { |descendant| descendant.object.to_s }
  all_descendants_uris = [uri]
  immediate_descendant_uris.each do |descendant_uri|
    all_descendants_uris += descendant_uris(descendant_uri)
  end
  all_descendants_uris
end

#index_configObject

Returns ActiveFedora::Indexing::Map.

Returns:

  • ActiveFedora::Indexing::Map



78
79
80
81
82
83
84
# File 'lib/active_fedora/indexing.rb', line 78

def index_config
  @index_config ||= if superclass.respond_to?(:index_config)
                      superclass.index_config.deep_dup
                    else
                      ActiveFedora::Indexing::Map.new
                    end
end

#load_instance_from_solr(id, solr_doc = nil) ⇒ Object

This method can be used instead of ActiveFedora::Model::ClassMethods.find. It works similarly except it populates an object from Solr instead of Fedora. It is most useful for objects used in read-only displays in order to speed up loading time. If only a id is passed in it will query solr for a corresponding solr document and then use it to populate this object.

If a value is passed in for optional parameter solr_doc it will not query solr again and just use the one passed to populate the object.

It will anything stored within solr such as metadata and relationships. Non-metadata attached files will not be loaded and if needed you should use find instead.



106
107
108
# File 'lib/active_fedora/indexing.rb', line 106

def load_instance_from_solr(id, solr_doc = nil)
  SolrInstanceLoader.new(self, id, solr_doc).object
end

#reindex_everythingObject



86
87
88
89
90
91
92
93
# File 'lib/active_fedora/indexing.rb', line 86

def reindex_everything
  descendants = descendant_uris(ActiveFedora::Base.id_to_uri(''))
  descendants.shift # Discard the root uri
  descendants.each do |uri|
    logger.debug "Re-index everything ... #{uri}"
    ActiveFedora::Base.find(ActiveFedora::Base.uri_to_id(uri)).update_index
  end
end