public virtual void TestUpdateNonNumericDocValuesField()
{
// we don't support adding new fields or updating existing non-numeric-dv
// fields through numeric updates
Directory dir = NewDirectory();
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
IndexWriter writer = new IndexWriter(dir, conf);
Document doc = new Document();
doc.Add(new StringField("key", "doc", Store.NO));
doc.Add(new StringField("foo", "bar", Store.NO));
writer.AddDocument(doc); // flushed document
writer.Commit();
writer.AddDocument(doc); // in-memory document
try
{
writer.UpdateNumericDocValue(new Term("key", "doc"), "ndv", 17L);
Assert.Fail("should not have allowed creating new fields through update");
}
catch (System.ArgumentException e)
{
// ok
}
try
{
writer.UpdateNumericDocValue(new Term("key", "doc"), "foo", 17L);
Assert.Fail("should not have allowed updating an existing field to numeric-dv");
}
catch (System.ArgumentException e)
{
// ok
}
writer.Dispose();
dir.Dispose();
}