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/09/12 01:02:26 UTC
svn commit: r1383648 - in /lucene/dev/trunk/solr: ./
core/src/java/org/apache/solr/schema/
core/src/test-files/solr/collection1/conf/
core/src/test/org/apache/solr/schema/
Author: hossman
Date: Tue Sep 11 23:02:25 2012
New Revision: 1383648
URL: http://svn.apache.org/viewvc?rev=1383648&view=rev
Log:
SOLR-3087: CurrencyField now generates an appropriate error on schema init if it is configured as multiValued
Added:
lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/bad-schema-currency-dynamic-multivalued.xml (with props)
lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/bad-schema-currency-ft-multivalued.xml (with props)
lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/bad-schema-currency-multivalued.xml (with props)
Modified:
lucene/dev/trunk/solr/CHANGES.txt
lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/CurrencyField.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/FieldType.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/SchemaField.java
lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/schema.xml
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=1383648&r1=1383647&r2=1383648&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Tue Sep 11 23:02:25 2012
@@ -145,6 +145,11 @@ Bug Fixes
from Collections passed to addValue/addField
(Tom Switzer via hossman)
+* SOLR-3087: CurrencyField now generates an appropriate error on schema init
+ if it is configured as multiValued - this has never been properly supported,
+ but previously failed silently in odd ways. (hossman)
+
+
Other Changes
----------------------
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/CurrencyField.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/CurrencyField.java?rev=1383648&r1=1383647&r2=1383648&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/CurrencyField.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/CurrencyField.java Tue Sep 11 23:02:25 2012
@@ -81,6 +81,11 @@ public class CurrencyField extends Field
@Override
protected void init(IndexSchema schema, Map<String, String> args) {
super.init(schema, args);
+ if (this.isMultiValued()) {
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+ "CurrencyField types can not be multiValued: " +
+ this.typeName);
+ }
this.schema = schema;
this.exchangeRateProviderClass = args.get(PARAM_RATE_PROVIDER_CLASS);
this.defaultCurrency = args.get(PARAM_DEFAULT_CURRENCY);
@@ -133,6 +138,16 @@ public class CurrencyField extends Field
}
@Override
+ public void checkSchemaField(final SchemaField field) throws SolrException {
+ super.checkSchemaField(field);
+ if (field.multiValued()) {
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+ "CurrencyFields can not be multiValued: " +
+ field.getName());
+ }
+ }
+
+ @Override
public StorableField[] createFields(SchemaField field, Object externalVal, float boost) {
CurrencyValue value = CurrencyValue.parse(externalVal.toString(), defaultCurrency);
@@ -763,4 +778,4 @@ class CurrencyValue {
public String toString() {
return String.valueOf(amount) + "," + currencyCode;
}
-}
\ No newline at end of file
+}
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/FieldType.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/FieldType.java?rev=1383648&r1=1383647&r2=1383648&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/FieldType.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/FieldType.java Tue Sep 11 23:02:25 2012
@@ -599,4 +599,20 @@ public abstract class FieldType extends
readableToIndexed(externalVal, br);
return new TermQuery(new Term(field.getName(), br));
}
+
+ /**
+ * Check's {@link org.apache.solr.schema.SchemaField} instances constructed
+ * using this field type to ensure that they are valid.
+ *
+ * <p>
+ * This method is called by the <code>SchemaField</code> constructor to
+ * check that it's initialization does not violate any fundemental
+ * requirements of the <code>FieldType</code>. The default implementation
+ * does nothing, but subclasses may chose to throw a {@link SolrException}
+ * if invariants are violated by the <code>SchemaField.
+ * </p>
+ */
+ public void checkSchemaField(final SchemaField field) throws SolrException {
+ // :NOOP:
+ }
}
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/SchemaField.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/SchemaField.java?rev=1383648&r1=1383647&r2=1383648&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/SchemaField.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/SchemaField.java Tue Sep 11 23:02:25 2012
@@ -69,6 +69,8 @@ public final class SchemaField extends F
// initalize with the required property flag
required = (properties & REQUIRED) !=0;
+
+ type.checkSchemaField(this);
}
public String getName() { return name; }
Added: lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/bad-schema-currency-dynamic-multivalued.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/bad-schema-currency-dynamic-multivalued.xml?rev=1383648&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/bad-schema-currency-dynamic-multivalued.xml (added)
+++ lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/bad-schema-currency-dynamic-multivalued.xml Tue Sep 11 23:02:25 2012
@@ -0,0 +1,36 @@
+<?xml version="1.0" ?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<schema name="bad-schema-currency-ft-multivalued" version="1.4">
+ <types>
+ <fieldType name="string" class="solr.StrField" multiValued="true"/>
+ <fieldType name="currency" class="solr.CurrencyField" currencyConfig="currency.xml" multiValued="false" />
+
+ </types>
+
+ <fields>
+ <field name="id" type="string" indexed="true" stored="true" multiValued="false"/>
+ <!-- BEGIN BAD STUFF: multiValued -->
+ <dynamicField name="*_c" type="currency" indexed="true" stored="true" multiValued="true" />
+ <!-- END BAD STUFF -->
+ </fields>
+
+ <defaultSearchField>id</defaultSearchField>
+ <uniqueKey>id</uniqueKey>
+
+</schema>
Added: lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/bad-schema-currency-ft-multivalued.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/bad-schema-currency-ft-multivalued.xml?rev=1383648&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/bad-schema-currency-ft-multivalued.xml (added)
+++ lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/bad-schema-currency-ft-multivalued.xml Tue Sep 11 23:02:25 2012
@@ -0,0 +1,34 @@
+<?xml version="1.0" ?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<schema name="bad-schema-currency-ft-multivalued" version="1.4">
+ <types>
+ <fieldType name="string" class="solr.StrField" multiValued="true"/>
+ <!-- BEGIN BAD STUFF: multiValued -->
+ <fieldType name="currency" class="solr.CurrencyField" currencyConfig="currency.xml" multiValued="true" />
+ </types>
+
+ <fields>
+ <field name="id" type="string" indexed="true" stored="true" multiValued="false"/>
+ <field name="money" type="currency" indexed="true" stored="true" />
+ </fields>
+
+ <defaultSearchField>id</defaultSearchField>
+ <uniqueKey>id</uniqueKey>
+
+</schema>
Added: lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/bad-schema-currency-multivalued.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/bad-schema-currency-multivalued.xml?rev=1383648&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/bad-schema-currency-multivalued.xml (added)
+++ lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/bad-schema-currency-multivalued.xml Tue Sep 11 23:02:25 2012
@@ -0,0 +1,35 @@
+<?xml version="1.0" ?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<schema name="bad-schema-currency-multivalued" version="1.4">
+ <types>
+ <fieldType name="string" class="solr.StrField" multiValued="true"/>
+ <fieldType name="currency" class="solr.CurrencyField" currencyConfig="currency.xml"/>
+ </types>
+
+ <fields>
+ <field name="id" type="string" indexed="true" stored="true" multiValued="false"/>
+ <!-- BEGIN BAD STUFF: multiValued -->
+ <field name="money" type="currency" indexed="true" stored="true" multiValued="true" />
+ <!-- END BAD STUFF -->
+ </fields>
+
+ <defaultSearchField>id</defaultSearchField>
+ <uniqueKey>id</uniqueKey>
+
+</schema>
Modified: lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/schema.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/schema.xml?rev=1383648&r1=1383647&r2=1383648&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/schema.xml (original)
+++ lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/schema.xml Tue Sep 11 23:02:25 2012
@@ -399,9 +399,11 @@
<fieldType name="latLon" class="solr.LatLonType" subFieldType="double"/>
<!-- Currency type -->
- <fieldType name="currency" class="solr.CurrencyField" currencyConfig="currency.xml"/>
- <fieldType name="mock_currency" class="solr.CurrencyField" providerClass="solr.MockExchangeRateProvider" foo="bar" />
- <fieldType name="openexchangeratesorg_currency" class="solr.CurrencyField"
+ <fieldType name="currency" class="solr.CurrencyField" currencyConfig="currency.xml" multiValued="false" />
+ <fieldType name="mock_currency" class="solr.CurrencyField" providerClass="solr.MockExchangeRateProvider" foo="bar" multiValued="false" />
+ <fieldType name="openexchangeratesorg_currency"
+ class="solr.CurrencyField"
+ multiValued="false"
providerClass="solr.OpenExchangeRatesOrgProvider"
ratesFileLocation="open-exchange-rates.json" />
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=1383648&r1=1383647&r2=1383648&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 Tue Sep 11 23:02:25 2012
@@ -66,6 +66,15 @@ public class BadIndexSchemaTest extends
"can not be configured to be multivalued");
}
+ public void testMultivaluedCurrency() throws Exception {
+ doTest("bad-schema-currency-ft-multivalued.xml",
+ "types can not be multiValued: currency");
+ doTest("bad-schema-currency-multivalued.xml",
+ "Fields can not be multiValued: money");
+ doTest("bad-schema-currency-dynamic-multivalued.xml",
+ "Fields can not be multiValued: *_c");
+ }
+
public void testPerFieldtypeSimButNoSchemaSimFactory() throws Exception {
doTest("bad-schema-sim-global-vs-ft-mismatch.xml", "global similarity does not support it");
}