Sha256: e752f496d74b8e9454b16703750a5a96fbcbe0ea3e38af27d189ee896d0ee252

Contents?: true

Size: 1.31 KB

Versions: 14

Compression:

Stored size: 1.31 KB

Contents

module Sufia
  module GenericFile
    module FullTextIndexing
      extend ActiveSupport::Concern

      included do
        has_file_datastream 'full_text', versionable: false
      end

      def append_metadata
        super
        extract_content
      end

      private

        def extract_content
          url = Blacklight.solr_config[:url] ? Blacklight.solr_config[:url] : Blacklight.solr_config["url"] ? Blacklight.solr_config["url"] : Blacklight.solr_config[:fulltext] ? Blacklight.solr_config[:fulltext]["url"] : Blacklight.solr_config[:default]["url"]
          uri = URI("#{url}/update/extract?extractOnly=true&wt=json&extractFormat=text")
          req = Net::HTTP.new(uri.host, uri.port)
          resp = req.post(uri.to_s, self.content.content, {
              'Content-type' => "#{self.mime_type};charset=utf-8",
              'Content-Length' => self.content.content.size.to_s
            })
          raise "URL '#{uri}' returned code #{resp.code}" unless resp.code == "200"
          self.content.content.rewind if self.content.content.respond_to?(:rewind)
          extracted_text = JSON.parse(resp.body)[''].rstrip
          full_text.content = extracted_text if extracted_text.present?
        rescue => e
          logger.error("Error extracting content from #{self.pid}: #{e.inspect}")
        end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
sufia-5.0.0 sufia-models/app/models/concerns/sufia/generic_file/full_text_indexing.rb
sufia-models-5.0.0 app/models/concerns/sufia/generic_file/full_text_indexing.rb
sufia-5.0.0.rc1 sufia-models/app/models/concerns/sufia/generic_file/full_text_indexing.rb
sufia-models-5.0.0.rc1 app/models/concerns/sufia/generic_file/full_text_indexing.rb
sufia-4.3.1 sufia-models/app/models/concerns/sufia/generic_file/full_text_indexing.rb
sufia-models-4.3.1 app/models/concerns/sufia/generic_file/full_text_indexing.rb
sufia-4.2.0 sufia-models/app/models/concerns/sufia/generic_file/full_text_indexing.rb
sufia-models-4.2.0 app/models/concerns/sufia/generic_file/full_text_indexing.rb
sufia-4.1.0 sufia-models/app/models/concerns/sufia/generic_file/full_text_indexing.rb
sufia-models-4.1.0 app/models/concerns/sufia/generic_file/full_text_indexing.rb
sufia-4.0.1 sufia-models/app/models/concerns/sufia/generic_file/full_text_indexing.rb
sufia-models-4.0.1 app/models/concerns/sufia/generic_file/full_text_indexing.rb
sufia-models-4.0.0 app/models/concerns/sufia/generic_file/full_text_indexing.rb
sufia-4.0.0 sufia-models/app/models/concerns/sufia/generic_file/full_text_indexing.rb