indexwriter.close 中的空指针异常(在 Google 应用引擎中使用 ramdirectory)

发布于 2024-12-28 10:03:44 字数 2090 浏览 2 评论 0原文

我正在努力让 lucene 索引在 Google App Engine 上工作。 我使用 ramdirectory 来创建索引,然后将其(ramdirectory 对象)序列化到 memcache 和 blobstore 以进行持久存储。 http://code.google.com/appengine/docs/java /blobstore/overview.html#Writing_Files_to_the_Blobstore 对于搜索,我只是将其反序列化并在我的搜索中使用。

当我关闭索引编写器时,我遇到空指针异常。

我认为这可能与 Google 应用引擎仅支持以下库这一事实有关。 http://code.google.com/appengine/docs/java/jrewhitelist.html

我正在使用 lucene 3.5.0 和 app engine java 版本 1.6.1

以下是我得到的堆栈跟踪

java.lang.NullPointerException
at org.apache.lucene.store.DataOutput.writeString(DataOutput.java:103)
at org.apache.lucene.store.DataOutput.writeStringStringMap(DataOutput.java:189)
at org.apache.lucene.index.SegmentInfo.write(SegmentInfo.java:623)
at org.apache.lucene.index.SegmentInfos.write(SegmentInfos.java:394)
at org.apache.lucene.index.SegmentInfos.prepareCommit(SegmentInfos.java:872)
at org.apache.lucene.index.IndexWriter.startCommit(IndexWriter.java:4601)
at org.apache.lucene.index.IndexWriter.prepareCommit(IndexWriter.java:3453)
at org.apache.lucene.index.IndexWriter.commitInternal(IndexWriter.java:3524)
at org.apache.lucene.index.IndexWriter.closeInternal(IndexWriter.java:1879)
at org.apache.lucene.index.IndexWriter.close(IndexWriter.java:1822)
at org.apache.lucene.index.IndexWriter.close(IndexWriter.java:1786)

代码在我的本地计算机上正常工作(我没有添加太多代码,只是添加了一些样本文件并做了a indexwriter.close())

以前有人遇到过这个问题吗?如果是的话有没有解决方法?

我发现问题的代码很简单,

RAMDirectory dir = new RAMDirectory();
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_35, new StandardAnalyzer(Version.LUCENE_35));
IndexWriter writer = new IndexWriter(dir,config); 
Document doc;
doc = new Document();
doc.add(new Field("text","mary had a little lamb", Store.YES, Index.ANALYZED));
writer.addDocument(doc)
writer.close();

当我试图在最后一行关闭编写器时抛出异常

I am working on getting lucene indexing working on Google App Engine.
I am using a ramdirectory to make the index and then serializing it (the ramdirectory object) to memcache and blobstore for persistent storage.
http://code.google.com/appengine/docs/java/blobstore/overview.html#Writing_Files_to_the_Blobstore
For search I just deserialize it and use in my searches.

I am facing a null pointer exception when I close the indexwriter.

I think that might have something to do with the fact that only the following libraries are supported in google app engine.
http://code.google.com/appengine/docs/java/jrewhitelist.html

I am using lucene 3.5.0 and app engine java version 1.6.1

The following is the stack trace which i get

java.lang.NullPointerException
at org.apache.lucene.store.DataOutput.writeString(DataOutput.java:103)
at org.apache.lucene.store.DataOutput.writeStringStringMap(DataOutput.java:189)
at org.apache.lucene.index.SegmentInfo.write(SegmentInfo.java:623)
at org.apache.lucene.index.SegmentInfos.write(SegmentInfos.java:394)
at org.apache.lucene.index.SegmentInfos.prepareCommit(SegmentInfos.java:872)
at org.apache.lucene.index.IndexWriter.startCommit(IndexWriter.java:4601)
at org.apache.lucene.index.IndexWriter.prepareCommit(IndexWriter.java:3453)
at org.apache.lucene.index.IndexWriter.commitInternal(IndexWriter.java:3524)
at org.apache.lucene.index.IndexWriter.closeInternal(IndexWriter.java:1879)
at org.apache.lucene.index.IndexWriter.close(IndexWriter.java:1822)
at org.apache.lucene.index.IndexWriter.close(IndexWriter.java:1786)

The code works properly on my local machine (I haven't added much of a code , just added some sample documents and did a indexwriter.close())

Has someone faced this problem before ?? and if so is there a workaround for it ??

The code where I am finding the problem is simple

RAMDirectory dir = new RAMDirectory();
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_35, new StandardAnalyzer(Version.LUCENE_35));
IndexWriter writer = new IndexWriter(dir,config); 
Document doc;
doc = new Document();
doc.add(new Field("text","mary had a little lamb", Store.YES, Index.ANALYZED));
writer.addDocument(doc)
writer.close();

the exception is thrown when i am trying to close the writer in the last line

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坏尐絯 2025-01-04 10:03:44

问题是,出于某种原因,Lucene 尝试将 os.version 和 os.arch 存储在索引中。

我不知道为什么,但是解决方案是将属性添加到您的 appengine-web.xml 中:

<system-properties>
    <property name="os.version" value="1.0.GAE whatever" />
    <property name="os.arch" value="GAE whatever" />
</system-properties>

它会为您工作。希望有帮助:)

the problem is that for some reason Lucene tries to store os.version and os.arch in index.

I don't know why, however the solution is adding the properties to your appengine-web.xml:

<system-properties>
    <property name="os.version" value="1.0.GAE whatever" />
    <property name="os.arch" value="GAE whatever" />
</system-properties>

and it will work for you. Hope that helps :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文