From 6fd7b9197271ab8b16cec824796e2c970df6b89e Mon Sep 17 00:00:00 2001 From: "Chris M. Hostetter" Date: Fri, 14 May 2010 20:58:29 +0000 Subject: [PATCH] SOLR-1908: Fixed SignatureUpdateProcessor to fail to initialize on invalid config. Specificly: a signatureField that does not exist, or overwriteDupes=true with a signatureField that is not indexed. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@944463 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 5 ++ .../SignatureUpdateProcessorFactory.java | 28 ++++++++++- .../SignatureUpdateProcessorFactoryTest.java | 47 ++++++++++++++++++- .../test/test-files/solr/conf/bad-schema.xml | 4 ++ .../solr/conf/schema-copyfield-test.xml | 1 + .../solr/conf/schema-luceneMatchVersion.xml | 3 ++ .../conf/schema-not-required-unique-key.xml | 2 + .../solr/conf/schema-required-fields.xml | 1 + .../test-files/solr/conf/schema-reversed.xml | 4 ++ .../test/test-files/solr/conf/schema-trie.xml | 2 + .../test/test-files/solr/conf/schema11.xml | 3 ++ .../test/test-files/solr/conf/solrconfig.xml | 15 +++++- 12 files changed, 111 insertions(+), 4 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 6fa4b1eccf5..c830c9b2010 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -287,6 +287,11 @@ Bug Fixes * SOLR-1902: Exposed SolrResourceLoader's class loader for use by Tika +* SOLR-1908: Fixed SignatureUpdateProcessor to fail to initialize on + invalid config. Specificly: a signatureField that does not exist, + or overwriteDupes=true with a signatureField that is not indexed. + (hossman) + Other Changes ---------------------- diff --git a/solr/src/java/org/apache/solr/update/processor/SignatureUpdateProcessorFactory.java b/solr/src/java/org/apache/solr/update/processor/SignatureUpdateProcessorFactory.java index b32d36fc9b6..486a0bd1b44 100755 --- a/solr/src/java/org/apache/solr/update/processor/SignatureUpdateProcessorFactory.java +++ b/solr/src/java/org/apache/solr/update/processor/SignatureUpdateProcessorFactory.java @@ -23,6 +23,8 @@ import java.util.Collections; import java.util.List; import org.apache.lucene.index.Term; +import org.apache.solr.common.SolrException; +import org.apache.solr.common.SolrException.ErrorCode; import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.SolrInputField; import org.apache.solr.common.params.SolrParams; @@ -34,9 +36,14 @@ import org.apache.solr.update.AddUpdateCommand; import org.apache.solr.update.CommitUpdateCommand; import org.apache.solr.update.DeleteUpdateCommand; import org.apache.solr.core.SolrResourceLoader; +import org.apache.solr.core.SolrCore; +import org.apache.solr.schema.IndexSchema; +import org.apache.solr.schema.SchemaField; +import org.apache.solr.util.plugin.SolrCoreAware; -public class SignatureUpdateProcessorFactory extends - UpdateRequestProcessorFactory { +public class SignatureUpdateProcessorFactory + extends UpdateRequestProcessorFactory + implements SolrCoreAware { private List sigFields; private String signatureField; @@ -72,6 +79,23 @@ public class SignatureUpdateProcessorFactory extends } } + public void inform(SolrCore core) { + final SchemaField field = core.getSchema().getFieldOrNull(getSignatureField()); + if (null == field) { + throw new SolrException + (ErrorCode.SERVER_ERROR, + "Can't use signatureField which does not exist in schema: " + + getSignatureField()); + } + + if (getOverwriteDupes() && ( ! field.indexed() ) ) { + throw new SolrException + (ErrorCode.SERVER_ERROR, + "Can't set overwriteDupes when signatureField is not indexed: " + + getSignatureField()); + } + } + public List getSigFields() { return sigFields; } diff --git a/solr/src/test/org/apache/solr/update/processor/SignatureUpdateProcessorFactoryTest.java b/solr/src/test/org/apache/solr/update/processor/SignatureUpdateProcessorFactoryTest.java index 7a9854ff785..cdbc53de8c7 100755 --- a/solr/src/test/org/apache/solr/update/processor/SignatureUpdateProcessorFactoryTest.java +++ b/solr/src/test/org/apache/solr/update/processor/SignatureUpdateProcessorFactoryTest.java @@ -24,6 +24,7 @@ import java.util.Map; import org.apache.solr.common.params.MultiMapSolrParams; import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.params.UpdateParams; +import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.ContentStream; import org.apache.solr.common.util.ContentStreamBase; import org.apache.solr.core.SolrCore; @@ -37,6 +38,9 @@ import org.apache.solr.util.AbstractSolrTestCase; */ public class SignatureUpdateProcessorFactoryTest extends AbstractSolrTestCase { + /** modified by tests as needed */ + private String processor = "dedupe"; + @Override public String getSchemaFile() { return "schema12.xml"; @@ -47,6 +51,12 @@ public class SignatureUpdateProcessorFactoryTest extends AbstractSolrTestCase { return "solrconfig.xml"; } + @Override + public void setUp() throws Exception { + super.setUp(); + processor = "dedupe"; // set the default that most tests expect + } + public void testDupeDetection() throws Exception { SolrCore core = h.getCore(); UpdateRequestProcessorChain chained = core.getUpdateProcessingChain( @@ -169,10 +179,45 @@ public class SignatureUpdateProcessorFactoryTest extends AbstractSolrTestCase { factory.setEnabled(false); } + /** + * a non-indexed signatureField is fine as long as overwriteDupes==false + */ + public void testNonIndexedSignatureField() throws Exception { + SolrCore core = h.getCore(); + + assertEquals("docs found when none are expected at start", + 0l, core.getSearcher().get().getReader().numDocs()); + + processor = "stored_sig"; + addDoc(adoc("id", "2a", "v_t", "Hello Dude man!", "name", "ali babi'")); + addDoc(adoc("id", "2b", "v_t", "Hello Dude man!", "name", "ali babi'")); + addDoc(commit()); + + assertEquals("did not find exepcted docs", + 2l, core.getSearcher().get().getReader().numDocs()); + } + + public void testFailNonIndexedSigWithOverwriteDupes() throws Exception { + SolrCore core = h.getCore(); + SignatureUpdateProcessorFactory f = new SignatureUpdateProcessorFactory(); + NamedList initArgs = new NamedList(); + initArgs.add("overwriteDupes", "true"); + initArgs.add("signatureField", "signatureField_sS"); + f.init(initArgs); + boolean exception_ok = false; + try { + f.inform(core); + } catch (Exception e) { + exception_ok = true; + } + assertTrue("Should have gotten an exception from inform(SolrCore)", + exception_ok); + } + private void addDoc(String doc) throws Exception { Map params = new HashMap(); MultiMapSolrParams mmparams = new MultiMapSolrParams(params); - params.put(UpdateParams.UPDATE_PROCESSOR, new String[] { "dedupe" }); + params.put(UpdateParams.UPDATE_PROCESSOR, new String[] { processor }); SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(), (SolrParams) mmparams) { }; diff --git a/solr/src/test/test-files/solr/conf/bad-schema.xml b/solr/src/test/test-files/solr/conf/bad-schema.xml index 9567fe3a50a..be3c85b16d4 100644 --- a/solr/src/test/test-files/solr/conf/bad-schema.xml +++ b/solr/src/test/test-files/solr/conf/bad-schema.xml @@ -34,6 +34,8 @@ + + @@ -41,6 +43,8 @@ + + id diff --git a/solr/src/test/test-files/solr/conf/schema-copyfield-test.xml b/solr/src/test/test-files/solr/conf/schema-copyfield-test.xml index 2a6fe0d0938..ce05b3f2c29 100644 --- a/solr/src/test/test-files/solr/conf/schema-copyfield-test.xml +++ b/solr/src/test/test-files/solr/conf/schema-copyfield-test.xml @@ -394,6 +394,7 @@ termVectors="true" termPositions="true" termOffsets="true"/> + diff --git a/solr/src/test/test-files/solr/conf/schema-luceneMatchVersion.xml b/solr/src/test/test-files/solr/conf/schema-luceneMatchVersion.xml index 6f5b7dfc005..d523aa6ae5b 100644 --- a/solr/src/test/test-files/solr/conf/schema-luceneMatchVersion.xml +++ b/solr/src/test/test-files/solr/conf/schema-luceneMatchVersion.xml @@ -17,6 +17,7 @@ --> + @@ -43,9 +44,11 @@ + + diff --git a/solr/src/test/test-files/solr/conf/schema-not-required-unique-key.xml b/solr/src/test/test-files/solr/conf/schema-not-required-unique-key.xml index bb67e7353e5..71145d0b6c3 100644 --- a/solr/src/test/test-files/solr/conf/schema-not-required-unique-key.xml +++ b/solr/src/test/test-files/solr/conf/schema-not-required-unique-key.xml @@ -39,6 +39,8 @@ + + subject diff --git a/solr/src/test/test-files/solr/conf/schema-required-fields.xml b/solr/src/test/test-files/solr/conf/schema-required-fields.xml index 871c99563c1..7fbfda9d871 100644 --- a/solr/src/test/test-files/solr/conf/schema-required-fields.xml +++ b/solr/src/test/test-files/solr/conf/schema-required-fields.xml @@ -376,6 +376,7 @@ + diff --git a/solr/src/test/test-files/solr/conf/schema-reversed.xml b/solr/src/test/test-files/solr/conf/schema-reversed.xml index f4cea9e2d02..d4dec526e7c 100644 --- a/solr/src/test/test-files/solr/conf/schema-reversed.xml +++ b/solr/src/test/test-files/solr/conf/schema-reversed.xml @@ -26,6 +26,7 @@ + @@ -72,6 +73,9 @@ + + + one diff --git a/solr/src/test/test-files/solr/conf/schema-trie.xml b/solr/src/test/test-files/solr/conf/schema-trie.xml index 45440194d54..26515c10810 100644 --- a/solr/src/test/test-files/solr/conf/schema-trie.xml +++ b/solr/src/test/test-files/solr/conf/schema-trie.xml @@ -274,6 +274,7 @@ + @@ -293,6 +294,7 @@ both match, the first appearing in the schema will be used. --> + diff --git a/solr/src/test/test-files/solr/conf/schema11.xml b/solr/src/test/test-files/solr/conf/schema11.xml index 7c481990d83..a5fa1bbb3af 100755 --- a/solr/src/test/test-files/solr/conf/schema11.xml +++ b/solr/src/test/test-files/solr/conf/schema11.xml @@ -292,6 +292,8 @@ + + + diff --git a/solr/src/test/test-files/solr/conf/solrconfig.xml b/solr/src/test/test-files/solr/conf/solrconfig.xml index 2001aa77d8c..cb0a7a7666c 100644 --- a/solr/src/test/test-files/solr/conf/solrconfig.xml +++ b/solr/src/test/test-files/solr/conf/solrconfig.xml @@ -459,5 +459,18 @@ - + + + + true + non_indexed_signature_sS + false + v_t,t_field + org.apache.solr.update.processor.TextProfileSignature + + + +