带有源的错误简单示例lucene 4.0(不是jar lib) [英] Error simple example lucene 4.0 with source (not jar lib)

查看:74
本文介绍了带有源的错误简单示例lucene 4.0(不是jar lib)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了解决方法:编辑core.jar,删除除编解码器包以外的所有包,然后添加到构建路径中,编解码器包必须位于jar中,不能作为源代码 我不明白,这对于Lucene是非常简单的代码,它与Lucene核心库一起运行,但是当我使用Lucene核心源时会导致错误.

I found the solution: edit the core.jar, delete all package except the codec package and add to the build path, the codec package must be in jar, can't be source code I can't understand, this is very simple code for Lucene, it run with Lucene core lib, but cause error when I use Lucene core source.

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

推荐答案

您必须将Lucene jar添加到类路径中.

You have to add the Lucene jar to the classpath.

如果这不起作用,请将jar复制到您的索引目录中,例如

If this doesn't work, copy jar into your index directory, e.g.

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

解压后的网络应用中的某些罐子是为战争量身定制的, 并且没有自己的MANIFEST目录.路加罐有 代码,并且是一个独立的jar.

Some of the jars in the unpacked web app are custom-made for the war, and do not have their own MANIFEST directory. The Luke jar has the code and is a standalone jar.

另请参阅:

如何执行CheckIndex在LWE2.1中

这篇关于带有源的错误简单示例lucene 4.0(不是jar lib)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆