Module: ActiveFedora::Indexing::ClassMethods

Defined in:
lib/active_fedora/indexing.rb

Instance Method Summary collapse

Instance Method Details

#descendant_uris(uri, exclude_uri: false) ⇒ Object



130
131
132
# File 'lib/active_fedora/indexing.rb', line 130

def descendant_uris(uri, exclude_uri: false)
  DescendantFetcher.new(uri, exclude_self: exclude_uri).descendant_and_self_uris
end

#index_configObject

Returns ActiveFedora::Indexing::Map.

Returns:

  • ActiveFedora::Indexing::Map



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

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

#reindex_everything(batch_size: 50, softCommit: true, progress_bar: false, final_commit: false) ⇒ Object

Parameters:

  • batch_size (Integer) (defaults to: 50)
    • The number of Fedora objects to process for each SolrService.add call. Default 50.

  • softCommit (Boolean) (defaults to: true)
    • Do we perform a softCommit when we add the to_solr objects to SolrService. Default true.

  • progress_bar (Boolean) (defaults to: false)
    • If true output progress bar information. Default false.

  • final_commit (Boolean) (defaults to: false)
    • If true perform a hard commit to the Solr service at the completion of the batch of updates. Default false.



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/active_fedora/indexing.rb', line 98

def reindex_everything(batch_size: 50, softCommit: true, progress_bar: false, final_commit: false)
  # skip root url
  descendants = descendant_uris(ActiveFedora.fedora.base_uri, exclude_uri: true)

  batch = []

  progress_bar_controller = ProgressBar.create(total: descendants.count, format: "%t: |%B| %p%% %e") if progress_bar

  descendants.each do |uri|
    logger.debug "Re-index everything ... #{uri}"

    batch << ActiveFedora::Base.find(ActiveFedora::Base.uri_to_id(uri)).to_solr

    if (batch.count % batch_size).zero?
      SolrService.add(batch, softCommit: softCommit)
      batch.clear
    end

    progress_bar_controller.increment if progress_bar_controller
  end

  if batch.present?
    SolrService.add(batch, softCommit: softCommit)
    batch.clear
  end

  if final_commit
    logger.debug "Solr hard commit..."
    SolrService.commit
  end
end