Skip to content

Commit

Permalink
move full-text indexing to ObjectIndexer
Browse files Browse the repository at this point in the history
Otherwise re-indexing will not update all_text_timv
  • Loading branch information
dunn committed Apr 13, 2018
1 parent 0a9999d commit d0f74c9
Show file tree
Hide file tree
Showing 6 changed files with 4,564 additions and 2,068 deletions.
3 changes: 3 additions & 0 deletions app/indexers/object_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def generate_solr_document
solr_doc["uri_ssm"] =
"#{Settings.oai_identifier_prefix}#{object.identifier.first}"

# Full-Text Indexing
::FullTextToSolrJob.new(solr_doc).perform

yield(solr_doc) if block_given?
end
end
Expand Down
27 changes: 16 additions & 11 deletions app/jobs/full_text_to_solr_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,34 @@
class FullTextToSolrJob < ApplicationJob
# @return [String] the id for the SolrDocument being updated
# @return [IO] the PDF content
attr_reader :work_id, :logger
attr_reader :solr_doc

queue_as :default

def initialize(work_id, logger = Logger.new(STDOUT))
@work_id = work_id
@logger = logger
def initialize(solr_doc)
@solr_doc = solr_doc
end

def perform
return if all_text.nil?
solr_document = SolrDocument.find(@work_id).to_h
solr_document["all_text_timv"] = all_text
ActiveFedora::SolrService.add(solr_document)
return if solr_doc[:id].blank?
return if all_text.blank?

solr_doc["all_text_timv"] = all_text
ActiveFedora::SolrService.add(solr_doc)
ActiveFedora::SolrService.commit
@logger.info("Full text indexed for work: #{@work_id}")
end

private

def work
ActiveFedora::Base.find(solr_doc[:id])
end

def files
return nil if ActiveFedora::Base.find(@work_id).class == Collection
ActiveFedora::Base.find(@work_id).file_sets.map(&:files).flatten
unless CurationConcerns.config.registered_curation_concern_types.include?(work.class.to_s)
return nil
end
work.file_sets.map(&:files).flatten
end

def all_text
Expand Down
2 changes: 0 additions & 2 deletions lib/importer/factory/object_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ def create

logger.info "Created #{klass.model_name.human} #{object.id} "\
"(#{Array(attributes[system_identifier_field]).first})"
# Full-Text Indexing
::FullTextToSolrJob.new(object.id, @logger).perform
end

def update
Expand Down
Loading

0 comments on commit d0f74c9

Please sign in to comment.