Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 59 additions & 1 deletion lib/bibdata_rs/src/marc/contributors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use itertools::Itertools;
use marctk::{Field, Record};

use crate::{marc::trim_punctuation, solr::AuthorRoles};
use crate::{marc::trim_punctuation, solr::AuthorRoles, solr::ExpandedAuthor};

impl From<&Record> for AuthorRoles {
fn from(record: &Record) -> Self {
Expand Down Expand Up @@ -42,6 +43,31 @@ impl From<&Record> for AuthorRoles {
}
}

impl From<&Record> for ExpandedAuthor {
fn from(record: &Record) -> Self {
let author_fields = record.extract_fields("100");
let parallel_fields =
record
.get_fields("880")
.into_iter()
.filter(|field| matches!(field.first_subfield("6"), Some(subfield) if subfield.content().starts_with("100")));
let expanded_author = author_fields
.chain(parallel_fields)
.map(|field| {
field
.subfields()
.iter()
.filter(|subfield| subfield.code() == "a")
.map(|subfield| subfield.content())
.join(" ")
})
.collect::<Vec<String>>();
Self {
author: Some(expanded_author),
}
}
}

enum ContributorType {
Compiler,
Editor,
Expand Down Expand Up @@ -139,6 +165,38 @@ mod tests {
editors: vec!["Eugenides, Jeffrey".to_owned()],
compilers: vec!["Cole, Teju".to_owned()]
}
);
assert_eq!(
ExpandedAuthor::from(&record),
ExpandedAuthor {
author: Some(vec!("".to_owned(), "".to_owned()))
}
);
}

#[test]
fn it_can_find_expanded_author_from_marc_record() {
let record = Record::from_breaker(
r#"=100 \\$6880-01$aṢaffūrī, ʻAlī ibn ʻAbd al-Raḥmān,
=880 \\$6100-01$aصفوري، علي بن عبد الرحمن.
=700 \\$aEugenides, Jeffrey$4edt
=700 \\$aCole, Teju$4com
=700 \\$aNikolakopoulou, Evangelia$4trl
=700 \\$aMorrison, Toni$4aaa
=700 \\$aOates, Joyce Carol
=700 \\$aMarchesi, Simone$etranslator.
=700 \\$aFitzgerald, F. Scott$eed."#
)
.unwrap();

assert_eq!(
ExpandedAuthor::from(&record),
ExpandedAuthor {
author: Some(vec!(
"Ṣaffūrī, ʻAlī ibn ʻAbd al-Raḥmān,".to_owned(),
"صفوري، علي بن عبد الرحمن.".to_owned()
))
}
)
}
}
2 changes: 1 addition & 1 deletion lib/bibdata_rs/src/marc/ruby_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fn solr_fields(ruby: &Ruby, record: magnus::RObject) -> Result<RHash, magnus::Er
.ok()
.and_then(|date| date.maybe_to_string());

let hash = ruby.hash_new_capa(38);
let hash = ruby.hash_new();
hash.aset("aat_s", ruby.ary_from_iter(genre::aat_s(&record)))?;
hash.aset("action_notes_1display", action_notes_1display)?;
hash.aset("access_restrictions_note_display", access_notes(&record))?;
Expand Down
2 changes: 2 additions & 0 deletions lib/bibdata_rs/src/solr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod builder;
mod dataspace_solr_mapping;
mod electronic_access;
mod ephemera_solr_mapping;
mod expanded_author;
mod format_facet;
mod library_facet;

Expand All @@ -15,6 +16,7 @@ pub use author_roles::AuthorRoles;
pub use builder::SolrDocumentBuilder;
pub use electronic_access::DigitalContent;
pub use electronic_access::ElectronicAccess;
pub use expanded_author::ExpandedAuthor;
pub use format_facet::FormatFacet;
pub use library_facet::LibraryFacet;
pub use solr_document::SolrDocument;
7 changes: 7 additions & 0 deletions lib/bibdata_rs/src/solr/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct SolrDocumentBuilder {
author_roles_1display: Option<AuthorRoles>,
author_citation_display: Option<Vec<String>>,
advisor_display: Option<Vec<String>>,
expanded_author_display: Option<Vec<String>>,
format: Option<Vec<FormatFacet>>,
geographic_facet: Option<Vec<String>>,
id: String,
Expand Down Expand Up @@ -77,6 +78,11 @@ impl SolrDocumentBuilder {
self
}

pub fn with_expanded_author(&mut self, expanded_author: Option<Vec<String>>) -> &mut Self {
self.expanded_author_display = expanded_author;
self
}

pub fn with_title_t(&mut self, title_t: Option<Vec<String>>) -> &mut Self {
self.title_t = title_t;
self
Expand Down Expand Up @@ -335,6 +341,7 @@ impl SolrDocumentBuilder {
call_number_display: self.call_number_display.clone(),
call_number_browse_s: self.call_number_browse_s.clone(),
electronic_access_1display: self.electronic_access_1display.clone(),
expanded_author_display: self.expanded_author_display.clone(),
geographic_facet: self.geographic_facet.clone(),
id: self.id.clone(),
restrictions_display_text: self.restrictions_display_text.clone(),
Expand Down
8 changes: 8 additions & 0 deletions lib/bibdata_rs/src/solr/expanded_author.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This module is responsible for creating a field with the author and any related 880 field

use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct ExpandedAuthor {
pub author: Option<Vec<String>>,
}
2 changes: 2 additions & 0 deletions lib/bibdata_rs/src/solr/solr_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub struct SolrDocument {
#[serde(skip_serializing_if = "Option::is_none")]
pub electronic_portfolio_s: Option<String>,

pub expanded_author_display: Option<Vec<String>>,

pub format: Option<Vec<FormatFacet>>,

#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
4 changes: 4 additions & 0 deletions marc_to_solr/lib/traject_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@
accumulator.replace(names)
end

to_field 'expanded_author_display' do |record, accumulator, context|
accumulator.replace context.clipboard[:solr_fields]['expanded_author_display']
end

# for now not separate
# to_field 'author_vern_display', extract_marc('100aqbcdek:110abcdefgkln:111abcdefgklnpq', :trim_punctuation => true, :alternate_script => :only, :first => true)

Expand Down
2 changes: 2 additions & 0 deletions spec/marc_to_solr/lib/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,8 @@ def fixture_record(fixture_name, indexer: @indexer)
expect(@local_subject_heading['lc_subject_display']).to include("Undocumented immigrants#{SEPARATOR}Europe")
expect(@local_subject_heading['local_subject_display']).to eq(["Undocumented immigrants#{SEPARATOR}Europe"])
expect(@siku_subject_headings['siku_subject_display']).to contain_exactly('Zi bu—Zhu jia lei—Jidu jiao zhi shu', '子部—諸家類—基督教之屬', 'Zi bu—Tian wen suan fa lei—Li fa.', '子部—天文算法類—曆法.')
byebug
expect(@siku_subject_headings['expanded_author_display']).to contian_exactly('', '')
end
end

Expand Down