diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2012-02-05 09:36:10 +0100 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2012-02-05 09:36:10 +0100 |
commit | 55b2ec0716c8d1c96e39f2e84982be18c455dcef (patch) | |
tree | ac7dc8375c6aee5736773bf0ee3865ed8d474e22 /src/main/java/org/dyndns/andreasbaumann/LuceneAnalyzer.java | |
parent | 5b52d073647c8a895035825fb2a4fa3d788675f3 (diff) | |
download | LuceneAnalyzer-55b2ec0716c8d1c96e39f2e84982be18c455dcef.tar.gz LuceneAnalyzer-55b2ec0716c8d1c96e39f2e84982be18c455dcef.tar.bz2 |
added -H to make printing headers optional
Diffstat (limited to 'src/main/java/org/dyndns/andreasbaumann/LuceneAnalyzer.java')
-rw-r--r-- | src/main/java/org/dyndns/andreasbaumann/LuceneAnalyzer.java | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/src/main/java/org/dyndns/andreasbaumann/LuceneAnalyzer.java b/src/main/java/org/dyndns/andreasbaumann/LuceneAnalyzer.java index 4f37cea..3f5cbdd 100644 --- a/src/main/java/org/dyndns/andreasbaumann/LuceneAnalyzer.java +++ b/src/main/java/org/dyndns/andreasbaumann/LuceneAnalyzer.java @@ -59,11 +59,13 @@ public class LuceneAnalyzer private static final String programName = "lucenanalyzer"; private static final String versionString = "0.0.4"; - private static void printGlobalInfo( IndexReader indexReader ) throws IOException + private static void printGlobalInfo( IndexReader indexReader, boolean printHeaders ) throws IOException { - System.out.println( "Global Information:" ); - System.out.println( "===================" ); - + if( printHeaders ) { + System.out.println( "Global Information:" ); + System.out.println( "===================" ); + } + System.out.println( "\tnumber of documents: " + indexReader.numDocs( ) ); // we should get the number of features differently, this is inefficient, but Lucene @@ -106,10 +108,12 @@ public class LuceneAnalyzer } } - private static void printFieldInfo( IndexReader indexReader ) throws IOException + private static void printFieldInfo( IndexReader indexReader, boolean printHeaders ) throws IOException { - System.out.println( "Field Information:" ); - System.out.println( "==================" ); + if( printHeaders ) { + System.out.println( "Field Information:" ); + System.out.println( "==================" ); + } // print info per Lucene field type printFieldInfoPerFieldOption( indexReader, IndexReader.FieldOption.ALL ); @@ -129,11 +133,14 @@ public class LuceneAnalyzer } private static void printTerms( IndexReader indexReader, + boolean printHeaders, boolean printDocNumbers, - boolean printPositions ) throws IOException + boolean printPositions ) throws IOException { - System.out.println( "Terms:" ); - System.out.println( "======" ); + if( printHeaders ) { + System.out.println( "Terms:" ); + System.out.println( "======" ); + } TermEnum terms = indexReader.terms( ); while( terms.next( ) ) { Term term = terms.term( ); @@ -232,6 +239,8 @@ public class LuceneAnalyzer "print field information" ); Option terms = addHelp( parser.addBooleanOption( 't', "terms" ), "print statistics per term" ); + Option headers = addHelp( parser.addBooleanOption( 'H', "headers" ), + "print headers for sections" ); // read the command line options try { @@ -262,6 +271,12 @@ public class LuceneAnalyzer verbosity++; } } + + boolean printHeaders = false; + if( (Boolean)parser.getOptionValue( headers, Boolean.FALSE ) ) { + printHeaders = true; + } + // read command line arguments String[] otherArgs = parser.getRemainingArgs( ); @@ -286,13 +301,13 @@ public class LuceneAnalyzer IndexReader indexReader = IndexReader.open( luceneDirectory ); if( (Boolean)parser.getOptionValue( globals, Boolean.FALSE ) ) { - printGlobalInfo( indexReader ); + printGlobalInfo( indexReader, printHeaders ); } if( (Boolean)parser.getOptionValue( fields, Boolean.FALSE ) ) { - printFieldInfo( indexReader ); + printFieldInfo( indexReader, printHeaders ); } if( (Boolean)parser.getOptionValue( terms, Boolean.FALSE ) ) { - printTerms( indexReader, verbosity == 1, verbosity >= 2 ); + printTerms( indexReader, printHeaders, verbosity == 1, verbosity >= 2 ); } indexReader.close( ); |