2012-10-16 17 views
5

編輯:我發現解決方案:編輯core.jar,刪除所有包,除了編解碼器包並添加到構建路徑,編解碼器包必須在jar,不能被源代碼 我無法理解,這是Lucene的非常簡單的代碼,它使用Lucene核心庫運行,但是當我使用Lucene核心源時會導致錯誤。錯誤簡單的例子lucene 4.0與源代碼(不是jar lib)

public static void main(String[] args) throws IOException, ParseException { 
    Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT); 

    // Store the index in memory: 
    Directory directory = new RAMDirectory(); 
    // To store an index on disk, use this instead: 
    // Directory directory = FSDirectory.open("/tmp/testindex"); 
    IndexWriterConfig config = new IndexWriterConfig(
      Version.LUCENE_CURRENT, analyzer); 
    IndexWriter iwriter = new IndexWriter(directory, config); 
    Document doc = new Document(); 
    String text = "This is the text to be indexed."; 
    doc.add(new Field("fieldname", text, TextField.TYPE_STORED)); 
    iwriter.addDocument(doc); 
    iwriter.close(); 

    // Now search the index: 
    DirectoryReader ireader = DirectoryReader.open(directory); 
    IndexSearcher isearcher = new IndexSearcher(ireader); 
    // Parse a simple query that searches for "text": 
    QueryParser parser = new QueryParser(Version.LUCENE_CURRENT, 
      "fieldname", analyzer); 
    Query query = parser.parse("text"); 
    ScoreDoc[] hits = isearcher.search(query, null, 1000).scoreDocs; 
    // Iterate through the results: 
    for (int i = 0; i < hits.length; i++) { 
     Document hitDoc = isearcher.doc(hits[i].doc); 
       System.out.println(hitDoc.get("fieldname")); 
    } 
    ireader.close(); 
    directory.close(); 
} 

的錯誤是:

Exception in thread "main" java.lang.ExceptionInInitializerError 
     at org.apache.lucene.index.LiveIndexWriterConfig.<init>(LiveIndexWriterConfig.java:118) 
     at org.apache.lucene.index.IndexWriterConfig.<init>(IndexWriterConfig.java:145) 
     at Test.main(Test.java:34) 
    Caused by: java.lang.IllegalArgumentException: A SPI class of type org.apache.lucene.codecs.Codec with name 'Lucene40' does not exist. You need to add the corresponding JAR file supporting this SPI to your classpath.The current classpath supports the following names: [] 
     at org.apache.lucene.util.NamedSPILoader.lookup(NamedSPILoader.java:104) 
     at org.apache.lucene.codecs.Codec.forName(Codec.java:95) 
     at org.apache.lucene.codecs.Codec.<clinit>(Codec.java:122) 
     ... 3 more 
+0

參見:http://stackoverflow.com/questions/9474625/how-to-debug-solr-test-cases-in-eclipse – kenorb

+0

我已經使用Luke打開由Lucene42生成的solr索引時出現類似的錯誤。 – kenorb

回答

0

你必須Lucene的jar添加到classpath中。

如果這不起作用,請將jar複製到您的索引目錄中,例如

java -cp app/luke/lukeall-4.0-dev.jar org.apache.lucene.index.CheckIndex data/solr/cores/collection1_0/data/index/ 

一些解壓的web應用程序的罐子中的戰爭, 是定製的,並沒有自己的清單目錄。盧克罐有 代碼,是一個獨立的罐子。

參見:

How Do I Execute CheckIndex In LWE2.1