Class: Solrizer::Fedora::Solrizer

Inherits:
Object
  • Object
show all
Defined in:
lib/solrizer/fedora/solrizer.rb

Constant Summary collapse

ALL_FIELDS =
[
  :pid, :label, :fType, :cModel, :state, :ownerId, :cDate, :mDate, :dcmDate, 
  :bMech, :title, :creator, :subject, :description, :contributor,
  :date, :type, :format, :identifier, :source, :language, :relation, :coverage, :rights 
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Solrizer

This method initializes the indexer If passed an argument of :index_full_text=>true, it will perform full-text indexing instead of indexing fields only.



24
25
26
27
28
29
30
31
32
# File 'lib/solrizer/fedora/solrizer.rb', line 24

def initialize( opts={} )
  @@index_list = false unless defined?(@@index_list)
  if opts[:index_full_text] == true || opts[:index_full_text] == "true"
    @index_full_text = true 
  else
    @index_full_text = false 
  end
  @indexer = Indexer.new( :index_full_text=>@index_full_text )
end

Instance Attribute Details

#index_full_textObject

Returns the value of attribute index_full_text.



18
19
20
# File 'lib/solrizer/fedora/solrizer.rb', line 18

def index_full_text
  @index_full_text
end

#indexerObject

Returns the value of attribute indexer.



18
19
20
# File 'lib/solrizer/fedora/solrizer.rb', line 18

def indexer
  @indexer
end

Instance Method Details

#solrize(obj, opts = {}) ⇒ Object

Solrize the given Fedora object’s full-text and facets into the search index

Examples:

Suppress errors using :suppress_errors option

solrizer.solrize("my:pid", :suppress_errors=>true)

Parameters:

  • obj (String or ActiveFedora::Base)

    the object to solrize

  • opts (Hash) (defaults to: {})

    optional parameters



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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/solrizer/fedora/solrizer.rb', line 40

def solrize( obj, opts={} )
  # retrieve the Fedora object based on the given unique id
    
  begin
    
    start = Time.now
    logger.debug "SOLRIZER Retrieving object #{obj} ..."


    if obj.kind_of? ActiveFedora::Base
      # do nothing
    elsif obj.kind_of? String
      obj = Repository.get_object( obj )
    elsif obj.respond_to? :pid
      obj = Repository.get_object( obj.pid )
    else
      raise "you must pass either a ActiveFedora::Base, Fedora::RepositoryObject, or a String.  You submitted a #{obj.class}"
    end
      
        obj_done = Time.now
        obj_done_elapse = obj_done - start
        logger.debug  " completed. Duration: #{obj_done_elapse}"
        
       logger.debug "\t Indexing object #{obj.pid} ... "
       # add the keywords and facets to the search index
       index_start = Time.now
       indexer.index( obj )
       
       index_done = Time.now
       index_elapsed = index_done - index_start
       
        logger.debug "completed. Duration:  #{index_elapsed} ."
      
    
  rescue Exception => e
      if opts[:suppress_errors] 
        logger.error "SOLRIZER unable to index #{obj}.  Failed with #{e.inspect}"
      else
        raise e
      end
  end

end

#solrize_from_csvObject

Raises:

  • (ArgumentException)


109
110
111
112
113
114
115
116
# File 'lib/solrizer/fedora/solrizer.rb', line 109

def solrize_from_csv
  raise ArgumentException, "#{@@index_list} does not exists!" unless File.exists?(@@index_list)
  puts "Indexing from list at #{@@index_list}"
  CSV.foreach(@@index_list) do |row|
      pid = row[0]
      solrize( pid )
  end 
end

#solrize_from_fedora_search(opts) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/solrizer/fedora/solrizer.rb', line 101

def solrize_from_fedora_search(opts)
  connections.each do |conn|
    conn.search(nil) do |object|
      solrize( object.pid, opts )
    end
  end 
end

#solrize_objects(opts = {}) ⇒ Object

Retrieve a comprehensive list of all the unique identifiers in Fedora and solrize each object’s full-text and facets into the search index

Examples:

Suppress errors using :suppress_errors option

solrizer.solrize_objects( :suppress_errors=>true )


89
90
91
92
93
94
95
96
97
98
99
# File 'lib/solrizer/fedora/solrizer.rb', line 89

def solrize_objects(opts={})
  # retrieve a list of all the pids in the fedora repository
  num_docs = 1000000   # modify this number to guarantee that all the objects are retrieved from the repository
  puts "WARNING: You have turned off indexing of Full Text content.  Be sure to re-run indexer with @@index_full_text set to true in main.rb" if index_full_text == false

  if @@index_list == false
    solrize_from_fedora_search(opts) 
  else
    solrize_from_csv
  end
end