Skip to content

Commit

Permalink
pretty print info cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
John Wang committed Mar 3, 2014
1 parent bb1d283 commit 4b26672
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions src/main/java/com/senseidb/clue/commands/InfoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.TreeMap;

import org.apache.lucene.index.AtomicReader;
import org.apache.lucene.index.AtomicReaderContext;
Expand Down Expand Up @@ -37,25 +36,26 @@ public String help() {
}

@SuppressWarnings("unchecked")
private static String toString(Object[] info) throws IOException {
private static void toString(Object[] info, PrintStream out) throws IOException {
FieldInfo finfo = (FieldInfo) info[0];
List<Terms> termList = (List<Terms>) info[1];
TreeMap<String, String> valMap = new TreeMap<String, String>();
valMap.put("name", finfo.name);
valMap.put("docval", String.valueOf(finfo.hasDocValues()));
valMap.put("norms", String.valueOf(finfo.hasNorms()));
valMap.put("payloads", String.valueOf(finfo.hasPayloads()));
valMap.put("vectors", String.valueOf(finfo.hasVectors()));
valMap.put("attributes", finfo.attributes().toString());
out.println("name:\t" + finfo.name);
out.println("norms:\t" + String.valueOf(finfo.hasNorms()));
out.println("payloads:\t" + String.valueOf(finfo.hasPayloads()));
out.println("docval:\t" + String.valueOf(finfo.hasDocValues()));
IndexOptions indexOptions = finfo.getIndexOptions();
if (indexOptions != null) {
valMap.put("index-options", finfo.getIndexOptions().name());
out.println("index_options:\t" + finfo.getIndexOptions().name());
}

out.println("vectors:\t" + String.valueOf(finfo.hasVectors()));
out.println("attributes:\t" + finfo.attributes().toString());

if (finfo.hasNorms()) {
valMap.put("norm_type", String.valueOf(finfo.getNormType()));
out.println("norm_type:\t" + String.valueOf(finfo.getNormType()));
}
if (finfo.hasDocValues()) {
valMap.put("docval_type", String.valueOf(finfo.getDocValuesType()));
out.println("docval_type:\t" + String.valueOf(finfo.getDocValuesType()));
} else {

if (termList != null) {
Expand Down Expand Up @@ -85,14 +85,12 @@ private static String toString(Object[] info) throws IOException {
if (sumTotalTermFreq < 0) {
sumTotalTermFreq = -1;
}
valMap.put("num_terms", String.valueOf(numTerms));
valMap.put("doc_count", String.valueOf(docCount));
valMap.put("sum_doc_freq", String.valueOf(sumDocFreq));
valMap.put("sum_total_term_freq", String.valueOf(sumTotalTermFreq));
out.println("num_terms:\t" + String.valueOf(numTerms));
out.println("doc_count:\t" + String.valueOf(docCount));
out.println("sum_doc_freq:\t" + String.valueOf(sumDocFreq));
out.println("sum_total_term_freq:\t" + String.valueOf(sumTotalTermFreq));
}
}

return valMap.toString();
}

@Override
Expand Down Expand Up @@ -133,8 +131,11 @@ public void execute(String[] args, PrintStream out) throws Exception {
}
}
out.println("number of fields: " + fields.size());

for (Object[] finfo : fields.values()) {
out.println(toString(finfo));
FieldInfo f = (FieldInfo) finfo[0];
out.println("=================================== Field "+f.name+" ===================================");
toString(finfo, out);
}
} else {
int segid;
Expand All @@ -153,10 +154,10 @@ public void execute(String[] args, PrintStream out) throws Exception {
AtomicReader atomicReader = leaf.reader();

out.println("segment " + segid + ": ");
out.println("doc base: " + leaf.docBase);
out.println("numdocs: " + atomicReader.numDocs());
out.println("maxdoc: " + atomicReader.maxDoc());
out.println("num deleted docs: " + atomicReader.numDeletedDocs());
out.println("doc base:\t" + leaf.docBase);
out.println("numdocs:\t" + atomicReader.numDocs());
out.println("maxdoc:\t" + atomicReader.maxDoc());
out.println("num deleted docs:\t" + atomicReader.numDeletedDocs());

FieldInfos fields = atomicReader.getFieldInfos();
Fields flds = atomicReader.fields();
Expand All @@ -166,7 +167,8 @@ public void execute(String[] args, PrintStream out) throws Exception {
for (int i = 0; i < fields.size(); ++i) {
FieldInfo finfo = fields.fieldInfo(i);
Terms te = flds.terms(finfo.name);
out.println(toString(new Object[] { finfo, Arrays.asList(te) }));
out.println("=================================== Field "+finfo.name+" ===================================");
toString(new Object[] { finfo, Arrays.asList(te) }, out);
}
}

Expand Down

0 comments on commit 4b26672

Please sign in to comment.