lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r555793 - in /lucene/java/trunk/src: java/org/apache/lucene/index/IndexWriter.java test/org/apache/lucene/index/TestIndexWriter.java
Date Thu, 12 Jul 2007 22:15:21 GMT
Author: mikemccand
Date: Thu Jul 12 15:15:20 2007
New Revision: 555793

URL: http://svn.apache.org/viewvc?view=rev&rev=555793
Log:
LUCENE-843: fixed the triggerMerger logic from LUCENE-887 that I accidentally lost

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java?view=diff&rev=555793&r1=555792&r2=555793
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java Thu Jul 12 15:15:20
2007
@@ -1828,10 +1828,6 @@
       flush(true, false);
   }
 
-  public final synchronized void flush() throws CorruptIndexException, IOException {  
-    flush(true, false);
-  }
-
   /**
    * Flush all in-memory buffered updates (adds and deletes)
    * to the Directory. 
@@ -1840,7 +1836,19 @@
    * @throws CorruptIndexException if the index is corrupt
    * @throws IOException if there is a low-level IO error
    */
-  public final synchronized void flush(boolean triggerMerge, boolean flushDocStores) throws
CorruptIndexException, IOException {
+  public final synchronized void flush() throws CorruptIndexException, IOException {  
+    flush(true, false);
+  }
+
+  /**
+   * Flush all in-memory buffered udpates (adds and deletes)
+   * to the Directory.
+   * @param triggerMerge if true, we may merge segments (if
+   *  deletes or docs were flushed) if necessary
+   * @param flushDocStores if false we are allowed to keep
+   *  doc stores open to share with the next segment
+   */
+  protected final synchronized void flush(boolean triggerMerge, boolean flushDocStores) throws
CorruptIndexException, IOException {
     ensureOpen();
 
     // Make sure no threads are actively adding a document
@@ -1986,7 +1994,8 @@
         else
           maybeMergeSegments(docWriter.getMaxBufferedDocs());
         */
-        maybeMergeSegments(docWriter.getMaxBufferedDocs());
+        if (triggerMerge)
+          maybeMergeSegments(docWriter.getMaxBufferedDocs());
       }
     } finally {
       docWriter.clearFlushPending();

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java?view=diff&rev=555793&r1=555792&r2=555793
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java Thu Jul 12 15:15:20
2007
@@ -1293,6 +1293,23 @@
       dir.close();
     }
 
+    public void testFlushWithNoMerging() throws IOException {
+      Directory dir = new RAMDirectory();
+      IndexWriter writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);      
+      writer.setMaxBufferedDocs(2);
+      Document doc = new Document();
+      doc.add(new Field("field", "aaa", Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
+      for(int i=0;i<19;i++)
+        writer.addDocument(doc);
+      writer.flush(false, true);
+      writer.close();
+      SegmentInfos sis = new SegmentInfos();
+      sis.read(dir);
+      // Since we flushed w/o allowing merging we should now
+      // have 10 segments
+      assert sis.size() == 10;
+    }
+
     // Make sure we can flush segment w/ norms, then add
     // empty doc (no norms) and flush
     public void testEmptyDocAfterFlushingRealDoc() throws IOException {



Mime
View raw message