2

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);
}
}

谁能指导我?怎么了?

4

2 回答 2

2

只需进入Google AppEngine administration -> Datastore viewer,选择 GaeLock 实体并删除所有实体,这样做您将解锁每个因任何原因被锁定的 Lucene 索引。

当心!可能您的数据存储已陷入脏状态,因此您必须通过删除以下所有条目来手动删除索引:LuceneIndex, Segment, SegmentHunk, GaeLock

当 Lucene AppEngine 配置不正确时,您可能会遇到问题。检查lucene-appengine 站点上的配置说明。

于 2013-06-28T13:59:14.680 回答
1

我遇到了同样的问题,但在测试中,在云中运行得很好。我在 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)行中抛出错误

于 2017-07-09T18:28:47.427 回答