Sha256: b0f29522bcb00509c1bea19f1fb1cfb5f623bed1818f4c281e0b168a863ad6f3

Contents?: true

Size: 1.55 KB

Versions: 18

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

module Spotlight
  # Creates solr documents for the uploaded documents in a resource
  class UploadSolrDocumentBuilder < SolrDocumentBuilder
    delegate :compound_id, to: :resource

    def to_solr
      super.tap do |solr_hash|
        add_default_solr_fields solr_hash
        add_sidecar_fields solr_hash

        if attached_file?
          add_image_dimensions solr_hash
          add_file_versions solr_hash
          add_manifest_path solr_hash
        end
      end
    end

    private

    def add_default_solr_fields(solr_hash)
      solr_hash[exhibit.blacklight_config.document_model.unique_key.to_sym] = compound_id
    end

    def add_image_dimensions(solr_hash)
      dimensions = Riiif::Image.new(resource.upload_id).info
      solr_hash[:spotlight_full_image_width_ssm] = dimensions.width
      solr_hash[:spotlight_full_image_height_ssm] = dimensions.height
    end

    def add_file_versions(solr_hash)
      solr_hash[Spotlight::Engine.config.thumbnail_field] = riiif.image_path(resource.upload_id, size: '!400,400')
    end

    def add_sidecar_fields(solr_hash)
      solr_hash.merge! resource.sidecar.to_solr
    end

    def add_manifest_path(solr_hash)
      solr_hash[Spotlight::Engine.config.iiif_manifest_field] = spotlight_routes.manifest_exhibit_solr_document_path(exhibit, resource.compound_id)
    end

    def spotlight_routes
      Spotlight::Engine.routes.url_helpers
    end

    def riiif
      Riiif::Engine.routes.url_helpers
    end

    def attached_file?
      resource.upload&.file_present?
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
blacklight-spotlight-3.0.0.rc3 app/services/spotlight/upload_solr_document_builder.rb
blacklight-spotlight-3.0.0.rc2 app/services/spotlight/upload_solr_document_builder.rb
blacklight-spotlight-3.0.0.rc1 app/services/spotlight/upload_solr_document_builder.rb
blacklight-spotlight-3.0.0.alpha.10 app/services/spotlight/upload_solr_document_builder.rb
blacklight-spotlight-3.0.0.alpha.9 app/services/spotlight/upload_solr_document_builder.rb
blacklight-spotlight-3.0.0.alpha.8 app/services/spotlight/upload_solr_document_builder.rb
blacklight-spotlight-3.0.0.alpha.7 app/services/spotlight/upload_solr_document_builder.rb
blacklight-spotlight-3.0.0.alpha.6 app/services/spotlight/upload_solr_document_builder.rb
blacklight-spotlight-3.0.0.alpha.5 app/services/spotlight/upload_solr_document_builder.rb
blacklight-spotlight-3.0.0.alpha.4 app/services/spotlight/upload_solr_document_builder.rb
blacklight-spotlight-3.0.0.alpha.3 app/services/spotlight/upload_solr_document_builder.rb
blacklight-spotlight-3.0.0.alpha.2 app/services/spotlight/upload_solr_document_builder.rb
blacklight-spotlight-3.0.0.alpha.1 app/services/spotlight/upload_solr_document_builder.rb
blacklight-spotlight-2.13.0 app/services/spotlight/upload_solr_document_builder.rb
blacklight-spotlight-2.12.1 app/services/spotlight/upload_solr_document_builder.rb
blacklight-spotlight-2.12.0 app/services/spotlight/upload_solr_document_builder.rb
blacklight-spotlight-2.9.0 app/services/spotlight/upload_solr_document_builder.rb
blacklight-spotlight-2.8.0 app/services/spotlight/upload_solr_document_builder.rb