Apache Lucene open-source search software
- Added a comment and cleaned up.
Otis Gospodnetic6fe013aa7de7
diff --git a/src/java/org/apache/lucene/queryParser/QueryParser.jj b/src/java/org/apache/lucene/queryParser/QueryParser.jjindex 02ea937f3f2..a25d004fc17 100644--- a/src/java/org/apache/lucene/queryParser/QueryParser.jj+++ b/src/java/org/apache/lucene/queryParser/QueryParser.jj@@ -506,7 +506,7 @@ PARSER_END(QueryParser)}<Boost> TOKEN : {-<NUMBER: (<_NUM_CHAR>)+ ( "." (<_NUM_CHAR>)+ )? > : DEFAULT+<NUMBER: (["+","-"])? (<_NUM_CHAR>)+ ( "." (<_NUM_CHAR>)+ )? > : DEFAULT}<RangeIn> TOKEN : {diff --git a/src/java/org/apache/lucene/util/BitVector.java b/src/java/org/apache/lucene/util/BitVector.javaindex 280fe2d823e..828486294c0 100644--- a/src/java/org/apache/lucene/util/BitVector.java+++ b/src/java/org/apache/lucene/util/BitVector.java@@ -62,11 +62,14 @@ import org.apache.lucene.store.OutputStream;/** Optimized implementation of a vector of bits. This is more-or-less likejava.util.BitSet, but also includes the following:- <UL>- <LI>a count() method, which efficiently computes the number of one bits;</LI>- <LI>optimized read from and write to disk;</LI>- <LI>inlinable get() method;</LI>- </UL>+ <ul>+ <li>a count() method, which efficiently computes the number of one bits;</li>+ <li>optimized read from and write to disk;</li>+ <li>inlinable get() method;</li>+ </ul>++ @author Doug Cutting+ @version $Id$*/public final class BitVector {@@ -108,11 +111,12 @@ public final class BitVector {computed and cached, so that, if the vector is not changed, norecomputation is done for repeated calls. */public final int count() {+ // if the vector has been modifiedif (count == -1) {int c = 0;int end = bits.length;for (int i = 0; i < end; i++)- c += BYTE_COUNTS[bits[i] & 0xFF]; // sum bits per byte+ c += BYTE_COUNTS[bits[i] & 0xFF]; // sum bits per bytecount = c;}return count;diff --git a/src/test/org/apache/lucene/SearchTest.java b/src/test/org/apache/lucene/SearchTest.javaindex 2eb291ec725..dee78f190b1 100644--- a/src/test/org/apache/lucene/SearchTest.java+++ b/src/test/org/apache/lucene/SearchTest.java@@ -71,18 +71,18 @@ class SearchTest {IndexWriter writer = new IndexWriter(directory, analyzer, true);String[] docs = {- "a b c d e",- "a b c d e a b c d e",- "a b c d e f g h i j",- "a c e",- "e c a",- "a c e a c e",- "a c e a b c"+ "a b c d e",+ "a b c d e a b c d e",+ "a b c d e f g h i j",+ "a c e",+ "e c a",+ "a c e a c e",+ "a c e a b c"};for (int j = 0; j < docs.length; j++) {- Document d = new Document();- d.add(Field.Text("contents", docs[j]));- writer.addDocument(d);+ Document d = new Document();+ d.add(Field.Text("contents", docs[j]));+ writer.addDocument(d);}writer.close();@@ -94,30 +94,30 @@ class SearchTest {// "\"a b c\"",// "a c",// "\"a c\"",- "\"a c e\"",+ "\"a c e\"",};Hits hits = null;QueryParser parser = new QueryParser("contents", analyzer);parser.setPhraseSlop(4);for (int j = 0; j < queries.length; j++) {- Query query = parser.parse(queries[j]);- System.out.println("Query: " + query.toString("contents"));+ Query query = parser.parse(queries[j]);+ System.out.println("Query: " + query.toString("contents"));//DateFilter filter =// new DateFilter("modified", Time(1997,0,1), Time(1998,0,1));//DateFilter filter = DateFilter.Before("modified", Time(1997,00,01));//System.out.println(filter);- hits = searcher.search(query);+ hits = searcher.search(query);- System.out.println(hits.length() + " total results");- for (int i = 0 ; i < hits.length() && i < 10; i++) {- Document d = hits.doc(i);- System.out.println(i + " " + hits.score(i)+ System.out.println(hits.length() + " total results");+ for (int i = 0 ; i < hits.length() && i < 10; i++) {+ Document d = hits.doc(i);+ System.out.println(i + " " + hits.score(i)// + " " + DateField.stringToDate(d.get("modified"))- + " " + d.get("contents"));- }+ + " " + d.get("contents"));+ }}searcher.close();diff --git a/src/test/org/apache/lucene/index/TestCompoundFile.java b/src/test/org/apache/lucene/index/TestCompoundFile.javaindex 8a7cf958049..c6fd731fb9c 100644--- a/src/test/org/apache/lucene/index/TestCompoundFile.java+++ b/src/test/org/apache/lucene/index/TestCompoundFile.java@@ -1,5 +1,59 @@package org.apache.lucene.index;+/* ====================================================================+ * The Apache Software License, Version 1.1+ *+ * Copyright (c) 2001 The Apache Software Foundation. All rights+ * reserved.+ *+ * Redistribution and use in source and binary forms, with or without+ * modification, are permitted provided that the following conditions+ * are met:+ *+ * 1. Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ *+ * 2. Redistributions in binary form must reproduce the above copyright+ * notice, this list of conditions and the following disclaimer in+ * the documentation and/or other materials provided with the+ * distribution.+ *+ * 3. The end-user documentation included with the redistribution,+ * if any, must include the following acknowledgment:+ * "This product includes software developed by the+ * Apache Software Foundation (http://www.apache.org/)."+ * Alternately, this acknowledgment may appear in the software itself,+ * if and wherever such third-party acknowledgments normally appear.+ *+ * 4. The names "Apache" and "Apache Software Foundation" and+ * "Apache Lucene" must not be used to endorse or promote products+ * derived from this software without prior written permission. For+ * written permission, please contact [email protected].+ *+ * 5. Products derived from this software may not be called "Apache",+ * "Apache Lucene", nor may "Apache" appear in their name, without+ * prior written permission of the Apache Software Foundation.+ *+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF+ * SUCH DAMAGE.+ * ====================================================================+ *+ * This software consists of voluntary contributions made by many+ * individuals on behalf of the Apache Software Foundation. For more+ * information on the Apache Software Foundation, please see+ * <http://www.apache.org/>.+ */+import java.io.IOException;import junit.framework.TestCase;@@ -36,8 +90,8 @@ public class TestCompoundFile extends TestCase// TestRunner.run (new TestCompoundFile("testIWCreate"));}--++public TestCompoundFile() {super();}@@ -45,16 +99,16 @@ public class TestCompoundFile extends TestCasepublic TestCompoundFile(String name) {super(name);}-+private Directory dir;--++public void setUp() throws IOException {//dir = new RAMDirectory();- dir = FSDirectory.getDirectory("testIndex", true);+ dir = FSDirectory.getDirectory("testIndex", true);}--++/** Creates a file of the specified size with random data. */private void createRandomFile(Directory dir, String name, int size)throws IOException@@ -66,15 +120,15 @@ public class TestCompoundFile extends TestCase}os.close();}-+/** Creates a file of the specified size with sequential data. The first* byte is written as the start byte provided. All subsequent bytes are* computed as start + offset where offset is the number of the byte.*/- private void createSequenceFile(Directory dir,- String name,- byte start,- int size)+ private void createSequenceFile(Directory dir,+ String name,+ byte start,+ int size)throws IOException{OutputStream os = dir.createFile(name);@@ -84,35 +138,35 @@ public class TestCompoundFile extends TestCase}os.close();}--- private void assertSameStreams(String msg,- InputStream expected,+++ private void assertSameStreams(String msg,+ InputStream expected,InputStream test)throws IOException{assertNotNull(msg + " null expected", expected);assertNotNull(msg + " null test", test);assertEquals(msg + " length", expected.length(), test.length());- assertEquals(msg + " position", expected.getFilePointer(),+ assertEquals(msg + " position", expected.getFilePointer(),test.getFilePointer());-+byte expectedBuffer[] = new byte[512];byte testBuffer[] = new byte[expectedBuffer.length];-+long remainder = expected.length() - expected.getFilePointer();while(remainder > 0) {int readLen = (int) Math.min(remainder, expectedBuffer.length);expected.readBytes(expectedBuffer, 0, readLen);test.readBytes(testBuffer, 0, readLen);- assertEqualArrays(msg + ", remainder " + remainder, expectedBuffer,+ assertEqualArrays(msg + ", remainder " + remainder, expectedBuffer,testBuffer, 0, readLen);remainder -= readLen;}}- private void assertSameStreams(String msg,+ private void assertSameStreams(String msg,InputStream expected,InputStream actual,long seekTo)@@ -122,30 +176,30 @@ public class TestCompoundFile extends TestCasetry {actual.seek(seekTo);fail(msg + ", " + seekTo + ", negative seek");- } catch (IOException e) {- /* success */+ } catch (IOException e) {+ /* success *///System.out.println("SUCCESS: Negative seek: " + e);}-+} else if (seekTo > 0 && seekTo >= expected.length()) {try {actual.seek(seekTo);fail(msg + ", " + seekTo + ", seek past EOF");- } catch (IOException e) {- /* success */+ } catch (IOException e) {+ /* success *///System.out.println("SUCCESS: Seek past EOF: " + e);}-+} else {expected.seek(seekTo);actual.seek(seekTo);assertSameStreams(msg + ", seek(mid)", expected, actual);}}---- private void assertSameSeekBehavior(String msg,++++ private void assertSameSeekBehavior(String msg,InputStream expected,InputStream actual)throws IOException@@ -153,52 +207,52 @@ public class TestCompoundFile extends TestCase// seek to 0long point = 0;assertSameStreams(msg + ", seek(0)", expected, actual, point);-+// seek to middlepoint = expected.length() / 2l;assertSameStreams(msg + ", seek(mid)", expected, actual, point);-+// seek to end - 2point = expected.length() - 2;assertSameStreams(msg + ", seek(end-2)", expected, actual, point);-+// seek to end - 1point = expected.length() - 1;assertSameStreams(msg + ", seek(end-1)", expected, actual, point);-+// seek to the endpoint = expected.length();assertSameStreams(msg + ", seek(end)", expected, actual, point);-+// seek past endpoint = expected.length() + 1;assertSameStreams(msg + ", seek(end+1)", expected, actual, point);}--- private void assertEqualArrays(String msg,- byte[] expected,- byte[] test,- int start,- int len)+++ private void assertEqualArrays(String msg,+ byte[] expected,+ byte[] test,+ int start,+ int len){assertNotNull(msg + " null expected", expected);assertNotNull(msg + " null test", test);-+for (int i=start; i<len; i++) {assertEquals(msg + " " + i, expected[i], test[i]);}}-+// ===========================================================// Tests of the basic CompoundFile functionality// ===========================================================-+/** This test creates compound file based on a single file.* Files of different sizes are tested: 0, 1, 10, 100 bytes.- */+ */public void testSingleFile() throws IOException {int data[] = new int[] { 0, 1, 10, 100 };for (int i=0; i<data.length; i++) {@@ -207,7 +261,7 @@ public class TestCompoundFile extends TestCaseCompoundFileWriter csw = new CompoundFileWriter(dir, name + ".cfs");csw.addFile(name);csw.close();-+CompoundFileReader csr = new CompoundFileReader(dir, name + ".cfs");InputStream expected = dir.openFile(name);InputStream actual = csr.openFile(name);@@ -218,20 +272,20 @@ public class TestCompoundFile extends TestCasecsr.close();}}--++/** This test creates compound file based on two files.- *+ **/public void testTwoFiles() throws IOException {createSequenceFile(dir, "d1", (byte) 0, 15);createSequenceFile(dir, "d2", (byte) 0, 114);-+CompoundFileWriter csw = new CompoundFileWriter(dir, "d.csf");csw.addFile("d1");csw.addFile("d2");csw.close();-+CompoundFileReader csr = new CompoundFileReader(dir, "d.csf");InputStream expected = dir.openFile("d1");InputStream actual = csr.openFile("d1");@@ -239,7 +293,7 @@ public class TestCompoundFile extends TestCaseassertSameSeekBehavior("d1", expected, actual);expected.close();actual.close();-+expected = dir.openFile("d2");actual = csr.openFile("d2");assertSameStreams("d2", expected, actual);@@ -248,7 +302,7 @@ public class TestCompoundFile extends TestCaseactual.close();csr.close();}-+/** This test creates a compound file based on a large number of files of* various length. The file content is generated randomly. The sizes range* from 0 to 1Mb. Some of the sizes are selected to test the buffering@@ -270,7 +324,7 @@ public class TestCompoundFile extends TestCasecreateRandomFile(dir, segment + ".big5", 3 * chunk - 1);createRandomFile(dir, segment + ".big6", 3 * chunk + 1);createRandomFile(dir, segment + ".big7", 1000 * chunk);-+// Setup extraneous filescreateRandomFile(dir, "onetwothree", 100);createRandomFile(dir, segment + ".notIn", 50);@@ -279,14 +333,14 @@ public class TestCompoundFile extends TestCase// Now testCompoundFileWriter csw = new CompoundFileWriter(dir, "test.cfs");final String data[] = new String[] {- ".zero", ".one", ".ten", ".hundred", ".big1", ".big2", ".big3",+ ".zero", ".one", ".ten", ".hundred", ".big1", ".big2", ".big3",".big4", ".big5", ".big6", ".big7"};for (int i=0; i<data.length; i++) {csw.addFile(segment + data[i]);}csw.close();-+CompoundFileReader csr = new CompoundFileReader(dir, "test.cfs");for (int i=0; i<data.length; i++) {InputStream check = dir.openFile(segment + data[i]);@@ -298,11 +352,11 @@ public class TestCompoundFile extends TestCase}csr.close();}--- /** Setup a larger compound file with a number of components, each of+++ /** Setup a larger compound file with a number of components, each of* which is a sequential file (so that we can easily tell that we are- * reading in the right byte). The methods sets up 20 files - f0 to f19,+ * reading in the right byte). The methods sets up 20 files - f0 to f19,* the size of each file is 1000 bytes.*/private void setUp_2() throws IOException {@@ -313,12 +367,12 @@ public class TestCompoundFile extends TestCase}cw.close();}--++public void testReadAfterClose() throws IOException {demo_FSInputStreamBug((FSDirectory) dir, "test");}-+private void demo_FSInputStreamBug(FSDirectory fsdir, String file)throws IOException{@@ -328,96 +382,96 @@ public class TestCompoundFile extends TestCaseos.writeByte((byte) i);}os.close();-+InputStream in = fsdir.openFile(file);-+// This read primes the buffer in InputStreambyte b = in.readByte();-+// Close the filein.close();-- // ERROR: this call should fail, but succeeds because the buffer++ // ERROR: this call should fail, but succeeds because the buffer// is still filledb = in.readByte();// ERROR: this call should fail, but succeeds for some reason as wellin.seek(1099);-+try {- // OK: this call correctly fails. We are now past the 1024 internal+ // OK: this call correctly fails. We are now past the 1024 internal// buffer, so an actual IO is attempted, which failsb = in.readByte();} catch (IOException e) {}}--++static boolean isCSInputStream(InputStream is) {return is instanceof CompoundFileReader.CSInputStream;}-+static boolean isCSInputStreamOpen(InputStream is) throws IOException {if (isCSInputStream(is)) {- CompoundFileReader.CSInputStream cis =+ CompoundFileReader.CSInputStream cis =(CompoundFileReader.CSInputStream) is;-+return _TestHelper.isFSInputStreamOpen(cis.base);} else {return false;}}-+public void testClonedStreamsClosing() throws IOException {setUp_2();CompoundFileReader cr = new CompoundFileReader(dir, "f.comp");-+// basic cloneInputStream expected = dir.openFile("f11");assertTrue(_TestHelper.isFSInputStreamOpen(expected));-+InputStream one = cr.openFile("f11");assertTrue(isCSInputStreamOpen(one));-+InputStream two = (InputStream) one.clone();assertTrue(isCSInputStreamOpen(two));-+assertSameStreams("basic clone one", expected, one);expected.seek(0);assertSameStreams("basic clone two", expected, two);-+// Now close the first stream- one.close();+ one.close();assertTrue("Only close when cr is closed", isCSInputStreamOpen(one));-+// The following should really fail since we couldn't expect to// access a file once close has been called on it (regardless of- // buffering and/or clone magic)+ // buffering and/or clone magic)expected.seek(0);two.seek(0);assertSameStreams("basic clone two/2", expected, two);--- // Now close the compound reader+++ // Now close the compound readercr.close();assertFalse("Now closed one", isCSInputStreamOpen(one));assertFalse("Now closed two", isCSInputStreamOpen(two));-+// The following may also fail since the compound stream is closedexpected.seek(0);two.seek(0);//assertSameStreams("basic clone two/3", expected, two);--++// Now close the second clonetwo.close();expected.seek(0);two.seek(0);//assertSameStreams("basic clone two/4", expected, two);-+expected.close();- }+ }/** This test opens two files from a compound stream and verifies that@@ -426,39 +480,39 @@ public class TestCompoundFile extends TestCasepublic void testRandomAccess() throws IOException {setUp_2();CompoundFileReader cr = new CompoundFileReader(dir, "f.comp");-- // Open two files++ // Open two filesInputStream e1 = dir.openFile("f11");InputStream e2 = dir.openFile("f3");-- InputStream a1 = cr.openFile("f11");++ InputStream a1 = cr.openFile("f11");InputStream a2 = dir.openFile("f3");-+// Seek the first paire1.seek(100);- a1.seek(100);+ a1.seek(100);assertEquals(100, e1.getFilePointer());assertEquals(100, a1.getFilePointer());byte be1 = e1.readByte();byte ba1 = a1.readByte();assertEquals(be1, ba1);-+// Now seek the second paire2.seek(1027);- a2.seek(1027);+ a2.seek(1027);assertEquals(1027, e2.getFilePointer());assertEquals(1027, a2.getFilePointer());byte be2 = e2.readByte();byte ba2 = a2.readByte();assertEquals(be2, ba2);-+// Now make sure the first one didn't moveassertEquals(101, e1.getFilePointer());assertEquals(101, a1.getFilePointer());be1 = e1.readByte();ba1 = a1.readByte();assertEquals(be1, ba1);-+// Now more the first one again, past the buffer lengthe1.seek(1910);a1.seek(1910);@@ -467,14 +521,14 @@ public class TestCompoundFile extends TestCasebe1 = e1.readByte();ba1 = a1.readByte();assertEquals(be1, ba1);-+// Now make sure the second set didn't moveassertEquals(1028, e2.getFilePointer());assertEquals(1028, a2.getFilePointer());be2 = e2.readByte();ba2 = a2.readByte();assertEquals(be2, ba2);-+// Move the second set back, again cross the buffer sizee2.seek(17);a2.seek(17);@@ -484,60 +538,60 @@ public class TestCompoundFile extends TestCaseba2 = a2.readByte();assertEquals(be2, ba2);- // Finally, make sure the first set didn't move+ // Finally, make sure the first set didn't move// Now make sure the first one didn't moveassertEquals(1911, e1.getFilePointer());assertEquals(1911, a1.getFilePointer());be1 = e1.readByte();ba1 = a1.readByte();assertEquals(be1, ba1);-+e1.close();e2.close();a1.close();a2.close();cr.close();- }-+ }+/** This test opens two files from a compound stream and verifies that* their file positions are independent of each other.*/public void testRandomAccessClones() throws IOException {setUp_2();CompoundFileReader cr = new CompoundFileReader(dir, "f.comp");-- // Open two files++ // Open two filesInputStream e1 = cr.openFile("f11");InputStream e2 = cr.openFile("f3");-+InputStream a1 = (InputStream) e1.clone();InputStream a2 = (InputStream) e2.clone();-+// Seek the first paire1.seek(100);- a1.seek(100);+ a1.seek(100);assertEquals(100, e1.getFilePointer());assertEquals(100, a1.getFilePointer());byte be1 = e1.readByte();byte ba1 = a1.readByte();assertEquals(be1, ba1);-+// Now seek the second paire2.seek(1027);- a2.seek(1027);+ a2.seek(1027);assertEquals(1027, e2.getFilePointer());assertEquals(1027, a2.getFilePointer());byte be2 = e2.readByte();byte ba2 = a2.readByte();assertEquals(be2, ba2);-+// Now make sure the first one didn't moveassertEquals(101, e1.getFilePointer());assertEquals(101, a1.getFilePointer());be1 = e1.readByte();ba1 = a1.readByte();assertEquals(be1, ba1);-+// Now more the first one again, past the buffer lengthe1.seek(1910);a1.seek(1910);@@ -546,14 +600,14 @@ public class TestCompoundFile extends TestCasebe1 = e1.readByte();ba1 = a1.readByte();assertEquals(be1, ba1);-+// Now make sure the second set didn't moveassertEquals(1028, e2.getFilePointer());assertEquals(1028, a2.getFilePointer());be2 = e2.readByte();ba2 = a2.readByte();assertEquals(be2, ba2);-+// Move the second set back, again cross the buffer sizee2.seek(17);a2.seek(17);@@ -563,40 +617,40 @@ public class TestCompoundFile extends TestCaseba2 = a2.readByte();assertEquals(be2, ba2);- // Finally, make sure the first set didn't move+ // Finally, make sure the first set didn't move// Now make sure the first one didn't moveassertEquals(1911, e1.getFilePointer());assertEquals(1911, a1.getFilePointer());be1 = e1.readByte();ba1 = a1.readByte();assertEquals(be1, ba1);-+e1.close();e2.close();a1.close();a2.close();cr.close();- }--+ }++public void testFileNotFound() throws IOException {- setUp_2();+ setUp_2();CompoundFileReader cr = new CompoundFileReader(dir, "f.comp");-- // Open two files++ // Open two filestry {InputStream e1 = cr.openFile("bogus");fail("File not found");-+} catch (IOException e) {/* success *///System.out.println("SUCCESS: File Not Found: " + e);}-+cr.close();}--++public void testReadPastEOF() throws IOException {setUp_2();CompoundFileReader cr = new CompoundFileReader(dir, "f.comp");@@ -604,7 +658,7 @@ public class TestCompoundFile extends TestCaseis.seek(is.length() - 10);byte b[] = new byte[100];is.readBytes(b, 0, 10);-+try {byte test = is.readByte();fail("Single byte read past end of file");@@ -612,7 +666,7 @@ public class TestCompoundFile extends TestCase/* success *///System.out.println("SUCCESS: single byte read past end of file: " + e);}-+is.seek(is.length() - 10);try {is.readBytes(b, 0, 50);@@ -621,81 +675,8 @@ public class TestCompoundFile extends TestCase/* success *///System.out.println("SUCCESS: block read past end of file: " + e);}-+is.close();cr.close();}--- // ===========================================================- // More extensive tests involving an IndexWriter- // ===========================================================-- public void testIWCreate() throws IOException {- // create index writer- IndexWriter iw = new IndexWriter(dir, new WhitespaceAnalyzer(), true);- int created = 0;- for (int i=0; i<150; i++) {- iw.addDocument(createTestDoc(String.valueOf(i)));- created ++;- }- assertEquals(created, iw.docCount());- iw.close();-- // delete 500 documents- IndexReader reader = IndexReader.open(dir);- int deleted = 0;- for (int i = 10; i < created-7; i+=7) {- reader.delete(i);- deleted ++;- }- reader.close();- int remains = created - deleted;-- iw = new IndexWriter(dir, new WhitespaceAnalyzer(), false);- assertEquals(created, iw.docCount());- iw.close();-- reader = IndexReader.open(dir);- assertEquals(created, reader.maxDoc());- assertEquals(remains, reader.numDocs());- for (int i = 10; i < created-7; i+=7) {- assertTrue("deleted: " + i, reader.isDeleted(i));- assertFalse("deleted+1: " + i, reader.isDeleted(i + 1));- assertFalse("deleted-1: " + i, reader.isDeleted(i - 1));- }-- reader.close();-- iw = new IndexWriter(dir, new WhitespaceAnalyzer(), false);- iw.optimize();- assertEquals(remains, iw.docCount());- iw.close();-- reader = IndexReader.open(dir);- assertEquals(remains, reader.maxDoc());- assertEquals(remains, reader.numDocs());- reader.close();- }--- private Document createTestDoc(String id) {- Document doc = new Document();- doc.add(Field.Keyword("keyword_id", id));- doc.add(Field.Text("text_id", id));- doc.add(Field.Keyword("keyword_text", "KeywordText"));- doc.add(Field.Text("text", "This is a text field"));- doc.add(Field.UnIndexed("unindexed", "This is some payload unindexed text"));- doc.add(Field.UnStored("unstored", "This is unstored text"));- return doc;- }-- private void verifyDoc(Document doc, String id) {- assertEquals("keyword_id", doc.get("keyword_id"), id);- assertEquals("text_id", id);- assertEquals("keyword_text", doc.get("keyword_text"), "KeywordText");- assertEquals("text", doc.get("text"), "This is some payload unindexed text");- assertEquals("unindexed", doc.get("unindexed"), "This is some payload unindexed text");- assertNull("unstored", doc.get("unstored"));- }}diff --git a/src/test/org/apache/lucene/index/TestIndexWriter.java b/src/test/org/apache/lucene/index/TestIndexWriter.javaindex 0e956697681..7b65990ada1 100644--- a/src/test/org/apache/lucene/index/TestIndexWriter.java+++ b/src/test/org/apache/lucene/index/TestIndexWriter.java@@ -37,30 +37,33 @@ public class TestIndexWriter extends TestCaseassertEquals(100, writer.docCount());writer.close();- // delete 50 documents+ // delete 40 documentsreader = IndexReader.open(dir);- for (i = 0; i < 50; i++) {+ for (i = 0; i < 40; i++) {reader.delete(i);}reader.close();- writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);+ // test doc count before segments are merged/index is optimized+ writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);assertEquals(100, writer.docCount());writer.close();reader = IndexReader.open(dir);assertEquals(100, reader.maxDoc());- assertEquals(50, reader.numDocs());+ assertEquals(60, reader.numDocs());reader.close();- writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);+ // optimize the index and check that the new doc count is correct+ writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);writer.optimize();- assertEquals(50, writer.docCount());+ assertEquals(60, writer.docCount());writer.close();+ // check that the index reader gives the same numbers.reader = IndexReader.open(dir);- assertEquals(50, reader.maxDoc());- assertEquals(50, reader.numDocs());+ assertEquals(60, reader.maxDoc());+ assertEquals(60, reader.numDocs());reader.close();}catch (IOException e) {diff --git a/src/test/org/apache/lucene/store/_TestHelper.java b/src/test/org/apache/lucene/store/_TestHelper.javaindex 0cd0d9cbae3..9128a32a1ae 100644--- a/src/test/org/apache/lucene/store/_TestHelper.java+++ b/src/test/org/apache/lucene/store/_TestHelper.java@@ -5,7 +5,6 @@ import java.io.IOException;/** This class provides access to package-level features defined in the* store package. It is used for testing only.*/-public class _TestHelper {/** Returns true if the instance of the provided input stream is actually@@ -14,8 +13,8 @@ public class _TestHelper {public static boolean isFSInputStream(InputStream is) {return is instanceof FSInputStream;}-- /** Returns true if the provided input stream is an FSInputStream and++ /** Returns true if the provided input stream is an FSInputStream and* is a clone, that is it does not own its underlying file descriptor.*/public static boolean isFSInputStreamClone(InputStream is) {@@ -29,7 +28,7 @@ public class _TestHelper {/** Given an instance of FSDirectory.FSInputStream, this method returns* true if the underlying file descriptor is valid, and false otherwise.* This can be used to determine if the OS file has been closed.- * The descriptor becomes invalid when the non-clone instance of the+ * The descriptor becomes invalid when the non-clone instance of the* FSInputStream that owns this descriptor is closed. However, the* descriptor may possibly become invalid in other ways as well.*/@@ -44,4 +43,4 @@ public class _TestHelper {}}-}\ No newline at end of file+}diff --git a/src/test/org/apache/lucene/util/TestBitVector.java b/src/test/org/apache/lucene/util/TestBitVector.javaindex ac38e9f068d..b9d45a6b5d5 100644--- a/src/test/org/apache/lucene/util/TestBitVector.java+++ b/src/test/org/apache/lucene/util/TestBitVector.java@@ -196,7 +196,8 @@ public class TestBitVector extends TestCase}/**- * Compare two BitVectors (really, this should be an equals method on the BitVector itself...+ * Compare two BitVectors.+ * This should really be an equals method on the BitVector itself.* @param bv One bit vector* @param compare The second to compare*/