lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r892224 - in /lucene/java/trunk: ./ src/java/org/apache/lucene/index/
Date Fri, 18 Dec 2009 11:29:57 GMT
Author: mikemccand
Date: Fri Dec 18 11:29:57 2009
New Revision: 892224

URL: http://svn.apache.org/viewvc?rev=892224&view=rev
Log:
LUCENE-1923: add toString to core IndexReaders

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/index/DirectoryReader.java
    lucene/java/trunk/src/java/org/apache/lucene/index/FilterIndexReader.java
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/java/trunk/src/java/org/apache/lucene/index/MergePolicy.java
    lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.java
    lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfo.java
    lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java
    lucene/java/trunk/src/java/org/apache/lucene/index/SegmentReader.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=892224&r1=892223&r2=892224&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Fri Dec 18 11:29:57 2009
@@ -16,8 +16,15 @@
   interface.  Anyone implementing FieldCache externally will need to
   fix their code to implement this, on upgrading.  (Mike McCandless)
 
+* LUCENE-1923: Renamed SegmentInfo & SegmentInfos segString method to
+  toString.  These are advanced APIs and subject to change suddenly.
+  (Tim Smith via Mike McCandless)
+
 Changes in runtime behavior
 
+* LUCENE-1923: Made IndexReader.toString() produce something
+  meaningful (Tim Smith via Mike McCandless)
+
 API Changes
 
 * LUCENE-2076: Rename FSDirectory.getFile -> getDirectory.  (George

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=892224&r1=892223&r2=892224&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 Fri Dec 18 11:29:57
2009
@@ -299,6 +299,13 @@
     }
   }
 
+  /** {@inheritDoc} */
+  @Override
+  public String toString() {
+    final SegmentInfos infos = writer != null ? segmentInfosStart : segmentInfos;
+    return "DirectoryReader(" + infos.toString(directory) + ")";
+  }
+
   private void initialize(SegmentReader[] subReaders) {
     this.subReaders = subReaders;
     starts = new int[subReaders.length + 1];    // build starts array

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/FilterIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/FilterIndexReader.java?rev=892224&r1=892223&r2=892224&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/FilterIndexReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/FilterIndexReader.java Fri Dec 18 11:29:57
2009
@@ -288,4 +288,13 @@
   public Object getFieldCacheKey() {
     return in.getFieldCacheKey();
   }
+
+  /** {@inheritDoc} */
+  @Override
+  public String toString() {
+    final StringBuilder buffer = new StringBuilder("FilterReader(");
+    buffer.append(in);
+    buffer.append(')');
+    return buffer.toString();
+  }
 }

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=892224&r1=892223&r2=892224&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 Fri Dec 18 11:29:57
2009
@@ -145,6 +145,22 @@
     refCount.incrementAndGet();
   }
 
+  /** {@inheritDoc} */
+  @Override
+  public String toString() {
+    final StringBuilder buffer = new StringBuilder(getClass().getSimpleName());
+    buffer.append('(');
+    final IndexReader[] subReaders = getSequentialSubReaders();
+    if ((subReaders != null) && (subReaders.length > 0)) {
+      buffer.append(subReaders[0]);
+      for (int i = 1; i < subReaders.length; ++i) {
+        buffer.append(", ").append(subReaders[i]);
+      }
+    }
+    buffer.append(')');
+    return buffer.toString();
+  }
+
   /**
    * Expert: decreases the refCount of this IndexReader
    * instance.  If the refCount drops to 0, then pending

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?rev=892224&r1=892223&r2=892224&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java Fri Dec 18 11:29:57
2009
@@ -4484,7 +4484,7 @@
         buffer.append(' ');
       }
       final SegmentInfo info = infos.info(i);
-      buffer.append(info.segString(directory));
+      buffer.append(info.toString(directory));
       if (info.dir != directory)
         buffer.append("**");
     }

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/MergePolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/MergePolicy.java?rev=892224&r1=892223&r2=892224&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/MergePolicy.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/MergePolicy.java Fri Dec 18 11:29:57
2009
@@ -127,7 +127,7 @@
       final int numSegments = segments.size();
       for(int i=0;i<numSegments;i++) {
         if (i > 0) b.append(' ');
-        b.append(segments.info(i).segString(dir));
+        b.append(segments.info(i).toString(dir));
       }
       if (info != null)
         b.append(" into ").append(info.name);

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.java?rev=892224&r1=892223&r2=892224&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.java Fri Dec 18 11:29:57
2009
@@ -70,6 +70,21 @@
     this.incRefReaders = !closeSubReaders;
   }
 
+  /** {@inheritDoc} */
+  @Override
+  public String toString() {
+    final StringBuilder buffer = new StringBuilder("ParallelReader(");
+    final Iterator<IndexReader> iter = readers.iterator();
+    if (iter.hasNext()) {
+      buffer.append(iter.next());
+    }
+    while (iter.hasNext()) {
+      buffer.append(", ").append(iter.next());
+    }
+    buffer.append(')');
+    return buffer.toString();
+  }
+
  /** Add an IndexReader.
   * @throws IOException if there is a low-level IO error
   */

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfo.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfo.java?rev=892224&r1=892223&r2=892224&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfo.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfo.java Fri Dec 18 11:29:57
2009
@@ -91,11 +91,6 @@
 
   private Map<String,String> diagnostics;
 
-  @Override
-  public String toString() {
-    return "si: "+dir.toString()+" "+name+" docCount: "+docCount+" delCount: "+delCount+"
delFileName: "+getDelFileName();
-  }
-  
   public SegmentInfo(String name, int docCount, Directory dir) {
     this.name = name;
     this.docCount = docCount;
@@ -683,29 +678,65 @@
     sizeInBytes = -1;
   }
 
-  /** Used for debugging */
-  public String segString(Directory dir) {
-    String cfs;
+  /** {@inheritDoc} */
+  @Override
+  public String toString() {
+    return toString(dir);
+  }
+
+  /** Used for debugging.  Format may suddenly change.
+   * 
+   *  <p>Current format looks like
+   *  <code>_a:c45/4->_1</code>, which means the segment's
+   *  name is <code>_a</code>; it's using compound file
+   *  format (would be <code>C</code> if not compound); it
+   *  has 45 documents; it has 4 deletions (this part is
+   *  left off when there are no deletions); it's using the
+   *  shared doc stores named <code>_1</code> (this part is
+   *  left off if doc stores are private).</p>
+   */
+  public String toString(Directory dir) {
+
+    StringBuilder s = new StringBuilder();
+    s.append(name).append(':');
+
+    char cfs;
     try {
-      if (getUseCompoundFile())
-        cfs = "c";
-      else
-        cfs = "C";
+      if (getUseCompoundFile()) {
+        cfs = 'c';
+      } else {
+        cfs = 'C';
+      }
     } catch (IOException ioe) {
-      cfs = "?";
+      cfs = '?';
     }
+    s.append(cfs);
 
-    String docStore;
+    if (this.dir != dir) {
+      s.append('x');
+    }
+    s.append(docCount);
 
-    if (docStoreOffset != -1)
-      docStore = "->" + docStoreSegment;
-    else
-      docStore = "";
+    int delCount;
+    try {
+      delCount = getDelCount();
+    } catch (IOException ioe) {
+      delCount = -1;
+    }
+    if (delCount != 0) {
+      s.append('/');
+      if (delCount == -1) {
+        s.append('?');
+      } else {
+        s.append(delCount);
+      }
+    }
+    
+    if (docStoreOffset != -1) {
+      s.append("->").append(docStoreSegment);
+    }
 
-    return name + ":" +
-      cfs +
-      (this.dir == dir ? "" : "x") +
-      docCount + docStore;
+    return s.toString();
   }
 
   /** We consider another SegmentInfo instance equal if it

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java?rev=892224&r1=892223&r2=892224&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java Fri Dec 18 11:29:57
2009
@@ -867,17 +867,16 @@
     finishCommit(dir);
   }
 
-  public synchronized String segString(Directory directory) {
+  public synchronized String toString(Directory directory) {
     StringBuilder buffer = new StringBuilder();
+    buffer.append(getCurrentSegmentFileName()).append(": ");
     final int count = size();
     for(int i = 0; i < count; i++) {
       if (i > 0) {
         buffer.append(' ');
       }
       final SegmentInfo info = info(i);
-      buffer.append(info.segString(directory));
-      if (info.dir != directory)
-        buffer.append("**");
+      buffer.append(info.toString(directory));
     }
     return buffer.toString();
   }

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=892224&r1=892223&r2=892224&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 Fri Dec 18 11:29:57
2009
@@ -1198,6 +1198,12 @@
     return termVectorsReader.get(docNumber);
   }
   
+  /** {@inheritDoc} */
+  @Override
+  public String toString() {
+    return si.toString();
+  }
+
   /**
    * Return the name of the segment this reader is reading.
    */



Mime
View raw message