lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r888398 - in /lucene/java/trunk: CHANGES.txt contrib/regex/src/test/org/apache/lucene/search/regex/TestRegexQuery.java src/java/org/apache/lucene/index/DirectoryReader.java src/java/org/apache/lucene/index/MultiReader.java
Date Tue, 08 Dec 2009 13:47:20 GMT
Author: mikemccand
Date: Tue Dec  8 13:47:20 2009
New Revision: 888398

URL: http://svn.apache.org/viewvc?rev=888398&view=rev
Log:
LUCENE-2136: optimization: if Multi/DirectoryReader only has a single reader, delegate enums
to it

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/contrib/regex/src/test/org/apache/lucene/search/regex/TestRegexQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/index/DirectoryReader.java
    lucene/java/trunk/src/java/org/apache/lucene/index/MultiReader.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=888398&r1=888397&r2=888398&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Tue Dec  8 13:47:20 2009
@@ -70,6 +70,11 @@
   lots of seeking (Mike McCandless, Uwe Schindler, Robert Muir, Yonik
   Seeley)
 
+* LUCENE-2136: If the multi reader (DirectoryReader or MultiReader)
+  only has a single sub-reader, delegate all enum requests to it.
+  This avoid the overhead of using a PQ unecessarily.  (Mike
+  McCandless)
+
 Build
 
 Test Cases

Modified: lucene/java/trunk/contrib/regex/src/test/org/apache/lucene/search/regex/TestRegexQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/regex/src/test/org/apache/lucene/search/regex/TestRegexQuery.java?rev=888398&r1=888397&r2=888398&view=diff
==============================================================================
--- lucene/java/trunk/contrib/regex/src/test/org/apache/lucene/search/regex/TestRegexQuery.java
(original)
+++ lucene/java/trunk/contrib/regex/src/test/org/apache/lucene/search/regex/TestRegexQuery.java
Tue Dec  8 13:47:20 2009
@@ -83,7 +83,6 @@
   public void testMatchAll() throws Exception {
     TermEnum terms = new RegexQuery(new Term(FN, "jum.")).getEnum(searcher.getIndexReader());
     // no term should match
-    assertNull(terms.term());
     assertFalse(terms.next());
   }
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/DirectoryReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/DirectoryReader.java?rev=888398&r1=888397&r2=888398&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/DirectoryReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/DirectoryReader.java Tue Dec  8 13:47:20
2009
@@ -627,13 +627,23 @@
   @Override
   public TermEnum terms() throws IOException {
     ensureOpen();
-    return new MultiTermEnum(this, subReaders, starts, null);
+    if (subReaders.length == 1) {
+      // Optimize single segment case:
+      return subReaders[0].terms();
+    } else {
+      return new MultiTermEnum(this, subReaders, starts, null);
+    }
   }
 
   @Override
   public TermEnum terms(Term term) throws IOException {
     ensureOpen();
-    return new MultiTermEnum(this, subReaders, starts, term);
+    if (subReaders.length == 1) {
+      // Optimize single segment case:
+      return subReaders[0].terms(term);
+    } else {
+      return new MultiTermEnum(this, subReaders, starts, term);
+    }
   }
 
   @Override
@@ -648,13 +658,34 @@
   @Override
   public TermDocs termDocs() throws IOException {
     ensureOpen();
-    return new MultiTermDocs(this, subReaders, starts);
+    if (subReaders.length == 1) {
+      // Optimize single segment case:
+      return subReaders[0].termDocs();
+    } else {
+      return new MultiTermDocs(this, subReaders, starts);
+    }
+  }
+
+  @Override
+  public TermDocs termDocs(Term term) throws IOException {
+    ensureOpen();
+    if (subReaders.length == 1) {
+      // Optimize single segment case:
+      return subReaders[0].termDocs(term);
+    } else {
+      return super.termDocs(term);
+    }
   }
 
   @Override
   public TermPositions termPositions() throws IOException {
     ensureOpen();
-    return new MultiTermPositions(this, subReaders, starts);
+    if (subReaders.length == 1) {
+      // Optimize single segment case:
+      return subReaders[0].termPositions();
+    } else {
+      return new MultiTermPositions(this, subReaders, starts);
+    }
   }
 
   /**

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/MultiReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/MultiReader.java?rev=888398&r1=888397&r2=888398&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/MultiReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/MultiReader.java Tue Dec  8 13:47:20
2009
@@ -339,13 +339,23 @@
   @Override
   public TermEnum terms() throws IOException {
     ensureOpen();
-    return new MultiTermEnum(this, subReaders, starts, null);
+    if (subReaders.length == 1) {
+      // Optimize single segment case:
+      return subReaders[0].terms();
+    } else {
+      return new MultiTermEnum(this, subReaders, starts, null);
+    }
   }
 
   @Override
   public TermEnum terms(Term term) throws IOException {
     ensureOpen();
-    return new MultiTermEnum(this, subReaders, starts, term);
+    if (subReaders.length == 1) {
+      // Optimize single segment case:
+      return subReaders[0].terms(term);
+    } else {
+      return new MultiTermEnum(this, subReaders, starts, term);
+    }
   }
 
   @Override
@@ -360,13 +370,34 @@
   @Override
   public TermDocs termDocs() throws IOException {
     ensureOpen();
-    return new MultiTermDocs(this, subReaders, starts);
+    if (subReaders.length == 1) {
+      // Optimize single segment case:
+      return subReaders[0].termDocs();
+    } else {
+      return new MultiTermDocs(this, subReaders, starts);
+    }
+  }
+
+  @Override
+  public TermDocs termDocs(Term term) throws IOException {
+    ensureOpen();
+    if (subReaders.length == 1) {
+      // Optimize single segment case:
+      return subReaders[0].termDocs(term);
+    } else {
+      return super.termDocs(term);
+    }
   }
 
   @Override
   public TermPositions termPositions() throws IOException {
     ensureOpen();
-    return new MultiTermPositions(this, subReaders, starts);
+    if (subReaders.length == 1) {
+      // Optimize single segment case:
+      return subReaders[0].termPositions();
+    } else {
+      return new MultiTermPositions(this, subReaders, starts);
+    }
   }
 
   @Override



Mime
View raw message