mirror of https://github.com/apache/lucene.git
SOLR-4641: Schema should throw exceptoin on illegal field parameters
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1462502 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a6e3ba52c0
commit
abea806409
|
@ -118,6 +118,8 @@ Bug Fixes
|
|||
* SOLR-4650: copyField doesn't work with source globs that don't match any
|
||||
explicit or dynamic fields. This regression was introduced in Solr 4.2.
|
||||
(Daniel Collins, Steve Rowe)
|
||||
|
||||
* SOLR-4641: Schema now throws exception on illegal field parameters. (Robert Muir)
|
||||
|
||||
Optimizations
|
||||
----------------------
|
||||
|
|
|
@ -265,9 +265,6 @@
|
|||
type: mandatory - the name of a previously defined type from the <types> section
|
||||
indexed: true if this field should be indexed (searchable or sortable)
|
||||
stored: true if this field should be retrievable
|
||||
compressed: [false] if this field should be stored using gzip compression
|
||||
(this will only apply if the field type is compressable; among
|
||||
the standard field types, only TextField and StrField are)
|
||||
multiValued: true if this field may contain multiple values per document
|
||||
omitNorms: (expert) set to true to omit the norms associated with
|
||||
this field (this disables length normalization and index-time
|
||||
|
|
|
@ -246,9 +246,6 @@
|
|||
type: mandatory - the name of a previously defined type from the <types> section
|
||||
indexed: true if this field should be indexed (searchable or sortable)
|
||||
stored: true if this field should be retrievable
|
||||
compressed: [false] if this field should be stored using gzip compression
|
||||
(this will only apply if the field type is compressable; among
|
||||
the standard field types, only TextField and StrField are)
|
||||
multiValued: true if this field may contain multiple values per document
|
||||
omitNorms: (expert) set to true to omit the norms associated with
|
||||
this field (this disables length normalization and index-time
|
||||
|
|
|
@ -354,8 +354,8 @@
|
|||
termPositions="true" termOffsets="true"/>
|
||||
|
||||
<!-- test highlit field settings -->
|
||||
<field name="test_hlt" type="highlittext" indexed="true" compressed="true"/>
|
||||
<field name="test_hlt_off" type="highlittext" indexed="true" compressed="false"/>
|
||||
<field name="test_hlt" type="highlittext" indexed="true"/>
|
||||
<field name="test_hlt_off" type="highlittext" indexed="true"/>
|
||||
|
||||
<!-- fields to test individual tokenizers and tokenfilters -->
|
||||
<field name="teststop" type="teststop" indexed="true" stored="true"/>
|
||||
|
|
|
@ -470,10 +470,7 @@
|
|||
field type: mandatory - the name of a previously defined type from
|
||||
the <types> section indexed: true if this field should be indexed
|
||||
(searchable or sortable) stored: true if this field should be
|
||||
retrievable compressed: [false] if this field should be stored
|
||||
using gzip compression (this will only apply if the field type is
|
||||
compressable; among the standard field types, only TextField and
|
||||
StrField are) multiValued: true if this field may contain multiple
|
||||
retrievable multiValued: true if this field may contain multiple
|
||||
values per document omitNorms: (expert) set to true to omit the
|
||||
norms associated with this field (this disables length
|
||||
normalization and index-time boosting for the field, and saves
|
||||
|
|
|
@ -466,10 +466,7 @@
|
|||
field type: mandatory - the name of a previously defined type from
|
||||
the <types> section indexed: true if this field should be indexed
|
||||
(searchable or sortable) stored: true if this field should be
|
||||
retrievable compressed: [false] if this field should be stored
|
||||
using gzip compression (this will only apply if the field type is
|
||||
compressable; among the standard field types, only TextField and
|
||||
StrField are) multiValued: true if this field may contain multiple
|
||||
retrievable multiValued: true if this field may contain multiple
|
||||
values per document omitNorms: (expert) set to true to omit the
|
||||
norms associated with this field (this disables length
|
||||
normalization and index-time boosting for the field, and saves
|
||||
|
|
|
@ -64,7 +64,7 @@ public abstract class FieldProperties {
|
|||
static final Map<String,Integer> propertyMap = new HashMap<String,Integer>();
|
||||
static {
|
||||
for (String prop : propertyNames) {
|
||||
propertyMap.put(prop, propertyNameToInt(prop));
|
||||
propertyMap.put(prop, propertyNameToInt(prop, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,13 +74,17 @@ public abstract class FieldProperties {
|
|||
return propertyNames[ Integer.numberOfTrailingZeros(property) ];
|
||||
}
|
||||
|
||||
static int propertyNameToInt(String name) {
|
||||
static int propertyNameToInt(String name, boolean failOnError) {
|
||||
for (int i=0; i<propertyNames.length; i++) {
|
||||
if (propertyNames[i].equals(name)) {
|
||||
return 1 << i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
if (failOnError && !"default".equals(name)) {
|
||||
throw new IllegalArgumentException("Invalid field property: " + name);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -105,13 +109,13 @@ public abstract class FieldProperties {
|
|||
return (bitfield & props) == 0;
|
||||
}
|
||||
|
||||
static int parseProperties(Map<String,String> properties, boolean which) {
|
||||
static int parseProperties(Map<String,String> properties, boolean which, boolean failOnError) {
|
||||
int props = 0;
|
||||
for (Map.Entry<String, String> entry : properties.entrySet()) {
|
||||
String val = entry.getValue();
|
||||
if(val == null) continue;
|
||||
if (Boolean.parseBoolean(val) == which) {
|
||||
props |= propertyNameToInt(entry.getKey());
|
||||
props |= propertyNameToInt(entry.getKey(), failOnError);
|
||||
}
|
||||
}
|
||||
return props;
|
||||
|
|
|
@ -153,8 +153,8 @@ public abstract class FieldType extends FieldProperties {
|
|||
this.args = Collections.unmodifiableMap(args);
|
||||
Map<String,String> initArgs = new HashMap<String,String>(args);
|
||||
|
||||
trueProperties = FieldProperties.parseProperties(initArgs,true);
|
||||
falseProperties = FieldProperties.parseProperties(initArgs,false);
|
||||
trueProperties = FieldProperties.parseProperties(initArgs,true,false);
|
||||
falseProperties = FieldProperties.parseProperties(initArgs,false,false);
|
||||
|
||||
properties &= ~falseProperties;
|
||||
properties |= trueProperties;
|
||||
|
|
|
@ -221,8 +221,8 @@ public final class SchemaField extends FieldProperties {
|
|||
}
|
||||
|
||||
static int calcProps(String name, FieldType ft, Map<String, String> props) {
|
||||
int trueProps = parseProperties(props,true);
|
||||
int falseProps = parseProperties(props,false);
|
||||
int trueProps = parseProperties(props,true,true);
|
||||
int falseProps = parseProperties(props,false,true);
|
||||
|
||||
int p = ft.properties;
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
<?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-bogus-field-parameters" version="1.5">
|
||||
<types>
|
||||
<fieldType name="binary" class="solr.BinaryField" />
|
||||
</types>
|
||||
|
||||
|
||||
<fields>
|
||||
<field name="id" type="binary" someBogusParam="true"/>
|
||||
</fields>
|
||||
|
||||
</schema>
|
|
@ -346,8 +346,8 @@
|
|||
termPositions="true" termOffsets="true"/>
|
||||
|
||||
<!-- test highlit field settings -->
|
||||
<field name="test_hlt" type="highlittext" indexed="true" compressed="true"/>
|
||||
<field name="test_hlt_off" type="highlittext" indexed="true" compressed="false"/>
|
||||
<field name="test_hlt" type="highlittext" indexed="true"/>
|
||||
<field name="test_hlt_off" type="highlittext" indexed="true"/>
|
||||
|
||||
<!-- fields to test individual tokenizers and tokenfilters -->
|
||||
<field name="teststop" type="teststop" indexed="true" stored="true"/>
|
||||
|
|
|
@ -337,8 +337,8 @@
|
|||
termPositions="true" termOffsets="true"/>
|
||||
|
||||
<!-- test highlit field settings -->
|
||||
<field name="test_hlt" type="highlittext" indexed="true" compressed="true"/>
|
||||
<field name="test_hlt_off" type="highlittext" indexed="true" compressed="false"/>
|
||||
<field name="test_hlt" type="highlittext" indexed="true"/>
|
||||
<field name="test_hlt_off" type="highlittext" indexed="true"/>
|
||||
|
||||
<!-- fields to test individual tokenizers and tokenfilters -->
|
||||
<field name="teststop" type="teststop" indexed="true" stored="true"/>
|
||||
|
|
|
@ -469,8 +469,8 @@
|
|||
termPositions="true" termOffsets="true"/>
|
||||
|
||||
<!-- test highlit field settings -->
|
||||
<field name="test_hlt" type="highlittext" indexed="true" compressed="true"/>
|
||||
<field name="test_hlt_off" type="highlittext" indexed="true" compressed="false"/>
|
||||
<field name="test_hlt" type="highlittext" indexed="true"/>
|
||||
<field name="test_hlt_off" type="highlittext" indexed="true"/>
|
||||
|
||||
<!-- fields to test individual tokenizers and tokenfilters -->
|
||||
<field name="teststop" type="teststop" indexed="true" stored="true"/>
|
||||
|
|
|
@ -258,9 +258,6 @@
|
|||
type: mandatory - the name of a previously defined type from the <types> section
|
||||
indexed: true if this field should be indexed (searchable or sortable)
|
||||
stored: true if this field should be retrievable
|
||||
compressed: [false] if this field should be stored using gzip compression
|
||||
(this will only apply if the field type is compressable; among
|
||||
the standard field types, only TextField and StrField are)
|
||||
multiValued: true if this field may contain multiple values per document
|
||||
omitNorms: (expert) set to true to omit the norms associated with
|
||||
this field (this disables length normalization and index-time
|
||||
|
|
|
@ -506,22 +506,22 @@
|
|||
<!-- indexed=false should not prevent omit___=true -->
|
||||
<field name="pint_i_norm" type="pint" omitNorms="true"
|
||||
indexed="false" />
|
||||
<field name="pint_i_tf" type="pint" omitOmitTermFreqAndPositions="true"
|
||||
<field name="pint_i_tf" type="pint" omitTermFreqAndPositions="true"
|
||||
indexed="false" />
|
||||
<field name="pint_i_pos" type="pint" omitPositions="true"
|
||||
indexed="false" />
|
||||
<field name="pint_i_all" type="pint"
|
||||
indexed="false"
|
||||
omitNorms="true"
|
||||
omitOmitTermFreqAndPositions="true"
|
||||
omitTermFreqAndPositions="true"
|
||||
omitPositions="true" />
|
||||
<!-- omitOmitTermFreqAndPositions=false and omitPositions=true are ok -->
|
||||
<!-- omitTermFreqAndPositions=false and omitPositions=true are ok -->
|
||||
<field name="pint_tf_pos" type="pint" indexed="true"
|
||||
omitOmitTermFreqAndPositions="false" omitPositions="true" />
|
||||
omitTermFreqAndPositions="false" omitPositions="true" />
|
||||
|
||||
<!-- test highlit field settings -->
|
||||
<field name="test_hlt" type="highlittext" indexed="true" compressed="true"/>
|
||||
<field name="test_hlt_off" type="highlittext" indexed="true" compressed="false"/>
|
||||
<field name="test_hlt" type="highlittext" indexed="true"/>
|
||||
<field name="test_hlt_off" type="highlittext" indexed="true"/>
|
||||
|
||||
<!-- fields to test individual tokenizers and tokenfilters -->
|
||||
<field name="teststop" type="teststop" indexed="true" stored="true"/>
|
||||
|
|
|
@ -296,9 +296,6 @@ valued. -->
|
|||
type: mandatory - the name of a previously defined type from the <types> section
|
||||
indexed: true if this field should be indexed (searchable or sortable)
|
||||
stored: true if this field should be retrievable
|
||||
compressed: [false] if this field should be stored using gzip compression
|
||||
(this will only apply if the field type is compressable; among
|
||||
the standard field types, only TextField and StrField are)
|
||||
multiValued: true if this field may contain multiple values per document
|
||||
omitNorms: (expert) set to true to omit the norms associated with
|
||||
this field (this disables length normalization and index-time
|
||||
|
|
|
@ -472,8 +472,8 @@
|
|||
termPositions="true" termOffsets="true"/>
|
||||
|
||||
<!-- test highlit field settings -->
|
||||
<field name="test_hlt" type="highlittext" indexed="true" compressed="true"/>
|
||||
<field name="test_hlt_off" type="highlittext" indexed="true" compressed="false"/>
|
||||
<field name="test_hlt" type="highlittext" indexed="true"/>
|
||||
<field name="test_hlt_off" type="highlittext" indexed="true"/>
|
||||
|
||||
<!-- fields to test individual tokenizers and tokenfilters -->
|
||||
<field name="teststop" type="teststop" indexed="true" stored="true"/>
|
||||
|
|
|
@ -470,8 +470,8 @@
|
|||
termPositions="true" termOffsets="true"/>
|
||||
|
||||
<!-- test highlit field settings -->
|
||||
<field name="test_hlt" type="highlittext" indexed="true" compressed="true"/>
|
||||
<field name="test_hlt_off" type="highlittext" indexed="true" compressed="false"/>
|
||||
<field name="test_hlt" type="highlittext" indexed="true"/>
|
||||
<field name="test_hlt_off" type="highlittext" indexed="true"/>
|
||||
|
||||
<!-- fields to test individual tokenizers and tokenfilters -->
|
||||
<field name="teststop" type="teststop" indexed="true" stored="true"/>
|
||||
|
|
|
@ -487,8 +487,8 @@
|
|||
termPositions="true" termOffsets="true"/>
|
||||
|
||||
<!-- test highlit field settings -->
|
||||
<field name="test_hlt" type="highlittext" indexed="true" compressed="true"/>
|
||||
<field name="test_hlt_off" type="highlittext" indexed="true" compressed="false"/>
|
||||
<field name="test_hlt" type="highlittext" indexed="true"/>
|
||||
<field name="test_hlt_off" type="highlittext" indexed="true"/>
|
||||
|
||||
<!-- fields to test individual tokenizers and tokenfilters -->
|
||||
<field name="teststop" type="teststop" indexed="true" stored="true"/>
|
||||
|
|
|
@ -23,7 +23,7 @@ public class BadIndexSchemaTest extends AbstractBadConfigTestBase {
|
|||
|
||||
private void doTest(final String schema, final String errString)
|
||||
throws Exception {
|
||||
assertConfigs("solrconfig.xml", schema, errString);
|
||||
assertConfigs("solrconfig-basic.xml", schema, errString);
|
||||
}
|
||||
|
||||
public void testSevereErrorsForInvalidFieldOptions() throws Exception {
|
||||
|
@ -110,5 +110,9 @@ public class BadIndexSchemaTest extends AbstractBadConfigTestBase {
|
|||
doTest("bad-schema-sweetspot-partial-norms.xml",
|
||||
"Overriding default lengthNorm");
|
||||
}
|
||||
|
||||
public void testBogusParameters() throws Exception {
|
||||
doTest("bad-schema-bogus-field-parameters.xml", "Invalid field property");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -246,9 +246,6 @@
|
|||
type: mandatory - the name of a previously defined type from the <types> section
|
||||
indexed: true if this field should be indexed (searchable or sortable)
|
||||
stored: true if this field should be retrievable
|
||||
compressed: [false] if this field should be stored using gzip compression
|
||||
(this will only apply if the field type is compressable; among
|
||||
the standard field types, only TextField and StrField are)
|
||||
multiValued: true if this field may contain multiple values per document
|
||||
omitNorms: (expert) set to true to omit the norms associated with
|
||||
this field (this disables length normalization and index-time
|
||||
|
|
|
@ -324,9 +324,6 @@
|
|||
type: mandatory - the name of a previously defined type from the <types> section
|
||||
indexed: true if this field should be indexed (searchable or sortable)
|
||||
stored: true if this field should be retrievable
|
||||
compressed: [false] if this field should be stored using gzip compression
|
||||
(this will only apply if the field type is compressable; among
|
||||
the standard field types, only TextField and StrField are)
|
||||
multiValued: true if this field may contain multiple values per document
|
||||
omitNorms: (expert) set to true to omit the norms associated with
|
||||
this field (this disables length normalization and index-time
|
||||
|
|
|
@ -273,9 +273,6 @@
|
|||
type: mandatory - the name of a previously defined type from the <types> section
|
||||
indexed: true if this field should be indexed (searchable or sortable)
|
||||
stored: true if this field should be retrievable
|
||||
compressed: [false] if this field should be stored using gzip compression
|
||||
(this will only apply if the field type is compressable; among
|
||||
the standard field types, only TextField and StrField are)
|
||||
multiValued: true if this field may contain multiple values per document
|
||||
omitNorms: (expert) set to true to omit the norms associated with
|
||||
this field (this disables length normalization and index-time
|
||||
|
|
|
@ -246,9 +246,6 @@
|
|||
type: mandatory - the name of a previously defined type from the <types> section
|
||||
indexed: true if this field should be indexed (searchable or sortable)
|
||||
stored: true if this field should be retrievable
|
||||
compressed: [false] if this field should be stored using gzip compression
|
||||
(this will only apply if the field type is compressable; among
|
||||
the standard field types, only TextField and StrField are)
|
||||
multiValued: true if this field may contain multiple values per document
|
||||
omitNorms: (expert) set to true to omit the norms associated with
|
||||
this field (this disables length normalization and index-time
|
||||
|
|
Loading…
Reference in New Issue