Field field = new Field("id", "id1", Field.Store.YES, Field.Index.NOT_ANALYZED);
Document doc = new Document();
doc.add(field);
doc.add(new Field("keyword", "test", Field.Store.YES, Field.Index.NOT_ANALYZED));
RAMDirectory dir = new RAMDirectory();
IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT), true, IndexWriter.MaxFieldLength.LIMITED);
writer.addDocument(doc);
field.setValue("id2");
writer.addDocument(doc);
field.setValue("id3");
writer.addDocument(doc);
writer.close();
Searcher searcher = new IndexSearcher(dir, true);
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;
assertEquals(3, hits.length);
int result = 0;
for(int i=0;i<3;i++) {
Document doc2 = searcher.doc(hits[i].doc);
Field f = doc2.getField("id");
if (f.stringValue().equals("id1"))
result |= 1;
else if (f.stringValue().equals("id2"))
result |= 2;
else if (f.stringValue().equals("id3"))
result |= 4;
else
fail("unexpected id field");
}
searcher.close();
dir.close();
assertEquals("did not see all IDs", 7, result);
}