SOLR-1973: Empty fields in update messages confuse DataImportHandler

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1032433 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Koji Sekiguchi 2010-11-08 00:58:31 +00:00
parent 4d0d625e7e
commit 7e1e45bfb9
3 changed files with 40 additions and 5 deletions

View File

@ -543,6 +543,8 @@ Bug Fixes
* SOLR-2057: DataImportHandler never calls UpdateRequestProcessor.finish()
(Drew Farris via koji)
* SOLR-1973: Empty fields in XML update messages confuse DataImportHandler. (koji)
Other Changes
----------------------

View File

@ -277,7 +277,7 @@ public class XPathRecordReader {
if (event == END_ELEMENT) {
if (flattenedStarts > 0) flattenedStarts--;
else {
if (text.length() > 0 && valuesAddedinThisFrame != null) {
if (hasText && valuesAddedinThisFrame != null) {
valuesAddedinThisFrame.add(fieldName);
putText(values, text.toString(), fieldName, multiValued);
}

View File

@ -194,6 +194,29 @@ public class TestXPathRecordReader extends AbstractDataImportHandlerTestCase {
assertNull(((List) l.get(1).get("b")).get(0));
}
@Test
public void testElems2LevelEmpty() {
String xml="<root>\n"
+ "\t<a>\n"
+ "\t <b>\n\t <x>x0</x>\n"
+ "\t <y>y0</y>\n"
+ "\t </b>\n"
+ "\t <b>\n\t <x></x>\n" // empty
+ "\t <y>y1</y>\n"
+ "\t </b>\n"
+ "\t</a>\n"
+ "</root>";
XPathRecordReader rr = new XPathRecordReader("/root/a");
rr.addField("a", "/root/a/b/x", true);
rr.addField("b", "/root/a/b/y", true);
List<Map<String, Object>> l = rr.getAllRecords(new StringReader(xml));
assertEquals(1, l.size());
assertEquals("x0",((List) l.get(0).get("a")).get(0));
assertEquals("y0",((List) l.get(0).get("b")).get(0));
assertEquals("",((List) l.get(0).get("a")).get(1));
assertEquals("y1",((List) l.get(0).get("b")).get(1));
}
@Test
public void testMixedContent() {
String xml = "<xhtml:p xmlns:xhtml=\"http://xhtml.com/\" >This text is \n" +
@ -236,12 +259,16 @@ public class TestXPathRecordReader extends AbstractDataImportHandlerTestCase {
public void testElems2LevelWithAttrib() {
String xml = "<root>\n\t<a>\n\t <b k=\"x\">\n"
+ "\t <x>x0</x>\n"
+ "\t <y>y0</y>\n"
+ "\t <y></y>\n" // empty
+ "\t </b>\n"
+ "\t <b k=\"y\">\n"
+ "\t <x>x1</x>\n"
+ "\t <x></x>\n" // empty
+ "\t <y>y1</y>\n"
+ "\t </b>\n"
+ "\t <b k=\"z\">\n"
+ "\t <x>x2</x>\n"
+ "\t <y>y2</y>\n"
+ "\t </b>\n"
+ "\t </a>\n"
+ "\t <a>\n\t <b>\n"
+ "\t <x>x3</x>\n"
@ -256,8 +283,14 @@ public class TestXPathRecordReader extends AbstractDataImportHandlerTestCase {
rr.addField("y", "/root/a/b[@k]/y", true);
List<Map<String, Object>> l = rr.getAllRecords(new StringReader(xml));
assertEquals(2, l.size());
assertEquals(2, ((List) l.get(0).get("x")).size());
assertEquals(2, ((List) l.get(0).get("y")).size());
assertEquals(3, ((List) l.get(0).get("x")).size());
assertEquals(3, ((List) l.get(0).get("y")).size());
assertEquals("x0", ((List) l.get(0).get("x")).get(0));
assertEquals("", ((List) l.get(0).get("y")).get(0));
assertEquals("", ((List) l.get(0).get("x")).get(1));
assertEquals("y1", ((List) l.get(0).get("y")).get(1));
assertEquals("x2", ((List) l.get(0).get("x")).get(2));
assertEquals("y2", ((List) l.get(0).get("y")).get(2));
assertEquals(0, l.get(1).size());
}