lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r912672 - /lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java
Date Mon, 22 Feb 2010 17:28:27 GMT
Author: mikemccand
Date: Mon Feb 22 17:28:26 2010
New Revision: 912672

URL: http://svn.apache.org/viewvc?rev=912672&view=rev
Log:
LUCENE-2275: don't get TermDocs/IndexSearcher when applying deletes unless we actually have
terms & queries to delete

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java?rev=912672&r1=912671&r2=912672&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java Mon Feb 22 17:28:26
2010
@@ -986,25 +986,27 @@
     assert checkDeleteTerm(null);
 
     // Delete by term
-    TermDocs docs = reader.termDocs();
-    try {
-      for (Entry<Term, BufferedDeletes.Num> entry: deletesFlushed.terms.entrySet())
{
-        Term term = entry.getKey();
-        // LUCENE-2086: we should be iterating a TreeMap,
-        // here, so terms better be in order:
-        assert checkDeleteTerm(term);
-        docs.seek(term);
-        int limit = entry.getValue().getNum();
-        while (docs.next()) {
-          int docID = docs.doc();
-          if (docIDStart+docID >= limit)
-            break;
-          reader.deleteDocument(docID);
-          any = true;
+    if (deletesFlushed.terms.size() > 0) {
+      TermDocs docs = reader.termDocs();
+      try {
+        for (Entry<Term, BufferedDeletes.Num> entry: deletesFlushed.terms.entrySet())
{
+          Term term = entry.getKey();
+          // LUCENE-2086: we should be iterating a TreeMap,
+          // here, so terms better be in order:
+          assert checkDeleteTerm(term);
+          docs.seek(term);
+          int limit = entry.getValue().getNum();
+          while (docs.next()) {
+            int docID = docs.doc();
+            if (docIDStart+docID >= limit)
+              break;
+            reader.deleteDocument(docID);
+            any = true;
+          }
         }
+      } finally {
+        docs.close();
       }
-    } finally {
-      docs.close();
     }
 
     // Delete by docID
@@ -1017,23 +1019,28 @@
     }
 
     // Delete by query
-    IndexSearcher searcher = new IndexSearcher(reader);
-    for (Entry<Query, Integer> entry : deletesFlushed.queries.entrySet()) {
-      Query query = entry.getKey();
-      int limit = entry.getValue().intValue();
-      Weight weight = query.weight(searcher);
-      Scorer scorer = weight.scorer(reader, true, false);
-      if (scorer != null) {
-        while(true)  {
-          int doc = scorer.nextDoc();
-          if (((long) docIDStart) + doc >= limit)
-            break;
-          reader.deleteDocument(doc);
-          any = true;
+    if (deletesFlushed.queries.size() > 0) {
+      IndexSearcher searcher = new IndexSearcher(reader);
+      try {
+        for (Entry<Query, Integer> entry : deletesFlushed.queries.entrySet()) {
+          Query query = entry.getKey();
+          int limit = entry.getValue().intValue();
+          Weight weight = query.weight(searcher);
+          Scorer scorer = weight.scorer(reader, true, false);
+          if (scorer != null) {
+            while(true)  {
+              int doc = scorer.nextDoc();
+              if (((long) docIDStart) + doc >= limit)
+                break;
+              reader.deleteDocument(doc);
+              any = true;
+            }
+          }
         }
+      } finally {
+        searcher.close();
       }
     }
-    searcher.close();
     return any;
   }
 



Mime
View raw message