diff --git a/dspace-api/src/main/java/org/dspace/discovery/SolrServiceFileInfoPlugin.java b/dspace-api/src/main/java/org/dspace/discovery/SolrServiceFileInfoPlugin.java new file mode 100644 index 0000000000..6c42e7f43e --- /dev/null +++ b/dspace-api/src/main/java/org/dspace/discovery/SolrServiceFileInfoPlugin.java @@ -0,0 +1,70 @@ +package org.dspace.discovery; + +import org.apache.solr.common.SolrInputDocument; +import org.dspace.content.Bitstream; +import org.dspace.content.Bundle; +import org.dspace.content.DSpaceObject; +import org.dspace.content.Item; +import org.dspace.core.Context; + +import java.util.List; + +/** + *

+ * Adds filenames and file descriptions of all files in the ORIGINAL bundle + * to the Solr search index. + * + *

+ * To activate the plugin, add the following line to discovery.xml + *

+ * {@code }
+ * 
+ * + *

+ * After activating the plugin, rebuild the discovery index by executing: + *

+ * [dspace]/bin/dspace index-discovery -b
+ * 
+ * + * @author Martin Walk + */ +public class SolrServiceFileInfoPlugin implements SolrServiceIndexPlugin +{ + private static final String BUNDLE_NAME = "ORIGINAL"; + private static final String SOLR_FIELD_NAME_FOR_FILENAMES = "original_bundle_filenames"; + private static final String SOLR_FIELD_NAME_FOR_DESCRIPTIONS = "original_bundle_descriptions"; + + @Override + public void additionalIndex(Context context, DSpaceObject dso, SolrInputDocument document) + { + if (dso instanceof Item) + { + Item item = (Item) dso; + List bundles = item.getBundles(); + if (bundles != null) + { + for (Bundle bundle : bundles) + { + String bundleName = bundle.getName(); + if ((bundleName != null) && bundleName.equals(BUNDLE_NAME)) + { + List bitstreams = bundle.getBitstreams(); + if (bitstreams != null) + { + for (Bitstream bitstream : bitstreams) + { + document.addField(SOLR_FIELD_NAME_FOR_FILENAMES, bitstream.getName()); + + String description = bitstream.getDescription(); + if ((description != null) && (!description.isEmpty())) + { + document.addField(SOLR_FIELD_NAME_FOR_DESCRIPTIONS, description); + } + } + } + } + } + } + } + } +} diff --git a/dspace/config/spring/api/discovery.xml b/dspace/config/spring/api/discovery.xml index 1add0dcaa5..a17abfef71 100644 --- a/dspace/config/spring/api/discovery.xml +++ b/dspace/config/spring/api/discovery.xml @@ -31,6 +31,9 @@ + + +