LUCENE-1923: further improvements to IndexReader.toString

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@892457 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2009-12-19 10:45:00 +00:00
parent 16eaa6198f
commit 9892d10205
7 changed files with 32 additions and 11 deletions

View File

@ -302,8 +302,17 @@ class DirectoryReader extends IndexReader implements Cloneable {
/** {@inheritDoc} */
@Override
public String toString() {
final SegmentInfos infos = writer != null ? segmentInfosStart : segmentInfos;
return "DirectoryReader(" + infos.toString(directory) + ")";
final StringBuilder buffer = new StringBuilder();
if (hasChanges) {
buffer.append("*");
}
buffer.append(getClass().getSimpleName());
buffer.append('(');
for(SegmentReader r : subReaders) {
buffer.append(r);
}
buffer.append(')');
return buffer.toString();
}
private void initialize(SegmentReader[] subReaders) {

View File

@ -148,13 +148,17 @@ public abstract class IndexReader implements Cloneable,Closeable {
/** {@inheritDoc} */
@Override
public String toString() {
final StringBuilder buffer = new StringBuilder(getClass().getSimpleName());
final StringBuilder buffer = new StringBuilder();
if (hasChanges) {
buffer.append('*');
}
buffer.append(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(" ").append(subReaders[i]);
}
}
buffer.append(')');

View File

@ -4484,7 +4484,7 @@ public class IndexWriter implements Closeable {
buffer.append(' ');
}
final SegmentInfo info = infos.info(i);
buffer.append(info.toString(directory));
buffer.append(info.toString(directory, 0));
if (info.dir != directory)
buffer.append("**");
}

View File

@ -127,7 +127,7 @@ public abstract class MergePolicy implements java.io.Closeable {
final int numSegments = segments.size();
for(int i=0;i<numSegments;i++) {
if (i > 0) b.append(' ');
b.append(segments.info(i).toString(dir));
b.append(segments.info(i).toString(dir, 0));
}
if (info != null)
b.append(" into ").append(info.name);

View File

@ -681,7 +681,7 @@ public final class SegmentInfo {
/** {@inheritDoc} */
@Override
public String toString() {
return toString(dir);
return toString(dir, 0);
}
/** Used for debugging. Format may suddenly change.
@ -695,7 +695,7 @@ public final class SegmentInfo {
* shared doc stores named <code>_1</code> (this part is
* left off if doc stores are private).</p>
*/
public String toString(Directory dir) {
public String toString(Directory dir, int pendingDelCount) {
StringBuilder s = new StringBuilder();
s.append(name).append(':');
@ -723,6 +723,9 @@ public final class SegmentInfo {
} catch (IOException ioe) {
delCount = -1;
}
if (delCount != -1) {
delCount += pendingDelCount;
}
if (delCount != 0) {
s.append('/');
if (delCount == -1) {

View File

@ -876,7 +876,7 @@ public final class SegmentInfos extends Vector<SegmentInfo> {
buffer.append(' ');
}
final SegmentInfo info = info(i);
buffer.append(info.toString(directory));
buffer.append(info.toString(directory, 0));
}
return buffer.toString();
}

View File

@ -682,10 +682,10 @@ public class SegmentReader extends IndexReader implements Cloneable {
clone.readOnly = openReadOnly;
clone.si = si;
clone.readBufferSize = readBufferSize;
clone.pendingDeleteCount = pendingDeleteCount;
if (!openReadOnly && hasChanges) {
// My pending changes transfer to the new reader
clone.pendingDeleteCount = pendingDeleteCount;
clone.deletedDocsDirty = deletedDocsDirty;
clone.normsDirty = normsDirty;
clone.hasChanges = hasChanges;
@ -1201,7 +1201,12 @@ public class SegmentReader extends IndexReader implements Cloneable {
/** {@inheritDoc} */
@Override
public String toString() {
return si.toString();
final StringBuilder buffer = new StringBuilder();
if (hasChanges) {
buffer.append('*');
}
buffer.append(si.toString(core.dir, pendingDeleteCount));
return buffer.toString();
}
/**