From fd4981f4448b9aee3cf4331acf4c82cc1963128b Mon Sep 17 00:00:00 2001 From: "Chris M. Hostetter" Date: Tue, 8 Apr 2008 22:30:21 +0000 Subject: [PATCH] SOLR-530: Better error messages/warnings when parsing schema.xml: field using bogus fieldtype and multiple copyFields to a non-multiValue field git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@646107 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 4 ++++ .../org/apache/solr/schema/IndexSchema.java | 23 +++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) 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 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 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 copyFields = new HashMap(); private DynamicCopy[] dynamicCopyFields; - private final Set copyFieldTarget = new HashSet(); - + /** + * keys are all fields copied to, count is num of copyField + * directives that target them. + */ + private Map copyFieldTargetCounts + = new HashMap(); /** * 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 ); } /**