在Google APP engine中,我使用Lucene 4.1。
我能够在本地生成索引文件,但在google服务器上,我得到了以下异常(尽管相同的代码在本地机器中运行良好):
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);
}
}有人能指引我吗?怎么啦?
发布于 2013-06-28 13:59:14
只需进入Google AppEngine administration -> Datastore viewer,选择GaeLock实体并删除所有实体,就可以解锁因任何原因而锁定的每个Lucene索引。
注意!您的数据存储可能处于脏状态,因此必须手动删除索引,方法是删除以下所有条目:LuceneIndex、Segment、SegmentHunk、GaeLock。
当Lucene AppEngine配置不当时,可能会出现问题。检查lucene-appengine站点上的配置说明。
发布于 2017-07-09 18:28:47
我也遇到了同样的问题,但在一个测试中,云工作得很好。我是在groovy中这样做的:
final DatastoreService datastore = DatastoreServiceFactory.getDatastoreService()
final PreparedQuery pq = datastore.prepare(new Query())
def list = pq.asList(FetchOptions.Builder.withDefaults())
datastore.delete(list.collect {it.key})
GetIndexesRequest builder = GetIndexesRequest.newBuilder().build()
GetResponse<Index> indexes = SearchServiceFactory.getSearchService().getIndexes(builder)
for (Index index : indexes) {
Results<ScoredDocument> result = index.search("")
for (Document document : result) {
index.deleteAsync(document.id)
}
}它应该在每次测试之前清除数据存储中的所有数据和所有索引。但是在index.deleteAsync(document.id)行中抛出一个错误
https://stackoverflow.com/questions/14598958
复制相似问题