From 2dc4a8ff64314e744d766782ec64752a2c0a867d Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 5 Feb 2012 14:21:35 +0100 Subject: first SolR field type (boolean) gets mapped --- .../org/dyndns/andreasbaumann/LuceneAnalyzer.java | 33 ++++++++++++++++------ 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'src/main/java/org/dyndns/andreasbaumann/LuceneAnalyzer.java') diff --git a/src/main/java/org/dyndns/andreasbaumann/LuceneAnalyzer.java b/src/main/java/org/dyndns/andreasbaumann/LuceneAnalyzer.java index fb84cf2..bc1a66a 100644 --- a/src/main/java/org/dyndns/andreasbaumann/LuceneAnalyzer.java +++ b/src/main/java/org/dyndns/andreasbaumann/LuceneAnalyzer.java @@ -55,6 +55,8 @@ import org.apache.solr.schema.IndexSchema; import org.apache.solr.search.SolrIndexSearcher; import javax.xml.parsers.ParserConfigurationException; import org.xml.sax.SAXException; +import org.apache.solr.schema.SchemaField; +import org.apache.solr.schema.FieldType; /** * Lucene index analyzer. Works for file system indexes only (not @@ -72,7 +74,8 @@ public class LuceneAnalyzer private static final String programName = "lucenanalyzer"; private static final String versionString = "0.0.4"; - private static void printGlobalInfo( IndexReader indexReader, boolean printHeaders ) throws IOException + private static void printGlobalInfo( IndexReader indexReader, boolean printHeaders, + boolean isSolr, SolrIndexSearcher solrSearch ) throws IOException { if( printHeaders ) { System.out.println( "Global Information:" ); @@ -104,6 +107,10 @@ public class LuceneAnalyzer System.out.println( "\tmaximal document number: " + indexReader.maxDoc( ) ); System.out.println( "\thas deletions: " + indexReader.hasDeletions( ) ); + if( isSolr ) { + System.out.println( "\tSolr version: " + solrSearch.getVersion( ) ); + } + System.out.println( "" ); } @@ -121,7 +128,8 @@ public class LuceneAnalyzer } } - private static void printFieldInfo( IndexReader indexReader, boolean printHeaders ) throws IOException + private static void printFieldInfo( IndexReader indexReader, boolean printHeaders, + boolean isSolr, SolrIndexSearcher solrSearch ) throws IOException { if( printHeaders ) { System.out.println( "Field Information:" ); @@ -147,6 +155,7 @@ public class LuceneAnalyzer private static void printTerms( IndexReader indexReader, boolean printHeaders, + boolean isSolr, SolrIndexSearcher solrSearch, boolean printDocNumbers, boolean printPositions ) throws IOException { @@ -159,10 +168,18 @@ public class LuceneAnalyzer Term term = terms.term( ); // the df is stored in the iterator and not in the term, weird... int df = terms.docFreq( ); + String field = term.field( ); + String text = term.text( ); + if( isSolr ) { + IndexSchema schema = solrSearch.getSchema( ); + SchemaField schemaField = schema.getField( field ); + FieldType fieldType = schemaField.getType( ); + text = fieldType.indexedToReadable( text ); + } if( !printDocNumbers && !printPositions ) { - System.out.print( term.field( ) + "\t" + term.text( ) + "\t" + df ); + System.out.print( field + "\t" + text + "\t" + df ); } else { - System.out.print( term.field( ) + "\t" + term.text( ) ); + System.out.print( field + "\t" + text ); } if( printDocNumbers ) { @@ -321,7 +338,7 @@ public class LuceneAnalyzer System.exit( 1 ); } - SolrIndexSearcher solrSearcher; + SolrIndexSearcher solrSearcher = null; Directory luceneDirectory = new SimpleFSDirectory( indexDir ); IndexReader indexReader = IndexReader.open( luceneDirectory ); if( isSolr ) { @@ -349,13 +366,13 @@ public class LuceneAnalyzer } if( (Boolean)parser.getOptionValue( globals, Boolean.FALSE ) ) { - printGlobalInfo( indexReader, printHeaders ); + printGlobalInfo( indexReader, printHeaders, isSolr, solrSearcher ); } if( (Boolean)parser.getOptionValue( fields, Boolean.FALSE ) ) { - printFieldInfo( indexReader, printHeaders ); + printFieldInfo( indexReader, printHeaders, isSolr, solrSearcher ); } if( (Boolean)parser.getOptionValue( terms, Boolean.FALSE ) ) { - printTerms( indexReader, printHeaders, verbosity == 1, verbosity >= 2 ); + printTerms( indexReader, printHeaders, isSolr, solrSearcher, verbosity == 1, verbosity >= 2 ); } indexReader.close( ); -- cgit v1.2.3-54-g00ecf