本文介绍了indexwriter.close中的空指针异常(在Google App Engine中使用ramdirectory)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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_BlobstoreFor search I just deserialize it and use in my searches.

我在关闭索引编写器时遇到空指针异常.

我认为这可能与Google App Engine仅支持以下库的事实有关. http://code.google.com/appengine/docs/java/jrewhitelist.html

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

我正在使用lucene 3.5.0和App Engine Java版本1.6.1

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)

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

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

推荐答案

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

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

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

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 :)

这篇关于indexwriter.close中的空指针异常(在Google App Engine中使用ramdirectory)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 07:50