SOLR-4729: LukeRequestHandler: Using a dynamic copyField source that is not also a dynamic field triggers error message 'undefined field: "(glob)"'

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1470820 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Steven Rowe 2013-04-23 05:56:05 +00:00
parent 383af5c085
commit c8f3000300
4 changed files with 35 additions and 7 deletions

View File

@ -68,6 +68,10 @@ Bug Fixes
* SOLR-4333: edismax parser to not double-escape colons if already escaped by
the client application (James Dyer, Robert J. van der Boon)
* SOLR-4729: LukeRequestHandler: Using a dynamic copyField source that is
not also a dynamic field triggers error message 'undefined field: "(glob)"'.
(Adam Hahn, hossman, Steve Rowe)
Other Changes
----------------------

View File

@ -525,7 +525,7 @@ public class LukeRequestHandler extends RequestHandlerBase
field.add("positionIncrementGap", ft.getAnalyzer().getPositionIncrementGap(f.getName()));
}
field.add("copyDests", toListOfStringDests(schema.getCopyFieldsList(f.getName())));
field.add("copySources", toListOfStrings(schema.getCopySources(f.getName())));
field.add("copySources", schema.getCopySources(f.getName()));
fields.put( f.getName(), field );

View File

@ -1224,25 +1224,25 @@ public class IndexSchema {
* @return Array of fields copied into this field
*/
public SchemaField[] getCopySources(String destField) {
public List<String> getCopySources(String destField) {
SchemaField f = getField(destField);
if (!isCopyFieldTarget(f)) {
return new SchemaField[0];
return Collections.emptyList();
}
List<SchemaField> sf = new ArrayList<SchemaField>();
List<String> fieldNames = new ArrayList<String>();
for (Map.Entry<String, List<CopyField>> cfs : copyFieldsMap.entrySet()) {
for (CopyField copyField : cfs.getValue()) {
if (copyField.getDestination().getName().equals(destField)) {
sf.add(copyField.getSource());
fieldNames.add(copyField.getSource().getName());
}
}
}
for (DynamicCopy dynamicCopy : dynamicCopyFields) {
if (dynamicCopy.getDestFieldName().equals(destField)) {
sf.add(getField(dynamicCopy.getRegex()));
fieldNames.add(dynamicCopy.getRegex());
}
}
return sf.toArray(new SchemaField[sf.size()]);
return fieldNames;
}
/**

View File

@ -22,6 +22,7 @@ import java.util.EnumSet;
import org.apache.solr.common.luke.FieldFlag;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.util.AbstractSolrTestCase;
import org.junit.Before;
import org.junit.BeforeClass;
@ -196,4 +197,27 @@ public class LukeRequestHandlerTest extends AbstractSolrTestCase {
assertEquals(xml, null, r);
}
public void testCatchAllCopyField() throws Exception {
deleteCore();
initCore("solrconfig.xml", "schema-copyfield-test.xml");
IndexSchema schema = h.getCore().getLatestSchema();
assertNull("'*' should not be (or match) a dynamic field", schema.getDynamicPattern("*"));
boolean foundCatchAllCopyField = false;
for (IndexSchema.DynamicCopy dcf : schema.getDynamicCopyFields()) {
foundCatchAllCopyField = dcf.getRegex().equals("*") && dcf.getDestFieldName().equals("catchall_t");
}
assertTrue("<copyField source=\"*\" dest=\"catchall_t\"/> is missing from the schema", foundCatchAllCopyField);
SolrQueryRequest req = req("qt", "/admin/luke", "show", "schema", "indent", "on");
String xml = h.query(req);
String result = h.validateXPath(xml, field("bday") + "/arr[@name='copyDests']/str[.='catchall_t']");
assertNull(xml, result);
// Put back the configuration expected by the rest of the tests in this suite
deleteCore();
initCore("solrconfig.xml", "schema12.xml");
}
}