writer.commit();
// try the search over the first doc
IndexSearcher indexSearcher = new IndexSearcher(writer.getReader());
TopDocs result = indexSearcher.search(
new MatchAllDocsQuery("contents"), 10);
assertTrue(result.totalHits > 0);
Document d = indexSearcher.doc(result.scoreDocs[0].doc);
assertNotNull(d);
assertNotNull(d.getFieldable("title"));
assertNotNull(d.getFieldable("contents"));
// add a second doc
doc = new Document();
doc.add(new Field("title", "il mio titolo", Field.Store.YES,
Field.Index.ANALYZED));
doc.add(new Field("contents", "che cosa e' scritto qui",
Field.Store.YES, Field.Index.ANALYZED));
writer.addDocument(doc, analyzer);
writer.commit();
// do a matchalldocs query to retrieve both docs
indexSearcher = new IndexSearcher(writer.getReader());
result = indexSearcher.search(
new MatchAllDocsQuery("contents"), 10);
assertTrue(result.totalHits > 0);
for (ScoreDoc di : result.scoreDocs) {
d = indexSearcher.doc(di.doc);
assertNotNull(d);
assertNotNull(d.getFieldable("title"));