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