在Google APP engine
,我正在使用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);
}
}
谁能指导我?怎么了?