3

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

关闭索引器时,我面临空指针异常。

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

我正在使用 lucene 3.5.0 和应用引擎 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)

该代码在我的本地机器上正常工作(我没有添加太多代码,只是添加了一些示例文档并做了一个 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();

当我试图在最后一行关闭作者时抛出异常

4

1 回答 1

3

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

于 2012-02-16T15:48:31.763 回答