Module: ActiveFedora::Indexing::ClassMethods
- Defined in:
- lib/active_fedora/indexing.rb
Instance Method Summary collapse
- #descendant_uris(uri) ⇒ Object
- #indexer ⇒ Object
-
#load_instance_from_solr(id, solr_doc = nil) ⇒ Object
This method can be used instead of ActiveFedora::Model::ClassMethods.find.
- #reindex_everything ⇒ Object
Instance Method Details
#descendant_uris(uri) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/active_fedora/indexing.rb', line 82 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 Ldp::Response.rdf_source?(resource.head) immediate_descendant_uris = resource.graph.query(predicate: ::RDF::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 |
#indexer ⇒ Object
54 55 56 |
# File 'lib/active_fedora/indexing.rb', line 54 def indexer IndexingService 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.
78 79 80 |
# File 'lib/active_fedora/indexing.rb', line 78 def load_instance_from_solr(id, solr_doc=nil) SolrInstanceLoader.new(self, id, solr_doc).object end |
#reindex_everything ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/active_fedora/indexing.rb', line 58 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 |