Class: Hyrax::Indexer Private

Inherits:
Module
  • Object
show all
Defined in:
lib/hyrax/indexer.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rules = nil, schema_name: nil, index_loader: nil) ⇒ Module

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • rules (Hash{Symbol => Symbol}) (defaults to: nil)
  • schema_name (Symbol) (defaults to: nil)
  • index_loader (#index_rule_for) (defaults to: nil)


45
46
47
48
49
50
51
# File 'lib/hyrax/indexer.rb', line 45

def initialize(rules = nil, schema_name: nil, index_loader: nil)
  super()
  @schema_name = schema_name
  @index_loader = index_loader
  @rules = rules
  define_solr_method(schema_name:, index_loader:)
end

Instance Attribute Details

#index_loaderObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



37
38
39
# File 'lib/hyrax/indexer.rb', line 37

def index_loader
  @index_loader
end

#schema_nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



37
38
39
# File 'lib/hyrax/indexer.rb', line 37

def schema_name
  @schema_name
end

Instance Method Details

#define_solr_method(schema_name:, index_loader:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable Metrics/MethodLength



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/hyrax/indexer.rb', line 53

def define_solr_method(schema_name:, index_loader:) # rubocop:disable Metrics/MethodLength
  define_method :to_solr do |*args|
    super(*args).tap do |document|
      schema_args = if index_loader.is_a?(Hyrax::M3SchemaLoader)
                      document['schema_version_ssi'] = resource.schema_version
                      document['contexts_ssim'] = resource.contexts
                      { schema: resource.class.name, version: resource.schema_version, contexts: resource.contexts }
                    else
                      { schema: schema_name }
                    end
      rules = @rules || index_loader.index_rules_for(**schema_args)

      rules.each do |index_key, method|
        document[index_key] = resource.try(method)
      end
    end
  end
end