lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From o...@apache.org
Subject cvs commit: jakarta-lucene/src/test/org/apache/lucene/util TestBitVector.java
Date Mon, 13 Oct 2003 14:31:39 GMT
otis        2003/10/13 07:31:39

  Modified:    src/java/org/apache/lucene/queryParser QueryParser.jj
               src/java/org/apache/lucene/util BitVector.java
               src/test/org/apache/lucene SearchTest.java
               src/test/org/apache/lucene/index TestCompoundFile.java
                        TestIndexWriter.java
               src/test/org/apache/lucene/store _TestHelper.java
               src/test/org/apache/lucene/util TestBitVector.java
  Log:
  - Added a comment and cleaned up.
  
  Revision  Changes    Path
  1.35      +1 -1      jakarta-lucene/src/java/org/apache/lucene/queryParser/QueryParser.jj
  
  Index: QueryParser.jj
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/queryParser/QueryParser.jj,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- QueryParser.jj	9 Oct 2003 01:22:21 -0000	1.34
  +++ QueryParser.jj	13 Oct 2003 14:31:38 -0000	1.35
  @@ -506,7 +506,7 @@
   }
   
   <Boost> TOKEN : {
  -<NUMBER:    (<_NUM_CHAR>)+ ( "." (<_NUM_CHAR>)+ )? > : DEFAULT
  +<NUMBER:    (["+","-"])?   (<_NUM_CHAR>)+ ( "." (<_NUM_CHAR>)+ )? > :
DEFAULT
   }
   
   <RangeIn> TOKEN : {
  
  
  
  1.3       +10 -6     jakarta-lucene/src/java/org/apache/lucene/util/BitVector.java
  
  Index: BitVector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/util/BitVector.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BitVector.java	23 Feb 2003 07:02:10 -0000	1.2
  +++ BitVector.java	13 Oct 2003 14:31:38 -0000	1.3
  @@ -62,11 +62,14 @@
   
   /** Optimized implementation of a vector of bits.  This is more-or-less like
     java.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 @@
       computed and cached, so that, if the vector is not changed, no
       recomputation is done for repeated calls. */
     public final int count() {
  +    // if the vector has been modified
       if (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 byte
         count = c;
       }
       return count;
  
  
  
  1.5       +20 -20    jakarta-lucene/src/test/org/apache/lucene/SearchTest.java
  
  Index: SearchTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/test/org/apache/lucene/SearchTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SearchTest.java	29 Jan 2003 17:43:12 -0000	1.4
  +++ SearchTest.java	13 Oct 2003 14:31:38 -0000	1.5
  @@ -71,18 +71,18 @@
         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 @@
   // 	"\"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();
         
  
  
  
  1.2       +192 -211  jakarta-lucene/src/test/org/apache/lucene/index/TestCompoundFile.java
  
  Index: TestCompoundFile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/test/org/apache/lucene/index/TestCompoundFile.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestCompoundFile.java	25 Sep 2003 22:01:51 -0000	1.1
  +++ TestCompoundFile.java	13 Oct 2003 14:31:38 -0000	1.2
  @@ -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 apache@apache.org.
  + *
  + * 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 @@
   //        TestRunner.run (new TestCompoundFile("testIWCreate"));
   
       }
  -    
  -    
  +
  +
       public TestCompoundFile() {
           super();
       }
  @@ -45,16 +99,16 @@
       public 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 @@
           }
           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 @@
           }
           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 @@
               try {
                   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 @@
           // seek to 0
           long point = 0;
           assertSameStreams(msg + ", seek(0)", expected, actual, point);
  -        
  +
           // seek to middle
           point = expected.length() / 2l;
           assertSameStreams(msg + ", seek(mid)", expected, actual, point);
  -        
  +
           // seek to end - 2
           point = expected.length() - 2;
           assertSameStreams(msg + ", seek(end-2)", expected, actual, point);
  -        
  +
           // seek to end - 1
           point = expected.length() - 1;
           assertSameStreams(msg + ", seek(end-1)", expected, actual, point);
  -        
  +
           // seek to the end
           point = expected.length();
           assertSameStreams(msg + ", seek(end)", expected, actual, point);
  -        
  +
           // seek past end
           point = 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 @@
               CompoundFileWriter 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 @@
               csr.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 @@
           assertSameSeekBehavior("d1", expected, actual);
           expected.close();
           actual.close();
  -        
  +
           expected = dir.openFile("d2");
           actual = csr.openFile("d2");
           assertSameStreams("d2", expected, actual);
  @@ -248,7 +302,7 @@
           actual.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 @@
           createRandomFile(dir, segment + ".big5", 3 * chunk - 1);
           createRandomFile(dir, segment + ".big6", 3 * chunk + 1);
           createRandomFile(dir, segment + ".big7", 1000 * chunk);
  -        
  +
           // Setup extraneous files
           createRandomFile(dir, "onetwothree", 100);
           createRandomFile(dir, segment + ".notIn", 50);
  @@ -279,14 +333,14 @@
           // Now test
           CompoundFileWriter 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 @@
           }
           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 @@
           }
           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 @@
               os.writeByte((byte) i);
           }
           os.close();
  -        
  +
           InputStream in = fsdir.openFile(file);
  -        
  +
           // This read primes the buffer in InputStream
           byte b = in.readByte();
  -        
  +
           // Close the file
           in.close();
  -        
  -        // ERROR: this call should fail, but succeeds because the buffer 
  +
  +        // ERROR: this call should fail, but succeeds because the buffer
           // is still filled
           b = in.readByte();
   
           // ERROR: this call should fail, but succeeds for some reason as well
           in.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 fails
               b = 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 clone
           InputStream 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 reader
           cr.close();
           assertFalse("Now closed one", isCSInputStreamOpen(one));
           assertFalse("Now closed two", isCSInputStreamOpen(two));
  -            
  +
           // The following may also fail since the compound stream is closed
           expected.seek(0);
           two.seek(0);
           //assertSameStreams("basic clone two/3", expected, two);
  -            
  -        
  +
  +
           // Now close the second clone
           two.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 void testRandomAccess() throws IOException {
           setUp_2();
           CompoundFileReader cr = new CompoundFileReader(dir, "f.comp");
  -        
  -        // Open two files 
  +
  +        // Open two files
           InputStream 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 pair
           e1.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 pair
           e2.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 move
           assertEquals(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 length
           e1.seek(1910);
           a1.seek(1910);
  @@ -467,14 +521,14 @@
           be1 = e1.readByte();
           ba1 = a1.readByte();
           assertEquals(be1, ba1);
  -        
  +
           // Now make sure the second set didn't move
           assertEquals(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 size
           e2.seek(17);
           a2.seek(17);
  @@ -484,60 +538,60 @@
           ba2 = 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 move
           assertEquals(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 files
           InputStream e1 = cr.openFile("f11");
           InputStream e2 = cr.openFile("f3");
  -        
  +
           InputStream a1 = (InputStream) e1.clone();
           InputStream a2 = (InputStream) e2.clone();
  -        
  +
           // Seek the first pair
           e1.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 pair
           e2.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 move
           assertEquals(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 length
           e1.seek(1910);
           a1.seek(1910);
  @@ -546,14 +600,14 @@
           be1 = e1.readByte();
           ba1 = a1.readByte();
           assertEquals(be1, ba1);
  -        
  +
           // Now make sure the second set didn't move
           assertEquals(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 size
           e2.seek(17);
           a2.seek(17);
  @@ -563,40 +617,40 @@
           ba2 = 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 move
           assertEquals(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 files
           try {
               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 @@
           is.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 @@
               /* 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 @@
               /* 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"));
       }
   }
  
  
  
  1.3       +12 -9     jakarta-lucene/src/test/org/apache/lucene/index/TestIndexWriter.java
  
  Index: TestIndexWriter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/test/org/apache/lucene/index/TestIndexWriter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestIndexWriter.java	15 Sep 2003 12:33:07 -0000	1.2
  +++ TestIndexWriter.java	13 Oct 2003 14:31:38 -0000	1.3
  @@ -37,30 +37,33 @@
               assertEquals(100, writer.docCount());
               writer.close();
   
  -            // delete 50 documents
  +            // delete 40 documents
               reader = 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) {
  
  
  
  1.2       +4 -5      jakarta-lucene/src/test/org/apache/lucene/store/_TestHelper.java
  
  Index: _TestHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/test/org/apache/lucene/store/_TestHelper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- _TestHelper.java	25 Sep 2003 22:01:51 -0000	1.1
  +++ _TestHelper.java	13 Oct 2003 14:31:38 -0000	1.2
  @@ -5,7 +5,6 @@
   /** 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 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 @@
       /** 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 @@
           }
       }
   
  -}
  \ No newline at end of file
  +}
  
  
  
  1.2       +3 -2      jakarta-lucene/src/test/org/apache/lucene/util/TestBitVector.java
  
  Index: TestBitVector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/test/org/apache/lucene/util/TestBitVector.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestBitVector.java	7 Nov 2002 05:17:16 -0000	1.1
  +++ TestBitVector.java	13 Oct 2003 14:31:38 -0000	1.2
  @@ -196,7 +196,8 @@
       }
   
       /**
  -     * 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
        */
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Mime
View raw message