SOLR-1059 -- Fixing bug where skipping a row containing nested entities did not skip the nested entities. Handling special flag variables is in one method now.

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@764379 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2009-04-13 09:00:59 +00:00
parent 7c009e760d
commit 40a1e6da34
3 changed files with 49 additions and 31 deletions

View File

@ -87,7 +87,7 @@ public class DataConfig {
public boolean isDocRoot = false; public boolean isDocRoot = false;
public List<Field> fields; public List<Field> fields = new ArrayList<Field>();
public List<Map<String, String>> allFieldsList = new ArrayList<Map<String, String>>(); public List<Map<String, String>> allFieldsList = new ArrayList<Map<String, String>>();
@ -104,7 +104,7 @@ public class DataConfig {
public Script script; public Script script;
public Map<String, List<Field>> colNameVsField; public Map<String, List<Field>> colNameVsField = new HashMap<String, List<Field>>();
public Entity() { public Entity() {
} }
@ -121,8 +121,6 @@ public class DataConfig {
dataSource = getStringAttribute(element, DataImporter.DATA_SRC, null); dataSource = getStringAttribute(element, DataImporter.DATA_SRC, null);
allAttributes = getAllAttributes(element); allAttributes = getAllAttributes(element);
List<Element> n = getChildNodes(element, "field"); List<Element> n = getChildNodes(element, "field");
fields = new ArrayList<Field>();
colNameVsField = new HashMap<String, List<Field>>();
for (Element elem : n) { for (Element elem : n) {
Field field = new Field(elem); Field field = new Field(elem);
fields.add(field); fields.add(field);

View File

@ -31,7 +31,7 @@ public class DataImportHandlerException extends RuntimeException {
public boolean debugged = false; public boolean debugged = false;
public static final int SEVERE = 500, WARN = 400, SKIP = 300; public static final int SEVERE = 500, WARN = 400, SKIP = 300, SKIP_ROW =301;
public DataImportHandlerException(int err) { public DataImportHandlerException(int err) {
super(); super();

View File

@ -354,7 +354,8 @@ public class DocBuilder {
writer.log(SolrWriter.ENTITY_OUT, entity.name, arow); writer.log(SolrWriter.ENTITY_OUT, entity.name, arow);
} }
importStatistics.rowsCount.incrementAndGet(); importStatistics.rowsCount.incrementAndGet();
if (entity.fields != null && doc != null) { if (doc != null) {
handleSpecialCommands(arow);
addFields(entity, doc, arow); addFields(entity, doc, arow);
} }
if (isRoot) if (isRoot)
@ -382,6 +383,9 @@ public class DocBuilder {
if (verboseDebug) { if (verboseDebug) {
writer.log(SolrWriter.ENTITY_EXCEPTION, entity.name, e); writer.log(SolrWriter.ENTITY_EXCEPTION, entity.name, e);
} }
if(e.getErrCode() == DataImportHandlerException.SKIP_ROW){
continue;
}
if (isRoot) { if (isRoot) {
if (e.getErrCode() == DataImportHandlerException.SKIP) { if (e.getErrCode() == DataImportHandlerException.SKIP) {
importStatistics.skipDocCount.getAndIncrement(); importStatistics.skipDocCount.getAndIncrement();
@ -424,37 +428,53 @@ public class DocBuilder {
doc.setDocumentBoost(value); doc.setDocumentBoost(value);
} }
private void handleSpecialCommands(Map<String, Object> arow) {
Object value = arow.get("$deleteDocById");
if (value != null) {
if (value instanceof Collection) {
Collection collection = (Collection) value;
for (Object o : collection) {
writer.deleteDoc(o.toString());
}
} else {
writer.deleteDoc(value);
}
}
value = arow.get("$deleteDocByQuery");
if (value != null) {
if (value instanceof Collection) {
Collection collection = (Collection) value;
for (Object o : collection) {
writer.deleteByQuery(o.toString());
}
} else {
writer.deleteByQuery(value.toString());
}
}
value = arow.get("$skipDoc");
if (value != null) {
if (Boolean.parseBoolean(value.toString())) {
throw new DataImportHandlerException(DataImportHandlerException.SKIP,
"Document skipped :" + arow);
}
}
value = arow.get("$skipRow");
if (value != null) {
if (Boolean.parseBoolean(value.toString())) {
throw new DataImportHandlerException(DataImportHandlerException.SKIP_ROW);
}
}
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void addFields(DataConfig.Entity entity, SolrInputDocument doc, Map<String, Object> arow) { private void addFields(DataConfig.Entity entity, SolrInputDocument doc, Map<String, Object> arow) {
Object s = arow.get("$skipRow");
if (s != null && Boolean.parseBoolean(s.toString())) {
return;
}
for (Map.Entry<String, Object> entry : arow.entrySet()) { for (Map.Entry<String, Object> entry : arow.entrySet()) {
String key = entry.getKey(); String key = entry.getKey();
Object value = entry.getValue(); Object value = entry.getValue();
if (value == null) continue; if (value == null) continue;
if (key.startsWith("$")) { if (key.startsWith("$")) continue;
if ("$deleteDocById".equals(key)) {
if (value instanceof Collection) {
Collection collection = (Collection) value;
for (Object o : collection) {
writer.deleteDoc(o.toString());
}
} else {
writer.deleteDoc(value);
}
}
if ("$deleteDocByQuery".equals(key)) {
writer.deleteByQuery(entry.getValue().toString());
}
if ("$skipDoc".equals(key) && Boolean.parseBoolean(value.toString())) {
throw new DataImportHandlerException(DataImportHandlerException.SKIP,
"Document skipped :" + arow);
}
// All fields starting with $ are special values and don't need to be added
continue;
}
List<DataConfig.Field> field = entity.colNameVsField.get(key); List<DataConfig.Field> field = entity.colNameVsField.get(key);
if (field == null && dataImporter.getSchema() != null) { if (field == null && dataImporter.getSchema() != null) {
// This can be a dynamic field or a field which does not have an entry in data-config ( an implicit field) // This can be a dynamic field or a field which does not have an entry in data-config ( an implicit field)