Module: ActiveFedora::Indexing::ClassMethods

Defined in:
lib/active_fedora/indexing.rb

Instance Method Summary collapse

Instance Method Details

#descendant_uris(uri) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/active_fedora/indexing.rb', line 103

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::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



67
68
69
70
71
72
73
# File 'lib/active_fedora/indexing.rb', line 67

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

#indexerObject



75
76
77
# File 'lib/active_fedora/indexing.rb', line 75

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.



99
100
101
# File 'lib/active_fedora/indexing.rb', line 99

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

#reindex_everythingObject



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

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