在 Google APP 引擎
中,我使用的是 Lucene 4.1
。
我能够在本地生成索引文件,但在谷歌服务器上我收到以下异常(尽管相同的代码在本地计算机中工作正常):
org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out:
com.googlecode.lucene.appengine.GaeLockFactory$1@104a681
这是我的代码:
package com.search.domain;
import java.io.IOException;
import java.util.Set;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.util.Version;
import com.domain.dataobjects.Item;
import com.googlecode.lucene.appengine.GaeDirectory;
import com.googlecode.lucene.appengine.GaeLuceneUtil;
public class ItemDataIndexWriter {
public String createIndexes(){
IndexWriter indexWriter = null;
GaeDirectory indexDirectory = null;
try{
indexDirectory = new GaeDirectory();
StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_41 );
IndexWriterConfig config = GaeLuceneUtil.getIndexWriterConfig(Version.LUCENE_41, analyzer);//get configuration
config.setOpenMode(OpenMode.CREATE_OR_APPEND);
indexWriter = new IndexWriter(indexDirectory, config);
addToDoc(indexWriter,"test");
}catch(Exception e){
e.printStackTrace();
System.out.println(e.getMessage());
return e.toString();
}
finally{
try {
if(indexWriter!=null)
indexWriter.close();
if(indexDirectory!=null)
indexDirectory.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println(e.getMessage());
}
}
return "Good";
}
private static void addToDoc(IndexWriter w, String item) throws IOException {
Document doc = new Document();
doc.add(new TextField("item", item, Field.Store.YES));
w.addDocument(doc);
}
}
有人可以指导我吗?怎么了?
最佳答案
只需进入 Google AppEngine 管理 -> 数据存储查看器
,选择 GaeLock 实体并删除所有实体,这样您就可以解锁因任何原因锁定的每个 Lucene 索引。
小心!可能您的数据存储区已陷入脏状态,因此您必须通过删除以下所有条目来手动删除索引:LuceneIndex
、Segment
、SegmentHunk
、 GaeLock
。
当 Lucene AppEngine 配置不正确时,可能会出现您遇到的问题。检查 lucene-appengine site 上的配置说明.
关于google-app-engine - Google App Engine : Lucene org. apache.lucene.store.LockObtainFailedException:锁定获取超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14598958/