You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by ry...@apache.org on 2007/08/08 22:23:41 UTC
svn commit: r564010 - in /lucene/solr/trunk/src:
java/org/apache/solr/update/DocumentBuilder.java
test/org/apache/solr/update/DocumentBuilderTest.java
Author: ryan
Date: Wed Aug 8 13:23:36 2007
New Revision: 564010
URL: http://svn.apache.org/viewvc?view=rev&rev=564010
Log:
DocumentBuilder needs to skip null values. This adds a test to make sure that happens.
http://www.nabble.com/indexing-null-values--tf4238702.html
Modified:
lucene/solr/trunk/src/java/org/apache/solr/update/DocumentBuilder.java
lucene/solr/trunk/src/test/org/apache/solr/update/DocumentBuilderTest.java
Modified: lucene/solr/trunk/src/java/org/apache/solr/update/DocumentBuilder.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/update/DocumentBuilder.java?view=diff&rev=564010&r1=564009&r2=564010
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/update/DocumentBuilder.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/update/DocumentBuilder.java Wed Aug 8 13:23:36 2007
@@ -188,8 +188,13 @@
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 @@
}
// make sure the field was used somehow...
- if( !used ) {
+ if( !used && hasField ) {
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"ERROR:unknown field '" + name + "'");
}
}
Modified: lucene/solr/trunk/src/test/org/apache/solr/update/DocumentBuilderTest.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/update/DocumentBuilderTest.java?view=diff&rev=564010&r1=564009&r2=564010
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/update/DocumentBuilderTest.java (original)
+++ lucene/solr/trunk/src/test/org/apache/solr/update/DocumentBuilderTest.java Wed Aug 8 13:23:36 2007
@@ -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;
@@ -46,5 +47,16 @@
catch( SolrException ex ) {
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" ) );
}
}