- Applied a patch from Christoph Goller.

- Unified a mix of 2 and 4-space indentations.


git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150026 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Otis Gospodnetic 2003-09-15 12:33:07 +00:00
parent 84cab1f807
commit 045c15c808
1 changed files with 36 additions and 28 deletions

View File

@ -14,13 +14,11 @@ import org.apache.lucene.store.RAMDirectory;
/** /**
*
* @author goller * @author goller
* @version $Id$
*/ */
public class TestIndexWriter extends TestCase public class TestIndexWriter extends TestCase
{ {
private int docCount = 0;
public void testDocCount() public void testDocCount()
{ {
Directory dir = new RAMDirectory(); Directory dir = new RAMDirectory();
@ -30,46 +28,56 @@ public class TestIndexWriter extends TestCase
int i; int i;
try { try {
writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true); writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
// add 100 documents // add 100 documents
for (i = 0; i < 100; i++) { for (i = 0; i < 100; i++) {
addDoc(writer); addDoc(writer);
} }
assertEquals(100, writer.docCount()); assertEquals(100, writer.docCount());
writer.close(); writer.close();
// delete 50 documents // delete 50 documents
reader = IndexReader.open(dir); reader = IndexReader.open(dir);
for (i = 0; i < 50; i++) { for (i = 0; i < 50; i++) {
reader.delete(i); reader.delete(i);
} }
reader.close(); reader.close();
writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false); writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
assertEquals(50, writer.docCount()); assertEquals(100, writer.docCount());
writer.optimize(); writer.close();
assertEquals(50, writer.docCount());
writer.close(); reader = IndexReader.open(dir);
assertEquals(100, reader.maxDoc());
assertEquals(50, reader.numDocs());
reader.close();
writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
writer.optimize();
assertEquals(50, writer.docCount());
writer.close();
reader = IndexReader.open(dir);
assertEquals(50, reader.maxDoc());
assertEquals(50, reader.numDocs());
reader.close();
} }
catch (IOException e) { catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
private void addDoc(IndexWriter writer) private void addDoc(IndexWriter writer)
{ {
Document doc = new Document(); Document doc = new Document();
doc.add(Field.UnStored("content", "aaa"));
doc.add(Field.Keyword("id","id" + docCount));
doc.add(Field.UnStored("content","aaa"));
try { try {
writer.addDocument(doc); writer.addDocument(doc);
} }
catch (IOException e) { catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
docCount++;
} }
} }