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 ho...@apache.org on 2010/02/18 00:52:38 UTC

svn commit: r911228 - in /lucene/solr/trunk: CHANGES.txt src/java/org/apache/solr/update/DocumentBuilder.java

Author: hossman
Date: Wed Feb 17 23:52:38 2010
New Revision: 911228

URL: http://svn.apache.org/viewvc?rev=911228&view=rev
Log:
SOLR-1695: Improved error message when adding a document that does not contain a value for the uniqueKey field

Modified:
    lucene/solr/trunk/CHANGES.txt
    lucene/solr/trunk/src/java/org/apache/solr/update/DocumentBuilder.java

Modified: lucene/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=911228&r1=911227&r2=911228&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Wed Feb 17 23:52:38 2010
@@ -242,6 +242,9 @@
 * SOLR-1771: Improved error message when StringIndex cannot be initialized
   for a function query (hossman)
 
+* SOLR-1695: Improved error message when adding a document that does not
+  contain a value for the uniqueKey field (hossman)
+
 Build
 ----------------------
 

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?rev=911228&r1=911227&r2=911228&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/update/DocumentBuilder.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/update/DocumentBuilder.java Wed Feb 17 23:52:38 2010
@@ -17,6 +17,7 @@
 
 package org.apache.solr.update;
 
+import java.util.Collection;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -225,6 +226,16 @@
   { 
     Document out = new Document();
     out.setBoost( doc.getDocumentBoost() );
+
+    final SchemaField uniqueKeyField = schema.getUniqueKeyField();
+    if (null != uniqueKeyField) {
+      Collection<Object> keys = doc.getFieldValues(uniqueKeyField.getName());
+      if (null == keys || keys.isEmpty()) {
+        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
+                                "Document missing value for uniqueKeyField: " +
+                                uniqueKeyField.getName());
+      }
+    }
     
     // Load fields from SolrDocument to Document
     for( SolrInputField field : doc ) {
@@ -235,11 +246,10 @@
       
       // Make sure it has the correct number
       if( sfield!=null && !sfield.multiValued() && field.getValueCount() > 1 ) {
-        String id = "";
-        SchemaField sf = schema.getUniqueKeyField();
-        if( sf != null ) {
-          id = "["+doc.getFieldValue( sf.getName() )+"] ";
-        }
+        String id = ( uniqueKeyField == null )
+          ? ""
+          : ("["+doc.getFieldValue( uniqueKeyField.getName() )+"] ");
+
         throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
             "ERROR: "+id+"multiple values encountered for non multiValued field " + 
               sfield.getName() + ": " +field.getValue() );