Module: Cul::Scv::Hydra::Indexer

Defined in:
lib/cul_scv_hydra/indexer.rb

Class Method Summary collapse

Class Method Details

.recursively_index_fedora_objects(pid, pids_to_omit = nil, skip_generic_resources = false, verbose_output = false) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/cul_scv_hydra/indexer.rb', line 3

def self.recursively_index_fedora_objects(pid, pids_to_omit=nil, skip_generic_resources=false, verbose_output=false)

  if pid.blank?
    raise 'Please supply a pid (e.g. rake recursively_index_fedora_objects pid=ldpd:123)'
  end

  unless ActiveFedora::Base.exists?(pid)
    raise 'Could not find Fedora object with pid: ' + pid
  end

  if pids_to_omit.present? && pids_to_omit.include?(pid)
    puts 'Skipping indexing of topmost object in this set (' + pid + ') because it has been intentionally omitted...' if verbose_output
  else
    puts 'Indexing topmost object in this set (' + pid + ')...' if verbose_output
    puts 'If this is a BagAggregator with a lot of members, this may take a while...' if verbose_output

    # We found an object with the desired PID. Let's reindex it
    active_fedora_object = ActiveFedora::Base.find(pid, :cast => true)

    if skip_generic_resources && active_fedora_object.is_a?(GenericResource)
      puts 'Top level object was skipped because GenericResources are being skipped and it is a GenericResource.'
    else
      active_fedora_object.update_index
      puts 'Done indexing topmost object (' + pid + '). Took ' + (Time.now - START_TIME).to_s + ' seconds' if verbose_output
    end

  end

  puts 'Recursively retreieving and indexing all members of ' + pid + '...'

  unique_pids = Cul::Scv::Hydra::RisearchMembers.get_recursive_member_pids(pid, true)

  total_number_of_members = unique_pids.length
  puts 'Recursive search found ' + total_number_of_members.to_s + ' members.' if verbose_output

  if pids_to_omit.present?
    unique_pids = unique_pids - pids_to_omit
    total_number_of_members = unique_pids.length
    puts 'After checking against the list of omitted pids, the total number of objects to index will be: ' + total_number_of_members.to_s if verbose_output
  end

  i = 1
  if total_number_of_members > 0
    unique_pids.each {|pid|

      print 'Indexing ' + i.to_s + ' of ' + total_number_of_members.to_s + ' members (' + pid + ')...' if verbose_output

      active_fedora_object = ActiveFedora::Base.find(pid, :cast => true)

      if skip_generic_resources && active_fedora_object.is_a?(GenericResource)
        puts "skipped (because we're skipping GenericResources." if verbose_output
      else
        active_fedora_object.update_index
        # Display progress
        puts 'done.' if verbose_output
      end

      i += 1
    }
  end

  puts 'Indexing complete!  Took ' + (Time.now - START_TIME).to_s + ' seconds'

end