You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2012/07/30 19:58:21 UTC
svn commit: r1367192 - in /lucene/dev/trunk/solr: CHANGES.txt
core/src/java/org/apache/solr/schema/FieldTypePluginLoader.java
core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java
Author: hossman
Date: Mon Jul 30 17:58:21 2012
New Revision: 1367192
URL: http://svn.apache.org/viewvc?rev=1367192&view=rev
Log:
SOLR-3683: Improved error handling if an <analyzer> contains both an explicit class attribute, as well as nested factories. (hossman)
Modified:
lucene/dev/trunk/solr/CHANGES.txt
lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/FieldTypePluginLoader.java
lucene/dev/trunk/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java
Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1367192&r1=1367191&r2=1367192&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Mon Jul 30 17:58:21 2012
@@ -185,6 +185,8 @@ Other Changes
* SOLR-3215: Clone SolrInputDocument when distrib indexing so that update processors after
the distrib update process do not process the document twice. (Mark Miller)
+* SOLR-3683: Improved error handling if an <analyzer> contains both an
+ explicit class attribute, as well as nested factories. (hossman)
================== 4.0.0-ALPHA ==================
More information about this release, including any errata related to the
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/FieldTypePluginLoader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/FieldTypePluginLoader.java?rev=1367192&r1=1367191&r2=1367192&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/FieldTypePluginLoader.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/FieldTypePluginLoader.java Mon Jul 30 17:58:21 2012
@@ -225,7 +225,30 @@ public final class FieldTypePluginLoader
if (node == null) return null;
NamedNodeMap attrs = node.getAttributes();
String analyzerName = DOMUtil.getAttr(attrs,"class");
+
+ // check for all of these up front, so we can error if used in
+ // conjunction with an explicit analyzer class.
+ NodeList charFilterNodes = (NodeList)xpath.evaluate
+ ("./charFilter", node, XPathConstants.NODESET);
+ NodeList tokenizerNodes = (NodeList)xpath.evaluate
+ ("./tokenizer", node, XPathConstants.NODESET);
+ NodeList tokenFilterNodes = (NodeList)xpath.evaluate
+ ("./filter", node, XPathConstants.NODESET);
+
if (analyzerName != null) {
+
+ // explicitly check for child analysis factories instead of
+ // just any child nodes, because the user might have their
+ // own custom nodes (ie: <description> or something like that)
+ if (0 != charFilterNodes.getLength() ||
+ 0 != tokenizerNodes.getLength() ||
+ 0 != tokenFilterNodes.getLength()) {
+ throw new SolrException
+ ( SolrException.ErrorCode.SERVER_ERROR,
+ "Configuration Error: Analyzer class='" + analyzerName +
+ "' can not be combined with nested analysis factories");
+ }
+
try {
// No need to be core-aware as Analyzers are not in the core-aware list
final Class<? extends Analyzer> clazz = loader.findClass(analyzerName, Analyzer.class);
@@ -286,8 +309,7 @@ public final class FieldTypePluginLoader
}
};
- charFilterLoader.load( loader, (NodeList)xpath.evaluate("./charFilter", node, XPathConstants.NODESET) );
-
+ charFilterLoader.load( loader, charFilterNodes );
// Load the Tokenizer
// Although an analyzer only allows a single Tokenizer, we load a list to make sure
@@ -319,13 +341,12 @@ public final class FieldTypePluginLoader
}
};
- tokenizerLoader.load( loader, (NodeList)xpath.evaluate("./tokenizer", node, XPathConstants.NODESET) );
+ tokenizerLoader.load( loader, tokenizerNodes );
// Make sure something was loaded
if( tokenizers.isEmpty() ) {
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,"analyzer without class or tokenizer & filter list");
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,"analyzer without class or tokenizer");
}
-
// Load the Filters
@@ -353,7 +374,7 @@ public final class FieldTypePluginLoader
return null; // used for map registration
}
};
- filterLoader.load( loader, (NodeList)xpath.evaluate("./filter", node, XPathConstants.NODESET) );
+ filterLoader.load( loader, tokenFilterNodes );
return new TokenizerChain(charFilters.toArray(new CharFilterFactory[charFilters.size()]),
tokenizers.get(0), filters.toArray(new TokenFilterFactory[filters.size()]));
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java?rev=1367192&r1=1367191&r2=1367192&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java Mon Jul 30 17:58:21 2012
@@ -49,6 +49,7 @@ public class BadIndexSchemaTest extends
public void testSevereErrorsForUnexpectedAnalyzer() throws Exception {
doTest("bad-schema-nontext-analyzer.xml", "StrField (bad_type)");
+ doTest("bad-schema-analyzer-class-and-nested.xml", "bad_type");
}
public void testBadExternalFileField() throws Exception {