lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r762647 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/index/IndexReader.java src/java/org/apache/lucene/index/SegmentReader.java src/test/org/apache/lucene/index/TestIndexReader.java
Date Tue, 07 Apr 2009 08:25:15 GMT
Author: mikemccand
Date: Tue Apr  7 08:25:14 2009
New Revision: 762647

URL: http://svn.apache.org/viewvc?rev=762647&view=rev
Log:
LUCENE-1586: add IndexReader.getUniqueTermCount

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java
    lucene/java/trunk/src/java/org/apache/lucene/index/SegmentReader.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=762647&r1=762646&r2=762647&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Tue Apr  7 08:25:14 2009
@@ -207,6 +207,9 @@
     a specific fields to set the score for a document.  (Karl Wettin
     via Mike McCandless)
 
+19. LUCENE-1586: Add IndexReader.getUniqueTermCount().  (Mike
+    McCandless via Derek)
+
 Optimizations
 
  1. LUCENE-1427: Fixed QueryWrapperFilter to not waste time computing

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java?rev=762647&r1=762646&r2=762647&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java Tue Apr  7 08:25:14
2009
@@ -1254,4 +1254,20 @@
   public Object getFieldCacheKey() {
     return this;
   }
+
+  /** Returns the number of unique terms (across all fields)
+   *  in this reader.
+   *
+   *  This method returns long, even though internally
+   *  Lucene cannot handle more than 2^31 unique terms, for
+   *  a possible future when this limitation is removed.
+   *
+   *  @throws UnsupportedOperationException if this count
+   *  cannot be easily determined (eg Multi*Readers).
+   *  Instead, you should call {@link
+   *  #getSequentialSubReaders} and ask each sub reader for
+   *  its unique term count. */
+  public long getUniqueTermCount() throws IOException {
+    throw new UnsupportedOperationException("this reader does not implement getUniqueTermCount()");
+  }
 }

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/SegmentReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/SegmentReader.java?rev=762647&r1=762646&r2=762647&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/SegmentReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/SegmentReader.java Tue Apr  7 08:25:14
2009
@@ -1257,4 +1257,8 @@
   public final Object getFieldCacheKey() {
     return freqStream;
   }
+
+  public long getUniqueTermCount() {
+    return tis.size();
+  }
 }

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java?rev=762647&r1=762646&r2=762647&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java Tue Apr  7 08:25:14
2009
@@ -1794,4 +1794,36 @@
 
     dir.close();
   }
+
+  // LUCENE-1586: getUniqueTermCount
+  public void testUniqueTermCount() throws Exception {
+    Directory dir = new MockRAMDirectory();
+    IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
+    Document doc = new Document();
+    doc.add(new Field("field", "a b c d e f g h i j k l m n o p q r s t u v w x y z", Field.Store.NO,
Field.Index.ANALYZED));
+    doc.add(new Field("number", "0 1 2 3 4 5 6 7 8 9", Field.Store.NO, Field.Index.ANALYZED));
+    writer.addDocument(doc);
+    writer.addDocument(doc);
+    writer.commit();
+
+    IndexReader r = IndexReader.open(dir);
+    assertEquals(36, r.getUniqueTermCount());
+    writer.addDocument(doc);
+    writer.commit();
+    IndexReader r2 = r.reopen();
+    r.close();
+    try {
+      r2.getUniqueTermCount();
+      fail("expected exception");
+    } catch (UnsupportedOperationException uoe) {
+      // expected
+    }
+    IndexReader[] subs = r2.getSequentialSubReaders();
+    for(int i=0;i<subs.length;i++) {
+      assertEquals(36, subs[i].getUniqueTermCount());
+    }
+    r2.close();
+    writer.close();
+    dir.close();
+  }
 }



Mime
View raw message