Sha256: d48ee892091548ed92918674e5f37897fbde56b7787f6c429687b5a3ebc2221d

Contents?: true

Size: 1.36 KB

Versions: 18

Compression:

Stored size: 1.36 KB

Contents

module ActiveFedora::RDF
  module DatastreamIndexing
    extend ActiveSupport::Concern

    def to_solr(solr_doc = {}, opts = {}) # :nodoc:
      super.tap do |new_doc|
        solrize_rdf_assertions(opts[:name], new_doc)
      end
    end

    module ClassMethods
      def indexer
        ActiveFedora::RDF::IndexingService
      end

      def index_config
        @index_config ||= ActiveFedora::Indexing::Map.new
      end
    end

    protected

      def indexing_service
        @indexing_service ||= self.class.indexer.new(self)
      end

      # Serialize the datastream's RDF relationships to solr
      # @param [String] file_path used to prefix the keys in the solr document
      # @param [Hash] solr_doc @default an empty Hash
      def solrize_rdf_assertions(file_path, solr_doc = {})
        solr_doc.merge! indexing_service.generate_solr_document(prefix_method(file_path))
      end

      # Returns a function that takes field name and returns a solr document key
      def prefix_method(file_path)
        ->(field_name) { apply_prefix(field_name, file_path) }
      end

      def apply_prefix(name, file_path)
        prefix(file_path) + name.to_s
      end

      # The string to prefix all solr fields with. Override this method if you want
      # a prefix other than the default
      def prefix(path)
        path ? "#{path.underscore}__" : ''
      end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
active_fedora-datastreams-0.5.0 lib/active_fedora/rdf/datastream_indexing.rb
active_fedora-datastreams-0.4.0 lib/active_fedora/rdf/datastream_indexing.rb
active_fedora-datastreams-0.3.0 lib/active_fedora/rdf/datastream_indexing.rb
active_fedora-datastreams-0.2.0 lib/active_fedora/rdf/datastream_indexing.rb
active-fedora-10.3.0 lib/active_fedora/rdf/datastream_indexing.rb
active_fedora-datastreams-0.1.0 lib/active_fedora/rdf/datastream_indexing.rb
active-fedora-10.3.0.rc2 lib/active_fedora/rdf/datastream_indexing.rb
active-fedora-10.3.0.rc1 lib/active_fedora/rdf/datastream_indexing.rb
active-fedora-11.0.0.rc6 lib/active_fedora/rdf/datastream_indexing.rb
active-fedora-10.2.1 lib/active_fedora/rdf/datastream_indexing.rb
active-fedora-11.0.0.rc5 lib/active_fedora/rdf/datastream_indexing.rb
active-fedora-11.0.0.rc4 lib/active_fedora/rdf/datastream_indexing.rb
active-fedora-10.2.0 lib/active_fedora/rdf/datastream_indexing.rb
active-fedora-11.0.0.rc3 lib/active_fedora/rdf/datastream_indexing.rb
active-fedora-11.0.0.rc2 lib/active_fedora/rdf/datastream_indexing.rb
active-fedora-11.0.0.rc1 lib/active_fedora/rdf/datastream_indexing.rb
active-fedora-10.1.0 lib/active_fedora/rdf/datastream_indexing.rb
active-fedora-10.1.0.rc1 lib/active_fedora/rdf/datastream_indexing.rb