DocumentBuilder needs to skip null values. This adds a test to make sure that happens.

http://www.nabble.com/indexing-null-values--tf4238702.html

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@564010 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ryan McKinley 2007-08-08 20:23:36 +00:00
parent e8533194c0
commit 06b56541a6
2 changed files with 18 additions and 1 deletions

View File

@ -188,8 +188,13 @@ public class DocumentBuilder {
SchemaField[] destArr = schema.getCopyFields(name);
// load each field value
boolean hasField = false;
for( Object v : field ) {
if( v == null ) {
continue;
}
String val = null;
hasField = true;
// TODO!!! HACK -- date conversion
if( sfield != null && v instanceof Date && sfield.getType() instanceof DateField ) {
@ -232,7 +237,7 @@ public class DocumentBuilder {
}
// make sure the field was used somehow...
if( !used ) {
if( !used && hasField ) {
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"ERROR:unknown field '" + name + "'");
}
}

View File

@ -17,6 +17,7 @@
package org.apache.solr.update;
import org.apache.lucene.document.Document;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.core.SolrCore;
@ -47,4 +48,15 @@ public class DocumentBuilderTest extends AbstractSolrTestCase {
assertEquals( "should be bad request", 400, ex.code() );
}
}
public void testNullField()
{
SolrCore core = SolrCore.getSolrCore();
// make sure a null value is not indexed
SolrInputDocument doc = new SolrInputDocument();
doc.addField( "name", null, 1.0f );
Document out = DocumentBuilder.toDocument( doc, core.getSchema() );
assertNull( out.get( "name" ) );
}
}