I just ran across a situation where, in building my schema.xml file, I forgot to specify the <field /> for the field that I was using as my <uniqueKey />. It was totally my error, but having no idea what the error was, I had to spend some time debugging. Once I realized what was going on, I made a little change to IndexSchema.java to ensure that something appears in the log in this situation. The previous behavior was to simply throw a RuntimeException, which, in Tomcat at least, did not result in anything easy to spot in any of the logs I checked. The patch for this is below if you want to apply it. I know it would have saved me some time today.
Note also that the code that looks for a <defaultSearchField /> already assumed that getIndexedField(String) could return a null, although that code path was unreachable given the throw that this patch removed. It makes me think that having an XML Schema for schema.xml (there's a palindrome for you) would be a nice idea to. Thanks, -D Index: C:/Documents and Settings/Darren Vengroff/workspace/Solr/src/java/org/apache/solr/schema/IndexSchema.java =================================================================== --- C:/Documents and Settings/Darren Vengroff/workspace/Solr/src/java/org/apache/solr/schema/IndexSchema.java (revision 412846) +++ C:/Documents and Settings/Darren Vengroff/workspace/Solr/src/java/org/apache/solr/schema/IndexSchema.java (working copy) @@ -178,14 +178,7 @@ } private SchemaField getIndexedField(String fname) { - SchemaField f = getFields().get(fname); - if (f==null) { - throw new RuntimeException("unknown field '" + fname + "'"); - } - if (!f.indexed()) { - throw new RuntimeException("'"+fname+"' is not an indexed field:" + f); - } - return f; + return getFields().get(fname); } @@ -369,10 +362,15 @@ if (node==null) { log.warning("no uniqueKey specified in schema."); } else { - uniqueKeyField=getIndexedField(node.getNodeValue().trim()); - uniqueKeyFieldName=uniqueKeyField.getName(); - uniqueKeyFieldType=uniqueKeyField.getType(); - log.info("unique key field: "+uniqueKeyFieldName); + String fieldName = node.getNodeValue().trim(); + uniqueKeyField = getIndexedField(fieldName); + if(uniqueKeyField == null) { + log.warning("Unique key field '" + fieldName + "' undefined."); + } else { + uniqueKeyFieldName=uniqueKeyField.getName(); + uniqueKeyFieldType=uniqueKeyField.getType(); + log.info("unique key field: "+uniqueKeyFieldName); + } } /////////////// parse out copyField commands ///////////////