summaryrefslogtreecommitdiff
path: root/src/main/java/org/dyndns/andreasbaumann/LuceneAnalyzer.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/dyndns/andreasbaumann/LuceneAnalyzer.java')
-rw-r--r--src/main/java/org/dyndns/andreasbaumann/LuceneAnalyzer.java58
1 files changed, 53 insertions, 5 deletions
diff --git a/src/main/java/org/dyndns/andreasbaumann/LuceneAnalyzer.java b/src/main/java/org/dyndns/andreasbaumann/LuceneAnalyzer.java
index 3f5cbdd..1467f1e 100644
--- a/src/main/java/org/dyndns/andreasbaumann/LuceneAnalyzer.java
+++ b/src/main/java/org/dyndns/andreasbaumann/LuceneAnalyzer.java
@@ -26,6 +26,7 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.List;
+import java.util.Properties;
import jargs.gnu.CmdLineParser;
import jargs.gnu.CmdLineParser.Option;
@@ -43,6 +44,18 @@ import org.apache.lucene.index.TermPositions;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
+import java.util.logging.LogManager;
+import java.util.logging.Logger;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.CoreDescriptor;
+import org.apache.solr.core.SolrResourceLoader;
+import org.apache.solr.core.SolrConfig;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.schema.IndexSchema;
+import org.apache.solr.search.SolrIndexSearcher;
+import javax.xml.parsers.ParserConfigurationException;
+import org.xml.sax.SAXException;
+
/**
* Lucene index analyzer. Works for file system indexes only (not
* for indexes fully in RAM or in different persistence systems as
@@ -241,6 +254,8 @@ public class LuceneAnalyzer
"print statistics per term" );
Option headers = addHelp( parser.addBooleanOption( 'H', "headers" ),
"print headers for sections" );
+ Option solr = addHelp( parser.addBooleanOption( 's', "solr" ),
+ "treat index as a Solr index, indexDir is the Solr base dir" );
// read the command line options
try {
@@ -277,6 +292,10 @@ public class LuceneAnalyzer
printHeaders = true;
}
+ boolean isSolr = false;
+ if( (Boolean)parser.getOptionValue( solr, Boolean.FALSE ) ) {
+ isSolr = true;
+ }
// read command line arguments
String[] otherArgs = parser.getRemainingArgs( );
@@ -287,19 +306,48 @@ public class LuceneAnalyzer
System.exit( 1 );
}
- File indexDir = new File( otherArgs[0] );
+ String basePath = otherArgs[0];
+ String indexPath = otherArgs[0];
+ if( isSolr ) {
+ indexPath += "/data/index";
+ }
+ File indexDir = new File( indexPath );
if( !indexDir.exists( ) ) {
- System.err.println( indexDir + " doesn't exist" );
+ System.err.println( indexPath + " doesn't exist" );
System.exit( 1 );
}
if( !indexDir.isDirectory( ) ) {
- System.err.println( indexDir + " is not a directory" );
+ System.err.println( indexPath + " is not a directory" );
System.exit( 1 );
}
-
+
+ SolrIndexSearcher solrSearcher;
Directory luceneDirectory = new SimpleFSDirectory( indexDir );
IndexReader indexReader = IndexReader.open( luceneDirectory );
-
+ if( isSolr ) {
+ try {
+ Properties p = System.getProperties( );
+ p.setProperty( "solr.solr.home", basePath );
+ LogManager.getLogManager( ).reset( );
+ Logger globalLogger = Logger.getLogger( java.util.logging.Logger.GLOBAL_LOGGER_NAME );
+ globalLogger.setLevel( java.util.logging.Level.OFF );
+
+ CoreContainer cores = new CoreContainer( new SolrResourceLoader( basePath ) );
+ SolrConfig solrConfig = new SolrConfig( basePath, SolrConfig.DEFAULT_CONF_FILE, null );
+ CoreDescriptor descrCore = new CoreDescriptor( cores, "", solrConfig.getResourceLoader( ).getInstanceDir( ) );
+ IndexSchema solrSchema = new IndexSchema( solrConfig, basePath + "/conf/schema.xml", null );
+ SolrCore solrCore = new SolrCore( basePath, solrSchema );
+ solrSearcher = new SolrIndexSearcher( solrCore, solrSchema, "test",
+ luceneDirectory, true, false );
+ } catch( javax.xml.parsers.ParserConfigurationException e ) {
+ System.err.println( "Illegal Solr configuration: " + e );
+ System.exit( 1 );
+ } catch( org.xml.sax.SAXException e ) {
+ System.err.println( "Illegal Solr configuration: " + e );
+ System.exit( 1 );
+ }
+ }
+
if( (Boolean)parser.getOptionValue( globals, Boolean.FALSE ) ) {
printGlobalInfo( indexReader, printHeaders );
}