Created
November 16, 2018 00:01
-
-
Save mbklein/e1c7ee3320a99a3cbe422d67f27656b1 to your computer and use it in GitHub Desktop.
Add force_encoding(UTF-8) to full text indexing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveFedora::Base.class_eval do | |
def self.reindex_everything(batch_size: 50, softCommit: true, progress_bar: false, final_commit: false) | |
$stderr.puts "We're at it again, jerks!" | |
# skip root url | |
descendants = descendant_uris(ActiveFedora.fedora.base_uri, exclude_uri: true) | |
batch = [] | |
progress_bar_controller = ProgressBar.create(total: descendants.count, format: "%t: |%B| %p%% %e") if progress_bar | |
descendants.each do |uri| | |
logger.debug "Re-index everything ... #{uri}" | |
obj = ActiveFedora::Base.find(ActiveFedora::Base.uri_to_id(uri)) | |
solr_doc = obj.to_solr | |
solr_doc['all_text_timv'] = Array(solr_doc['all_text_timv']).collect do |text| | |
text.force_encoding(Encoding::UTF_8) | |
end | |
batch << solr_doc | |
if (batch.count % batch_size).zero? | |
ActiveFedora::SolrService.add(batch, softCommit: softCommit) | |
batch.clear | |
end | |
progress_bar_controller.increment if progress_bar_controller | |
end | |
if batch.present? | |
ActiveFedora::SolrService.add(batch, softCommit: softCommit) | |
batch.clear | |
end | |
if final_commit | |
logger.debug "Solr hard commit..." | |
ActiveFedora::SolrService.commit | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment