public virtual void TestFieldSetValue() { Field field = new StringField("id", "id1", Field.Store.YES); Documents.Document doc = new Documents.Document(); doc.Add(field); doc.Add(new StringField("keyword", "test", Field.Store.YES)); Directory dir = NewDirectory(); RandomIndexWriter writer = new RandomIndexWriter( #if FEATURE_INSTANCE_TESTDATA_INITIALIZATION this, #endif Random, dir); writer.AddDocument(doc); field.SetStringValue("id2"); writer.AddDocument(doc); field.SetStringValue("id3"); writer.AddDocument(doc); IndexReader reader = writer.GetReader(); IndexSearcher searcher = NewSearcher(reader); Query query = new TermQuery(new Term("keyword", "test")); // ensure that queries return expected results without DateFilter first ScoreDoc[] hits = searcher.Search(query, null, 1000).ScoreDocs; Assert.AreEqual(3, hits.Length); int result = 0; for (int i = 0; i < 3; i++) { Documents.Document doc2 = searcher.Doc(hits[i].Doc); Field f = (Field)doc2.GetField("id"); if (f.GetStringValue().Equals("id1", StringComparison.Ordinal)) { result |= 1; } else if (f.GetStringValue().Equals("id2", StringComparison.Ordinal)) { result |= 2; } else if (f.GetStringValue().Equals("id3", StringComparison.Ordinal)) { result |= 4; } else { Assert.Fail("unexpected id field"); } } writer.Dispose(); reader.Dispose(); dir.Dispose(); Assert.AreEqual(7, result, "did not see all IDs"); }