module ActiveFedora::Indexing::ClassMethods

Public Instance Methods

descendant_uris(uri, exclude_uri: false) click to toggle source

rubocop:enable Naming/VariableName

# File lib/active_fedora/indexing.rb, line 134
def descendant_uris(uri, exclude_uri: false)
  DescendantFetcher.new(uri, exclude_self: exclude_uri).descendant_and_self_uris
end
index_config() click to toggle source

@return ActiveFedora::Indexing::Map

# File lib/active_fedora/indexing.rb, line 88
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) click to toggle source

rubocop:disable Naming/VariableName @param [Integer] batch_size - The number of Fedora objects to process for each SolrService.add call. Default 50. @param [Boolean] softCommit - Do we perform a softCommit when we add the to_solr objects to SolrService. Default true. @param [Boolean] progress_bar - If true output progress bar information. Default false. @param [Boolean] final_commit - If true perform a hard commit to the Solr service at the completion of the batch of updates. Default false.

# File lib/active_fedora/indexing.rb, line 101
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
  end

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

  return unless final_commit

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