Module: Bulkrax::ParserExportRecordSet

Defined in:
app/parsers/bulkrax/parser_export_record_set.rb

Overview

This module is responsible for providing the means of querying Solr for the appropriate works, collections, and file sets for an export of entries.

Defined Under Namespace

Classes: All, Base, Collection, Importer, Worktype

Constant Summary collapse

SOLR_QUERY_PAGE_SIZE =
512

Class Method Summary collapse

Class Method Details

.for(parser:, export_from:) ⇒ #each, #count

A factory method for returning an object that can yield each id and associated entry_class as well as return the count of objects in the record set.

Parameters:

Returns:



20
21
22
# File 'app/parsers/bulkrax/parser_export_record_set.rb', line 20

def self.for(parser:, export_from:)
  "Bulkrax::ParserExportRecordSet::#{export_from.classify}".constantize.new(parser: parser)
end

.in_batches(array, page_size: SOLR_QUERY_PAGE_SIZE) {|slice| ... } ⇒ Array<Object>

A helper method for handling querying large batches of IDs. By default SOLR has a max of 1024 ‘OR` clauses per query. This method helps chunk large sets of IDs into batches.

Parameters:

  • array (Array<Object>)
  • page_size (Integer) (defaults to: SOLR_QUERY_PAGE_SIZE)

Yield Parameters:

  • slice (Array<Object>)

    of the original arrays which are yielded. The results of the yield are merged into the return value.

Returns:

  • (Array<Object>)

See Also:



38
39
40
41
42
43
44
45
46
# File 'app/parsers/bulkrax/parser_export_record_set.rb', line 38

def self.in_batches(array, page_size: SOLR_QUERY_PAGE_SIZE)
  array = Array.wrap(array)
  return [] if array.empty?
  results = []
  array.each_slice(page_size) do |slice|
    results += Array.wrap(yield(slice))
  end
  results
end