SOLR-5000: ManagedIndexSchema doesn't persist uniqueKey tag after calling addFields method

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1499578 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Steven Rowe 2013-07-03 22:07:51 +00:00
parent d23f0887e6
commit e76d6599d9
5 changed files with 72 additions and 2 deletions

View File

@ -242,6 +242,9 @@ Bug Fixes
* SOLR-4452: Hunspell stemmer should not merge duplicate dictionary entries (janhoy)
* SOLR-5000: ManagedIndexSchema doesn't persist uniqueKey tag after calling addFields
method. (Jun Ohtani, Steve Rowe)
Optimizations
----------------------

View File

@ -311,8 +311,8 @@ public class IndexSchema {
*/
public SchemaField getUniqueKeyField() { return uniqueKeyField; }
private String uniqueKeyFieldName;
private FieldType uniqueKeyFieldType;
protected String uniqueKeyFieldName;
protected FieldType uniqueKeyFieldType;
/**
* The raw (field type encoded) value of the Unique Key field for

View File

@ -334,6 +334,8 @@ public final class ManagedIndexSchema extends IndexSchema {
newSchema.similarityFactory = similarityFactory;
newSchema.isExplicitSimilarity = isExplicitSimilarity;
newSchema.uniqueKeyField = uniqueKeyField;
newSchema.uniqueKeyFieldName = uniqueKeyFieldName;
newSchema.uniqueKeyFieldType = uniqueKeyFieldType;
if (includeFieldDataStructures) {
// These need new collections, since addFields() can add members to them

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
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="one_field_no_dynamic_field_unique_key" version="1.1">
<types>
<fieldType name="string" class="solr.StrField"/>
<fieldType name="text" class="solr.TextField">
<analyzer class="org.apache.lucene.analysis.standard.StandardAnalyzer"/>
</fieldType>
</types>
<fields>
<field name="str" type="string" indexed="true" stored="true"/>
</fields>
<uniqueKey>str</uniqueKey>
</schema>

View File

@ -57,6 +57,7 @@ public class TestManagedSchema extends AbstractBadConfigTestBase {
FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig-basic.xml"), tmpConfDir);
FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig.snippet.randomindexconfig.xml"), tmpConfDir);
FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema-one-field-no-dynamic-field.xml"), tmpConfDir);
FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema-one-field-no-dynamic-field-unique-key.xml"), tmpConfDir);
FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema-minimal.xml"), tmpConfDir);
FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema_codec.xml"), tmpConfDir);
FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema-bm25.xml"), tmpConfDir);
@ -386,4 +387,39 @@ public class TestManagedSchema extends AbstractBadConfigTestBase {
assertQ(req(fieldName + ":thing"), "//*[@numFound='1']");
}
public void testPersistUniqueKey() throws Exception {
assertSchemaResource(collection, "managed-schema");
deleteCore();
File managedSchemaFile = new File(tmpConfDir, "managed-schema");
assertTrue(managedSchemaFile.delete()); // Delete managed-schema so it won't block parsing a new schema
initCore("solrconfig-mutable-managed-schema.xml", "schema-one-field-no-dynamic-field-unique-key.xml", tmpSolrHome.getPath());
assertTrue(managedSchemaFile.exists());
String managedSchemaContents = FileUtils.readFileToString(managedSchemaFile, "UTF-8");
assertFalse(managedSchemaContents.contains("\"new_field\""));
Map<String,Object> options = new HashMap<String,Object>();
options.put("stored", "false");
IndexSchema oldSchema = h.getCore().getLatestSchema();
assertEquals("str", oldSchema.getUniqueKeyField().getName());
String fieldName = "new_field";
String fieldType = "string";
SchemaField newField = oldSchema.newField(fieldName, fieldType, options);
IndexSchema newSchema = oldSchema.addField(newField);
assertEquals("str", newSchema.getUniqueKeyField().getName());
h.getCore().setLatestSchema(newSchema);
log.info("####close harness");
h.close();
log.info("####close harness end");
initCore();
assertTrue(managedSchemaFile.exists());
FileInputStream stream = new FileInputStream(managedSchemaFile);
managedSchemaContents = IOUtils.toString(stream, "UTF-8");
stream.close(); // Explicitly close so that Windows can delete this file
assertTrue(managedSchemaContents.contains("<field name=\"new_field\" type=\"string\" stored=\"false\"/>"));
IndexSchema newNewSchema = h.getCore().getLatestSchema();
assertNotNull(newNewSchema.getUniqueKeyField());
assertEquals("str", newNewSchema.getUniqueKeyField().getName());
}
}