mirror of https://github.com/apache/lucene.git
SOLR-5010: single field handling
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1502247 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
417f1ba3b4
commit
aade0000a6
|
@ -33,6 +33,7 @@ import org.slf4j.LoggerFactory;
|
|||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -136,7 +137,19 @@ public class CopyFieldCollectionResource extends BaseFieldResource implements GE
|
|||
log.error(message);
|
||||
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, message);
|
||||
}
|
||||
List<String> destinations = (List<String>)map.get(IndexSchema.DESTINATION);
|
||||
Object dest = map.get(IndexSchema.DESTINATION);
|
||||
List<String> destinations = null;
|
||||
if (dest != null) {
|
||||
if (dest instanceof List){
|
||||
destinations = (List<String>)dest;
|
||||
} else if (dest instanceof String){
|
||||
destinations = Collections.singletonList(dest.toString());
|
||||
} else {
|
||||
String message = "Invalid '" + IndexSchema.DESTINATION + "' type.";
|
||||
log.error(message);
|
||||
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, message);
|
||||
}
|
||||
}
|
||||
if (destinations == null) {
|
||||
malformed.add(fieldName);
|
||||
} else {
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -155,7 +156,19 @@ public class FieldCollectionResource extends BaseFieldResource implements GETabl
|
|||
throw new SolrException(ErrorCode.BAD_REQUEST, message);
|
||||
}
|
||||
// copyFields:"comma separated list of destination fields"
|
||||
List<String> copyTo = (List<String>) map.get(IndexSchema.COPY_FIELDS);
|
||||
Object copies = map.get(IndexSchema.COPY_FIELDS);
|
||||
List<String> copyTo = null;
|
||||
if (copies != null) {
|
||||
if (copies instanceof List){
|
||||
copyTo = (List<String>) copies;
|
||||
} else if (copies instanceof String){
|
||||
copyTo = Collections.singletonList(copies.toString());
|
||||
} else {
|
||||
String message = "Invalid '" + IndexSchema.COPY_FIELDS + "' type.";
|
||||
log.error(message);
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST, message);
|
||||
}
|
||||
}
|
||||
if (copyTo != null) {
|
||||
map.remove(IndexSchema.COPY_FIELDS);
|
||||
copyFields.put(fieldName, copyTo);
|
||||
|
|
|
@ -146,7 +146,19 @@ public class FieldResource extends BaseFieldResource implements GETable, PUTable
|
|||
throw new SolrException(ErrorCode.BAD_REQUEST, message);
|
||||
} else {
|
||||
ManagedIndexSchema oldSchema = (ManagedIndexSchema) getSchema();
|
||||
List<String> copyFieldNames = (List<String>) map.get(IndexSchema.COPY_FIELDS);
|
||||
Object copies = map.get(IndexSchema.COPY_FIELDS);
|
||||
List<String> copyFieldNames = null;
|
||||
if (copies != null) {
|
||||
if (copies instanceof List) {
|
||||
copyFieldNames = (List<String>) copies;
|
||||
} else if (copies instanceof String) {
|
||||
copyFieldNames = Collections.singletonList(copies.toString());
|
||||
} else {
|
||||
String message = "Invalid '" + IndexSchema.COPY_FIELDS + "' type.";
|
||||
log.error(message);
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST, message);
|
||||
}
|
||||
}
|
||||
if (copyFieldNames != null) {
|
||||
map.remove(IndexSchema.COPY_FIELDS);
|
||||
}
|
||||
|
|
|
@ -114,6 +114,9 @@ public class TestManagedSchemaFieldResource extends RestTestBase {
|
|||
assertJPut("/schema/fields/fieldB",
|
||||
"{\"type\":\"text\",\"stored\":\"false\", \"copyFields\":[\"fieldA\"]}",
|
||||
"/responseHeader/status==0");
|
||||
assertJPut("/schema/fields/fieldC",
|
||||
"{\"type\":\"text\",\"stored\":\"false\", \"copyFields\":\"fieldA\"}",
|
||||
"/responseHeader/status==0");
|
||||
|
||||
assertQ("/schema/fields/fieldB?indent=on&wt=xml",
|
||||
"count(/response/lst[@name='field']) = 1",
|
||||
|
@ -121,12 +124,15 @@ public class TestManagedSchemaFieldResource extends RestTestBase {
|
|||
assertQ("/schema/copyfields/?indent=on&wt=xml&source.fl=fieldB",
|
||||
"count(/response/arr[@name='copyFields']/lst) = 1"
|
||||
);
|
||||
assertQ("/schema/copyfields/?indent=on&wt=xml&source.fl=fieldC",
|
||||
"count(/response/arr[@name='copyFields']/lst) = 1"
|
||||
);
|
||||
//fine to pass in empty list, just won't do anything
|
||||
assertJPut("/schema/fields/fieldD",
|
||||
"{\"type\":\"text\",\"stored\":\"false\", \"copyFields\":[]}",
|
||||
"/responseHeader/status==0");
|
||||
//some bad usages
|
||||
assertJPut("/schema/fields/fieldC",
|
||||
assertJPut("/schema/fields/fieldF",
|
||||
"{\"type\":\"text\",\"stored\":\"false\", \"copyFields\":[\"some_nonexistent_field_ignore_exception\"]}",
|
||||
"/error/msg==\"copyField dest :\\'some_nonexistent_field_ignore_exception\\' is not an explicit field and doesn\\'t match a dynamicField.\"");
|
||||
}
|
||||
|
@ -185,7 +191,9 @@ public class TestManagedSchemaFieldResource extends RestTestBase {
|
|||
assertJPost("/schema/fields",
|
||||
"[{\"name\":\"fieldD\",\"type\":\"text\",\"stored\":\"false\"},"
|
||||
+ "{\"name\":\"fieldE\",\"type\":\"text\",\"stored\":\"false\"},"
|
||||
+ " {\"name\":\"fieldF\",\"type\":\"text\",\"stored\":\"false\", \"copyFields\":[\"fieldD\",\"fieldE\"]}]",
|
||||
+ " {\"name\":\"fieldF\",\"type\":\"text\",\"stored\":\"false\", \"copyFields\":[\"fieldD\",\"fieldE\"]},"
|
||||
+ " {\"name\":\"fieldG\",\"type\":\"text\",\"stored\":\"false\", \"copyFields\":\"fieldD\"}"//single
|
||||
+ "]",
|
||||
"/responseHeader/status==0");
|
||||
assertQ("/schema/copyfields/?indent=on&wt=xml&source.fl=fieldF",
|
||||
"count(/response/arr[@name='copyFields']/lst) = 2"
|
||||
|
@ -214,7 +222,7 @@ public class TestManagedSchemaFieldResource extends RestTestBase {
|
|||
+ "{\"name\":\"fieldD\",\"type\":\"text\",\"stored\":\"false\"},"
|
||||
+ " {\"name\":\"fieldE\",\"type\":\"text\",\"stored\":\"false\"}]",
|
||||
"/responseHeader/status==0");
|
||||
assertJPost("/schema/copyfields", "[{\"source\":\"fieldA\", \"dest\":[\"fieldB\"]},{\"source\":\"fieldD\", \"dest\":[\"fieldC\", \"fieldE\"]}]", "/responseHeader/status==0");
|
||||
assertJPost("/schema/copyfields", "[{\"source\":\"fieldA\", \"dest\":\"fieldB\"},{\"source\":\"fieldD\", \"dest\":[\"fieldC\", \"fieldE\"]}]", "/responseHeader/status==0");
|
||||
assertQ("/schema/copyfields/?indent=on&wt=xml&source.fl=fieldA",
|
||||
"count(/response/arr[@name='copyFields']/lst) = 1");
|
||||
assertQ("/schema/copyfields/?indent=on&wt=xml&source.fl=fieldD",
|
||||
|
|
Loading…
Reference in New Issue