SOLR-1695: Improved error message when adding a document that does not contain a value for the uniqueKey field

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@911228 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2010-02-17 23:52:38 +00:00
parent adadefd6f8
commit fb0ccdf724
2 changed files with 18 additions and 5 deletions

View File

@ -242,6 +242,9 @@ Other Changes
* 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
----------------------

View File

@ -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 @@ public class DocumentBuilder {
{
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 @@ public class DocumentBuilder {
// 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() );