From 55b2ec0716c8d1c96e39f2e84982be18c455dcef Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 5 Feb 2012 09:36:10 +0100 Subject: added -H to make printing headers optional --- .../org/dyndns/andreasbaumann/LuceneAnalyzer.java | 41 +++++++++++++++------- 1 file 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( ); -- cgit v1.2.3-54-g00ecf