Apache Lucene open-source search software
SOLR-676 -- DataImportHandler should use UpdateRequestProcessor API instead of directly using UpdateHandler
Shalin Shekhar Mangara29a3aee2662
diff --git a/CHANGES.txt b/CHANGES.txtindex a3ddfc7ef54..0a6fab4a63e 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -519,6 +519,8 @@ Bug Fixes44. SOLR-598: DebugComponent now always occurs last in the SearchHandler list unless the components are explicitly declared. (gsingers)+45. SOLR-676: DataImportHandler should use UpdateRequestProcessor API instead of directly using UpdateHandler. (shalin)+Other Changes1. SOLR-135: Moved common classes to org.apache.solr.common and altered thebuild scripts to make two jars: apache-solr-1.3.jar anddiff --git a/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataImportHandler.java b/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataImportHandler.javaindex 0df046ff883..eb86323d394 100644--- a/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataImportHandler.java+++ b/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DataImportHandler.java@@ -16,12 +16,12 @@*/package org.apache.solr.handler.dataimport;-import org.apache.lucene.document.Document;import org.apache.solr.common.SolrException;import org.apache.solr.common.SolrInputDocument;import org.apache.solr.common.params.CommonParams;import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.common.params.SolrParams;+import org.apache.solr.common.params.UpdateParams;import org.apache.solr.common.util.ContentStreamBase;import org.apache.solr.common.util.NamedList;import org.apache.solr.core.SolrConfig;@@ -33,8 +33,8 @@ import org.apache.solr.request.RawResponseWriter;import org.apache.solr.request.SolrQueryRequest;import org.apache.solr.request.SolrQueryResponse;import org.apache.solr.schema.IndexSchema;-import org.apache.solr.update.DocumentBuilder;-import org.apache.solr.update.UpdateHandler;+import org.apache.solr.update.processor.UpdateRequestProcessor;+import org.apache.solr.update.processor.UpdateRequestProcessorChain;import org.apache.solr.util.plugin.SolrCoreAware;import java.util.*;@@ -77,7 +77,7 @@ public class DataImportHandler extends RequestHandlerBase implementsprivate DataImporter.RequestParams requestParams;- private List<Document> debugDocuments;+ private List<SolrInputDocument> debugDocuments;private DebugLogger debugLogger;@@ -176,9 +176,12 @@ public class DataImportHandler extends RequestHandlerBase implements} else if (command != null) {if (DataImporter.FULL_IMPORT_CMD.equals(command)|| DataImporter.DELTA_IMPORT_CMD.equals(command)) {- UpdateHandler updater = req.getCore().getUpdateHandler();++ UpdateRequestProcessorChain processorChain =+ req.getCore().getUpdateProcessingChain(params.get(UpdateParams.UPDATE_PROCESSOR));+ UpdateRequestProcessor processor = processorChain.createProcessor(req, rsp);SolrResourceLoader loader = req.getCore().getResourceLoader();- SolrWriter sw = getSolrWriter(updater, loader, req+ SolrWriter sw = getSolrWriter(processor, loader, req.getSchema());if (requestParams.debug) {@@ -263,19 +266,18 @@ public class DataImportHandler extends RequestHandlerBase implements}}- private SolrWriter getSolrWriter(final UpdateHandler updater,+ private SolrWriter getSolrWriter(final UpdateRequestProcessor processor,final SolrResourceLoader loader, final IndexSchema schema) {- return new SolrWriter(updater, loader.getConfigDir()) {+ return new SolrWriter(processor, loader.getConfigDir()) {@Overridepublic boolean upload(SolrDoc d) {try {- Document document = DocumentBuilder.toDocument(- ((SolrDocumentWrapper) d).doc, schema);+ SolrInputDocument document = ((SolrDocumentWrapper) d).doc;if (requestParams.debug) {if (debugDocuments == null)- debugDocuments = new ArrayList<Document>();+ debugDocuments = new ArrayList<SolrInputDocument>();debugDocuments.add(document);if (debugDocuments.size() >= requestParams.rows) {// Abort this operation nowdiff --git a/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/SolrWriter.java b/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/SolrWriter.javaindex f1ea9e23033..a6ff1213c88 100644--- a/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/SolrWriter.java+++ b/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/SolrWriter.java@@ -20,7 +20,8 @@ import org.apache.lucene.document.Document;import org.apache.solr.update.AddUpdateCommand;import org.apache.solr.update.CommitUpdateCommand;import org.apache.solr.update.DeleteUpdateCommand;-import org.apache.solr.update.UpdateHandler;+import org.apache.solr.update.processor.UpdateRequestProcessor;+import org.apache.solr.common.SolrInputDocument;import java.io.*;import java.text.ParseException;@@ -48,29 +49,29 @@ public abstract class SolrWriter {static final String LAST_INDEX_KEY = "last_index_time";- private final UpdateHandler updater;+ private final UpdateRequestProcessor processor;private final String configDir;- public SolrWriter(UpdateHandler updater, String confDir) {- this.updater = updater;+ public SolrWriter(UpdateRequestProcessor processor, String confDir) {+ this.processor = processor;configDir = confDir;}- public boolean upload(Document d) {+ public boolean upload(SolrInputDocument d) {try {AddUpdateCommand command = new AddUpdateCommand();- command.doc = d;+ command.solrDoc = d;command.allowDups = false;command.overwritePending = true;command.overwriteCommitted = true;- updater.addDoc(command);+ processor.processAdd(command);} catch (IOException e) {LOG.log(Level.SEVERE, "Exception while adding: " + d, e);return false;} catch (Exception e) {- LOG.log(Level.WARNING, "Error creating document : " + d);+ LOG.log(Level.WARNING, "Error creating document : " + d, e);return false;}@@ -84,7 +85,7 @@ public abstract class SolrWriter {delCmd.id = id.toString();delCmd.fromPending = true;delCmd.fromCommitted = true;- updater.delete(delCmd);+ processor.processDelete(delCmd);} catch (IOException e) {LOG.log(Level.SEVERE, "Exception while deleteing: " + id, e);}@@ -167,7 +168,7 @@ public abstract class SolrWriter {delCmd.query = query;delCmd.fromCommitted = true;delCmd.fromPending = true;- updater.deleteByQuery(delCmd);+ processor.processDelete(delCmd);} catch (IOException e) {LOG.log(Level.SEVERE, "Exception while deleting by query: " + query, e);}@@ -176,7 +177,7 @@ public abstract class SolrWriter {public void commit(boolean optimize) {try {CommitUpdateCommand commit = new CommitUpdateCommand(optimize);- updater.commit(commit);+ processor.processCommit(commit);} catch (Exception e) {LOG.log(Level.SEVERE, "Exception while solr commit.", e);}@@ -188,7 +189,7 @@ public abstract class SolrWriter {deleteCommand.query = "*:*";deleteCommand.fromCommitted = true;deleteCommand.fromPending = true;- updater.deleteByQuery(deleteCommand);+ processor.processDelete(deleteCommand);} catch (IOException e) {throw new DataImportHandlerException(DataImportHandlerException.SEVERE,"Exception in full dump while deleting all documents.", e);