Package org.dspace.util
Class SolrImportExport
java.lang.Object
org.dspace.util.SolrImportExport
Utility class to export, clear and import Solr indexes.
- Author:
- Andrea Schweer schweer@waikato.ac.nz for the LCoNZ Institutional Research Repositories
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclearIndex(String solrUrl) Remove all documents from the Solr index with the given URL, then commit and optimise the index.static voidexportIndex(String indexName, File toDir, String solrUrl, String timeField, boolean overwrite) Exports all documents in the given index to the specified target directory in batches of #ROWS_PER_FILE.static voidexportIndex(String indexName, File toDir, String solrUrl, String timeField, String fromWhen, boolean overwrite) Exports documents from the given index to the specified target directory in batches of #ROWS_PER_FILE, starting at fromWhen (or all documents).static voidimportIndex(String indexName, File fromDir, String solrUrl, boolean clear) Import previously exported documents (or externally created CSV files that have the appropriate structure) into the specified index.static voidEntry point for command-line invocation
-
Field Details
-
ROWS_PER_FILE
public static final int ROWS_PER_FILE- See Also:
-
-
Method Details
-
main
Entry point for command-line invocation- Parameters:
args- command-line arguments; see help for description- Throws:
org.apache.commons.cli.ParseException- if the command-line arguments cannot be parsed
-
exportIndex
public static void exportIndex(String indexName, File toDir, String solrUrl, String timeField, boolean overwrite) throws org.apache.solr.client.solrj.SolrServerException, SolrImportExportException, IOException Exports all documents in the given index to the specified target directory in batches of #ROWS_PER_FILE. See #makeExportFilename for the file names that are generated.- Parameters:
indexName- The index to export.toDir- The target directory for the export. Will be created if it doesn't exist yet. The directory must be writeable.solrUrl- The solr URL for the index to export. Must not be null.timeField- The time field to use for sorting the export. Must not be null.overwrite- If set, allow export files to be overwritten- Throws:
org.apache.solr.client.solrj.SolrServerException- if there is a problem with exporting the index.IOException- if there is a problem creating the files or communicating with Solr.SolrImportExportException- if there is a problem in communicating with Solr.
-
importIndex
public static void importIndex(String indexName, File fromDir, String solrUrl, boolean clear) throws IOException, org.apache.solr.client.solrj.SolrServerException, SolrImportExportException Import previously exported documents (or externally created CSV files that have the appropriate structure) into the specified index.- Parameters:
indexName- the index to import.fromDir- the source directory. Must exist and be readable. The importer will look for files whose name starts withindexName
and ends with .csv (to match what is generated by #makeExportFilename).solrUrl- The solr URL for the index to export. Must not be null.clear- if true, clear the index before importing.- Throws:
IOException- if there is a problem reading the files or communicating with Solr.org.apache.solr.client.solrj.SolrServerException- if there is a problem reading the files or communicating with Solr.SolrImportExportException- if there is a problem communicating with Solr.
-
clearIndex
public static void clearIndex(String solrUrl) throws IOException, org.apache.solr.client.solrj.SolrServerException Remove all documents from the Solr index with the given URL, then commit and optimise the index.- Parameters:
solrUrl- URL of the Solr core to clear.- Throws:
IOException- if there is a problem in communicating with Solr.org.apache.solr.client.solrj.SolrServerException- if there is a problem in communicating with Solr.
-
exportIndex
public static void exportIndex(String indexName, File toDir, String solrUrl, String timeField, String fromWhen, boolean overwrite) throws org.apache.solr.client.solrj.SolrServerException, IOException, SolrImportExportException Exports documents from the given index to the specified target directory in batches of #ROWS_PER_FILE, starting at fromWhen (or all documents). See #makeExportFilename for the file names that are generated.- Parameters:
indexName- The index to export.toDir- The target directory for the export. Will be created if it doesn't exist yet. The directory must be writeable.solrUrl- The solr URL for the index to export. Must not be null.timeField- The time field to use for sorting the export. Must not be null.fromWhen- Optionally, from when to export. See options for allowed values. If null or empty, all documents will be exported.overwrite- If set, allow export files to be overwritten- Throws:
org.apache.solr.client.solrj.SolrServerException- if there is a problem with exporting the index.IOException- if there is a problem creating the files or communicating with Solr.SolrImportExportException- if there is a problem in communicating with Solr.
-