LUCENE-1923: add toString to core IndexReaders

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@892224 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2009-12-18 11:29:57 +00:00
parent c9ddd1b9fd
commit a1e956a41d
10 changed files with 120 additions and 30 deletions

View File

@ -16,8 +16,15 @@ Changes in backwards compatibility policy
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

View File

@ -299,6 +299,13 @@ class DirectoryReader extends IndexReader implements Cloneable {
}
}
/** {@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

View File

@ -288,4 +288,13 @@ public class FilterIndexReader extends IndexReader {
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();
}
}

View File

@ -145,6 +145,22 @@ public abstract class IndexReader implements Cloneable,Closeable {
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

View File

@ -4484,7 +4484,7 @@ public class IndexWriter implements Closeable {
buffer.append(' ');
}
final SegmentInfo info = infos.info(i);
buffer.append(info.segString(directory));
buffer.append(info.toString(directory));
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).segString(dir));
b.append(segments.info(i).toString(dir));
}
if (info != null)
b.append(" into ").append(info.name);

View File

@ -70,6 +70,21 @@ public class ParallelReader extends IndexReader {
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
*/

View File

@ -91,11 +91,6 @@ public final class SegmentInfo {
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 @@ public final class SegmentInfo {
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);
if (this.dir != dir) {
s.append('x');
}
s.append(docCount);
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);
}
String docStore;
if (docStoreOffset != -1)
docStore = "->" + docStoreSegment;
else
docStore = "";
return name + ":" +
cfs +
(this.dir == dir ? "" : "x") +
docCount + docStore;
return s.toString();
}
/** We consider another SegmentInfo instance equal if it

View File

@ -867,17 +867,16 @@ public final class SegmentInfos extends Vector<SegmentInfo> {
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();
}

View File

@ -1198,6 +1198,12 @@ public class SegmentReader extends IndexReader implements Cloneable {
return termVectorsReader.get(docNumber);
}
/** {@inheritDoc} */
@Override
public String toString() {
return si.toString();
}
/**
* Return the name of the segment this reader is reading.
*/