diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 1ba8799a597..53bb4409aa5 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -114,6 +114,10 @@ Bug Fixes * SOLR-3956: Fixed group.facet=true to work with negative facet.limit (Chris van der Merwe, hossman) + +* 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) Optimizations ---------------------- diff --git a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java index 6a5547f7ba9..cbeea49505e 100644 --- a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java +++ b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java @@ -740,8 +740,21 @@ public final class IndexSchema { boolean sourceIsDynamicFieldReference = false; boolean sourceIsExplicitFieldGlob = false; - - if (null == sourceSchemaField && isValidFieldGlob(source)) { + + + final String invalidGlobMessage = "is an invalid glob: either it contains more than one asterisk," + + " or the asterisk occurs neither at the start nor at the end."; + final boolean sourceIsGlob = isValidFieldGlob(source); + if (source.contains("*") && ! sourceIsGlob) { + String msg = "copyField source :'" + source + "' " + invalidGlobMessage; + throw new SolrException(ErrorCode.SERVER_ERROR, msg); + } + if (dest.contains("*") && ! isValidFieldGlob(dest)) { + String msg = "copyField dest :'" + dest + "' " + invalidGlobMessage; + throw new SolrException(ErrorCode.SERVER_ERROR, msg); + } + + if (null == sourceSchemaField && sourceIsGlob) { Pattern pattern = Pattern.compile(source.replace("*", ".*")); // glob->regex for (String field : fields.keySet()) { if (pattern.matcher(field).matches()) { @@ -778,19 +791,19 @@ public final class IndexSchema { } } } - if (null == sourceSchemaField && ! sourceIsDynamicFieldReference && ! sourceIsExplicitFieldGlob) { - String msg = "copyField source :'" + source + "' doesn't match any explicit field or dynamicField."; + if (null == sourceSchemaField && ! sourceIsGlob && ! sourceIsDynamicFieldReference) { + String msg = "copyField source :'" + source + "' is not a glob and doesn't match any explicit field or dynamicField."; throw new SolrException(ErrorCode.SERVER_ERROR, msg); } if (null == destSchemaField) { String msg = "copyField dest :'" + dest + "' is not an explicit field and doesn't match a dynamicField."; throw new SolrException(ErrorCode.SERVER_ERROR, msg); } - if (sourceIsDynamicFieldReference || sourceIsExplicitFieldGlob) { - if (null != destDynamicField) { // source: dynamic field ref or explicit field glob; dest: dynamic field ref + if (sourceIsDynamicFieldReference || sourceIsGlob) { + if (null != destDynamicField) { // source: glob or no-asterisk dynamic field ref; dest: dynamic field ref registerDynamicCopyField(new DynamicCopy(source, destDynamicField, maxChars, sourceDynamicBase, destDynamicBase)); incrementCopyFieldTargetCount(destSchemaField); - } else { // source: dynamic field reference; dest: explicit field + } else { // source: glob or no-asterisk dynamic field ref; dest: explicit field destDynamicField = new DynamicField(destSchemaField); registerDynamicCopyField(new DynamicCopy(source, destDynamicField, maxChars, sourceDynamicBase, null)); incrementCopyFieldTargetCount(destSchemaField); diff --git a/solr/core/src/test-files/solr/collection1/conf/bad-schema-misplaced-asterisk-copyfield-dest-should-fail-test.xml b/solr/core/src/test-files/solr/collection1/conf/bad-schema-misplaced-asterisk-copyfield-dest-should-fail-test.xml new file mode 100644 index 00000000000..5b32376751c --- /dev/null +++ b/solr/core/src/test-files/solr/collection1/conf/bad-schema-misplaced-asterisk-copyfield-dest-should-fail-test.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + diff --git a/solr/core/src/test-files/solr/collection1/conf/bad-schema-misplaced-asterisk-copyfield-source-should-fail-test.xml b/solr/core/src/test-files/solr/collection1/conf/bad-schema-misplaced-asterisk-copyfield-source-should-fail-test.xml new file mode 100644 index 00000000000..ddc9f4dc685 --- /dev/null +++ b/solr/core/src/test-files/solr/collection1/conf/bad-schema-misplaced-asterisk-copyfield-source-should-fail-test.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + diff --git a/solr/core/src/test-files/solr/collection1/conf/bad-schema-multiple-asterisk-copyfield-dest-should-fail-test.xml b/solr/core/src/test-files/solr/collection1/conf/bad-schema-multiple-asterisk-copyfield-dest-should-fail-test.xml new file mode 100644 index 00000000000..fb3ddbe5c41 --- /dev/null +++ b/solr/core/src/test-files/solr/collection1/conf/bad-schema-multiple-asterisk-copyfield-dest-should-fail-test.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + diff --git a/solr/core/src/test-files/solr/collection1/conf/bad-schema-multiple-asterisk-copyfield-source-should-fail-test.xml b/solr/core/src/test-files/solr/collection1/conf/bad-schema-multiple-asterisk-copyfield-source-should-fail-test.xml new file mode 100644 index 00000000000..b3ca6ae3096 --- /dev/null +++ b/solr/core/src/test-files/solr/collection1/conf/bad-schema-multiple-asterisk-copyfield-source-should-fail-test.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + diff --git a/solr/core/src/test-files/solr/collection1/conf/bad-schema-non-glob-copyfield-source-matching-nothing-should-fail-test.xml b/solr/core/src/test-files/solr/collection1/conf/bad-schema-non-glob-copyfield-source-matching-nothing-should-fail-test.xml new file mode 100644 index 00000000000..86e80a4555e --- /dev/null +++ b/solr/core/src/test-files/solr/collection1/conf/bad-schema-non-glob-copyfield-source-matching-nothing-should-fail-test.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-copyfield-test.xml b/solr/core/src/test-files/solr/collection1/conf/schema-copyfield-test.xml index eff2acb737c..6c45681d215 100644 --- a/solr/core/src/test-files/solr/collection1/conf/schema-copyfield-test.xml +++ b/solr/core/src/test-files/solr/collection1/conf/schema-copyfield-test.xml @@ -466,7 +466,10 @@ - + + + +