diff --git a/src/main/java/de/gwdg/metadataqa/marc/cli/MarcToSolr.java b/src/main/java/de/gwdg/metadataqa/marc/cli/MarcToSolr.java index 79f660a0..c6e29557 100644 --- a/src/main/java/de/gwdg/metadataqa/marc/cli/MarcToSolr.java +++ b/src/main/java/de/gwdg/metadataqa/marc/cli/MarcToSolr.java @@ -28,6 +28,7 @@ import java.io.Serializable; import java.nio.file.Path; import java.text.DecimalFormat; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -207,6 +208,7 @@ private void indexFieldCounts(BibliographicRecord bibliographicRecord, SolrInputDocument document) { Counter counter = new Counter<>(); boolean isPica = bibliographicRecord.getSchemaType().equals(SchemaType.PICA); + Map> subfields = new HashMap<>(); for (DataField field : bibliographicRecord.getDatafields()) { String tag; if (field.getDefinition() != null) { @@ -221,9 +223,15 @@ private void indexFieldCounts(BibliographicRecord bibliographicRecord, counter.count(safeTag); if (parameters.isIndexSubfieldCounts()) { + Counter subfieldCounter = new Counter<>(); for (MarcSubfield subfield : field.getSubfields()) { String safeSubfieldCode = DataFieldKeyGenerator.escape(subfield.getCode()); - counter.count(safeTag + safeSubfieldCode); + subfieldCounter.count(safeTag + safeSubfieldCode); + } + for (Map.Entry entry : subfieldCounter.entrySet()) { + if (!subfields.containsKey(entry.getKey())) + subfields.put(entry.getKey(), new ArrayList<>()); + subfields.get(entry.getKey()).add(entry.getValue()); } } } @@ -232,6 +240,14 @@ private void indexFieldCounts(BibliographicRecord bibliographicRecord, "%s%s_count_i", parameters.getFieldPrefix(), entry.getKey()), entry.getValue()); } + + if (parameters.isIndexSubfieldCounts()) { + for (Map.Entry> entry : subfields.entrySet()) { + document.addField(String.format( + "%s%s_count_is", + parameters.getFieldPrefix(), entry.getKey()), entry.getValue()); + } + } } private String escape(String tag) { diff --git a/src/main/java/de/gwdg/metadataqa/marc/cli/parameters/MarcToSolrParameters.java b/src/main/java/de/gwdg/metadataqa/marc/cli/parameters/MarcToSolrParameters.java index 89d2a035..257ccfbd 100644 --- a/src/main/java/de/gwdg/metadataqa/marc/cli/parameters/MarcToSolrParameters.java +++ b/src/main/java/de/gwdg/metadataqa/marc/cli/parameters/MarcToSolrParameters.java @@ -123,7 +123,7 @@ public boolean isIndexSubfieldCounts() { } public String getFieldPrefix() { - return fieldPrefix; + return fieldPrefix != null ? fieldPrefix : ""; } public void setFieldPrefix(String fieldPrefix) {