SOLR-676 -- DataImportHandler should use UpdateRequestProcessor API instead of directly using UpdateHandler

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@684307 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2008-08-09 17:53:04 +00:00
parent d6fba67d5c
commit a29a3aee26
3 changed files with 28 additions and 23 deletions

View File

@ -519,6 +519,8 @@ Bug Fixes
44. SOLR-598: DebugComponent now always occurs last in the SearchHandler list unless the components are explicitly declared. (gsingers) 44. 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 Changes Other Changes
1. SOLR-135: Moved common classes to org.apache.solr.common and altered the 1. SOLR-135: Moved common classes to org.apache.solr.common and altered the
build scripts to make two jars: apache-solr-1.3.jar and build scripts to make two jars: apache-solr-1.3.jar and

View File

@ -16,12 +16,12 @@
*/ */
package org.apache.solr.handler.dataimport; package org.apache.solr.handler.dataimport;
import org.apache.lucene.document.Document;
import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams; 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.ContentStreamBase;
import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrConfig; 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.SolrQueryRequest;
import org.apache.solr.request.SolrQueryResponse; import org.apache.solr.request.SolrQueryResponse;
import org.apache.solr.schema.IndexSchema; import org.apache.solr.schema.IndexSchema;
import org.apache.solr.update.DocumentBuilder; import org.apache.solr.update.processor.UpdateRequestProcessor;
import org.apache.solr.update.UpdateHandler; import org.apache.solr.update.processor.UpdateRequestProcessorChain;
import org.apache.solr.util.plugin.SolrCoreAware; import org.apache.solr.util.plugin.SolrCoreAware;
import java.util.*; import java.util.*;
@ -77,7 +77,7 @@ public class DataImportHandler extends RequestHandlerBase implements
private DataImporter.RequestParams requestParams; private DataImporter.RequestParams requestParams;
private List<Document> debugDocuments; private List<SolrInputDocument> debugDocuments;
private DebugLogger debugLogger; private DebugLogger debugLogger;
@ -176,9 +176,12 @@ public class DataImportHandler extends RequestHandlerBase implements
} else if (command != null) { } else if (command != null) {
if (DataImporter.FULL_IMPORT_CMD.equals(command) if (DataImporter.FULL_IMPORT_CMD.equals(command)
|| DataImporter.DELTA_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(); SolrResourceLoader loader = req.getCore().getResourceLoader();
SolrWriter sw = getSolrWriter(updater, loader, req SolrWriter sw = getSolrWriter(processor, loader, req
.getSchema()); .getSchema());
if (requestParams.debug) { 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) { final SolrResourceLoader loader, final IndexSchema schema) {
return new SolrWriter(updater, loader.getConfigDir()) { return new SolrWriter(processor, loader.getConfigDir()) {
@Override @Override
public boolean upload(SolrDoc d) { public boolean upload(SolrDoc d) {
try { try {
Document document = DocumentBuilder.toDocument( SolrInputDocument document = ((SolrDocumentWrapper) d).doc;
((SolrDocumentWrapper) d).doc, schema);
if (requestParams.debug) { if (requestParams.debug) {
if (debugDocuments == null) if (debugDocuments == null)
debugDocuments = new ArrayList<Document>(); debugDocuments = new ArrayList<SolrInputDocument>();
debugDocuments.add(document); debugDocuments.add(document);
if (debugDocuments.size() >= requestParams.rows) { if (debugDocuments.size() >= requestParams.rows) {
// Abort this operation now // Abort this operation now

View File

@ -20,7 +20,8 @@ import org.apache.lucene.document.Document;
import org.apache.solr.update.AddUpdateCommand; import org.apache.solr.update.AddUpdateCommand;
import org.apache.solr.update.CommitUpdateCommand; import org.apache.solr.update.CommitUpdateCommand;
import org.apache.solr.update.DeleteUpdateCommand; 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.io.*;
import java.text.ParseException; import java.text.ParseException;
@ -48,29 +49,29 @@ public abstract class SolrWriter {
static final String LAST_INDEX_KEY = "last_index_time"; static final String LAST_INDEX_KEY = "last_index_time";
private final UpdateHandler updater; private final UpdateRequestProcessor processor;
private final String configDir; private final String configDir;
public SolrWriter(UpdateHandler updater, String confDir) { public SolrWriter(UpdateRequestProcessor processor, String confDir) {
this.updater = updater; this.processor = processor;
configDir = confDir; configDir = confDir;
} }
public boolean upload(Document d) { public boolean upload(SolrInputDocument d) {
try { try {
AddUpdateCommand command = new AddUpdateCommand(); AddUpdateCommand command = new AddUpdateCommand();
command.doc = d; command.solrDoc = d;
command.allowDups = false; command.allowDups = false;
command.overwritePending = true; command.overwritePending = true;
command.overwriteCommitted = true; command.overwriteCommitted = true;
updater.addDoc(command); processor.processAdd(command);
} catch (IOException e) { } catch (IOException e) {
LOG.log(Level.SEVERE, "Exception while adding: " + d, e); LOG.log(Level.SEVERE, "Exception while adding: " + d, e);
return false; return false;
} catch (Exception e) { } catch (Exception e) {
LOG.log(Level.WARNING, "Error creating document : " + d); LOG.log(Level.WARNING, "Error creating document : " + d, e);
return false; return false;
} }
@ -84,7 +85,7 @@ public abstract class SolrWriter {
delCmd.id = id.toString(); delCmd.id = id.toString();
delCmd.fromPending = true; delCmd.fromPending = true;
delCmd.fromCommitted = true; delCmd.fromCommitted = true;
updater.delete(delCmd); processor.processDelete(delCmd);
} catch (IOException e) { } catch (IOException e) {
LOG.log(Level.SEVERE, "Exception while deleteing: " + id, e); LOG.log(Level.SEVERE, "Exception while deleteing: " + id, e);
} }
@ -167,7 +168,7 @@ public abstract class SolrWriter {
delCmd.query = query; delCmd.query = query;
delCmd.fromCommitted = true; delCmd.fromCommitted = true;
delCmd.fromPending = true; delCmd.fromPending = true;
updater.deleteByQuery(delCmd); processor.processDelete(delCmd);
} catch (IOException e) { } catch (IOException e) {
LOG.log(Level.SEVERE, "Exception while deleting by query: " + query, 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) { public void commit(boolean optimize) {
try { try {
CommitUpdateCommand commit = new CommitUpdateCommand(optimize); CommitUpdateCommand commit = new CommitUpdateCommand(optimize);
updater.commit(commit); processor.processCommit(commit);
} catch (Exception e) { } catch (Exception e) {
LOG.log(Level.SEVERE, "Exception while solr commit.", e); LOG.log(Level.SEVERE, "Exception while solr commit.", e);
} }
@ -188,7 +189,7 @@ public abstract class SolrWriter {
deleteCommand.query = "*:*"; deleteCommand.query = "*:*";
deleteCommand.fromCommitted = true; deleteCommand.fromCommitted = true;
deleteCommand.fromPending = true; deleteCommand.fromPending = true;
updater.deleteByQuery(deleteCommand); processor.processDelete(deleteCommand);
} catch (IOException e) { } catch (IOException e) {
throw new DataImportHandlerException(DataImportHandlerException.SEVERE, throw new DataImportHandlerException(DataImportHandlerException.SEVERE,
"Exception in full dump while deleting all documents.", e); "Exception in full dump while deleting all documents.", e);