Skip to content

Apache Lucene open-source search software

SOLR-530: Better error messages/warnings when parsing schema.xml: field using bogus fieldtype and multiple copyFields to a non-multiValue field

Chris M. Hostetterfd4981f4448b
diff --git a/CHANGES.txt b/CHANGES.txt
index 71c3fae773e..10d09c55834 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -327,6 +327,10 @@ Bug Fixes
specified and there is no defaultSearchField in schema.xml
(Lars Kotthoff via hossman)
+22. SOLR-530: Better error messages/warnings when parsing schema.xml:
+ field using bogus fieldtype and multiple copyFields to a non-multiValue
+ field. (Shalin Shekhar Mangar via hossman)
+
Other Changes
1. SOLR-135: Moved common classes to org.apache.solr.common and altered the
build scripts to make two jars: apache-solr-1.3.jar and
diff --git a/src/java/org/apache/solr/schema/IndexSchema.java b/src/java/org/apache/solr/schema/IndexSchema.java
index 6c4ae25499d..7236bc315e3 100644
--- a/src/java/org/apache/solr/schema/IndexSchema.java
+++ b/src/java/org/apache/solr/schema/IndexSchema.java
@@ -425,7 +425,7 @@ public final class IndexSchema {
FieldType ft = fieldTypes.get(type);
if (ft==null) {
- throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Unknown fieldtype '" + type + "'",false);
+ throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Unknown fieldtype '" + type + "' specified on field " + name,false);
}
Map<String,String> args = DOMUtil.toMapExcept(attrs, "name", "type");
@@ -594,9 +594,18 @@ public final class IndexSchema {
destArr = (SchemaField[])append(destArr,d);
}
copyFields.put(source,destArr);
- copyFieldTarget.add( d );
+
+ copyFieldTargetCounts.put(d, (copyFieldTargetCounts.containsKey(d) ? copyFieldTargetCounts.get(d) + 1 : 1));
}
}
+
+ for (Map.Entry<SchemaField, Integer> entry : copyFieldTargetCounts.entrySet()) {
+ if (entry.getValue() > 1 && !entry.getKey().multiValued()) {
+ log.warning("Field " + entry.getKey().name + " is not multivalued "+
+ "and destination for multiple copyFields ("+
+ entry.getValue()+")");
+ }
+ }
log.finest("Dynamic Copied Fields:" + dCopies);
@@ -976,8 +985,12 @@ public final class IndexSchema {
private final Map<String, SchemaField[]> copyFields = new HashMap<String,SchemaField[]>();
private DynamicCopy[] dynamicCopyFields;
- private final Set<SchemaField> copyFieldTarget = new HashSet<SchemaField>();
-
+ /**
+ * keys are all fields copied to, count is num of copyField
+ * directives that target them.
+ */
+ private Map<SchemaField, Integer> copyFieldTargetCounts
+ = new HashMap<SchemaField, Integer>();
/**
* Get all copy fields, both the static and the dynamic ones.
@@ -1040,7 +1053,7 @@ public final class IndexSchema {
*/
public boolean isCopyFieldTarget( SchemaField f )
{
- return copyFieldTarget.contains( f );
+ return copyFieldTargetCounts.containsKey( f );
}
/**