-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes error indexing (very) large records from PDC Describe #724
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
af1bd84
Started to diagnose the issue with importing very large records from …
hectorcorrea 1e3fe59
Got a working version. Still testing but it looks promising
hectorcorrea 14f8382
Use production describe as the source for indexing in staging
hectorcorrea 4ddac75
Testing a few configuration options for indexing into Solr
hectorcorrea cb2e6c2
More tuning and tweaking
hectorcorrea 6ce3111
Restore the indexing of files. Minor logging changes
hectorcorrea 9b712e1
Renable cronjob
hectorcorrea 683f020
Made PDC JSON compatible with previous version to prevent changes thr…
hectorcorrea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,26 @@ | |
provide 'solr.url', Indexing::SolrCloudHelper.collection_writer_url | ||
provide 'reader_class_name', 'Traject::NokogiriReader' | ||
provide 'solr_writer.commit_on_close', 'true' | ||
|
||
# There are some parameters in Traject that allows us to configure values related | ||
# to the Solr connection, in particular `batch_size` and the `thread_pool`. However, | ||
# given that we are calling traject for each individual record (rather than for a | ||
# batch of records) they might not apply to our scenario. | ||
# | ||
# The documentation is here in case we want to try them out: | ||
# https://www.rubydoc.info/gems/traject/Traject/SolrJsonWriter | ||
|
||
provide 'repository', ENV['REPOSITORY_ID'] | ||
provide 'logger', Logger.new($stderr, level: Logger::WARN) | ||
end | ||
|
||
# Converting the XML to JSON is a bit expensive therefore we make that conversion | ||
# only once per record and save it to the context so that we can re-use it. | ||
each_record do |record, context| | ||
xml = record.xpath("/hash").first.to_xml | ||
context.clipboard[:record_json] = Hash.from_xml(xml)["hash"].to_json | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the same data we were adding to the XML CDATA element above. |
||
end | ||
|
||
# ================== | ||
# Main fields | ||
|
||
|
@@ -25,10 +41,8 @@ | |
accumulator.concat [munged_doi] | ||
end | ||
|
||
# the <pdc_describe_json> element contains a CDATA node with a JSON blob in it | ||
to_field 'pdc_describe_json_ss' do |record, accumulator, _c| | ||
datacite = record.xpath("/hash/pdc_describe_json/text()").first.content | ||
accumulator.concat [datacite] | ||
to_field 'pdc_describe_json_ss' do |_record, accumulator, context| | ||
accumulator.concat [context.clipboard[:record_json]] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the value that we set in the |
||
end | ||
|
||
# Track the source of this record | ||
|
@@ -99,21 +113,21 @@ | |
end | ||
|
||
# Extract the author data from the pdc_describe_json and save it on its own field as JSON | ||
to_field 'authors_json_ss' do |record, accumulator, _c| | ||
pdc_json = record.xpath("/hash/pdc_describe_json/text()").first.content | ||
to_field 'authors_json_ss' do |_record, accumulator, context| | ||
pdc_json = context.clipboard[:record_json] | ||
authors = JSON.parse(pdc_json).dig("resource", "creators") || [] | ||
accumulator.concat [authors.to_json] | ||
end | ||
|
||
to_field 'authors_orcid_ssim' do |record, accumulator, _c| | ||
pdc_json = record.xpath("/hash/pdc_describe_json/text()").first.content | ||
to_field 'authors_orcid_ssim' do |_record, accumulator, context| | ||
pdc_json = context.clipboard[:record_json] | ||
authors_json = JSON.parse(pdc_json).dig("resource", "creators") || [] | ||
orcids = authors_json.map { |author| Author.new(author).orcid } | ||
accumulator.concat orcids.compact.uniq | ||
end | ||
|
||
to_field 'authors_affiliation_ssim' do |record, accumulator, _c| | ||
pdc_json = record.xpath("/hash/pdc_describe_json/text()").first.content | ||
to_field 'authors_affiliation_ssim' do |_record, accumulator, context| | ||
pdc_json = context.clipboard[:record_json] | ||
authors_json = JSON.parse(pdc_json).dig("resource", "creators") || [] | ||
affiliations = authors_json.map { |author| Author.new(author).affiliation_name } | ||
accumulator.concat affiliations.compact.uniq | ||
|
@@ -223,6 +237,10 @@ | |
|
||
# ================== | ||
# Store files metadata as a single JSON string so that we can display detailed information for each of them. | ||
# | ||
# TODO: Note that this information is duplicated with what we save in `pdc_describe_json_ss`. For large | ||
# datasets (e.g. those with 60K files) this is less than ideal. We should look into optimizing | ||
# this when we take care of https://github.com/pulibrary/pdc_discovery/issues/738 | ||
to_field 'files_ss' do |record, accumulator, _context| | ||
raw_doi = record.xpath("/hash/resource/doi/text()").to_s | ||
files = record.xpath("/hash/files/file").map do |file| | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the biggest change in this PR. Instead of adding a CDATA XML element with the PDC record as JSON here...we use the JSON that is available in Traject as-is (see below)