SolrJ addFile使文档保持打开状态 [英] SolrJ addFile keeps documents open

查看:214
本文介绍了SolrJ addFile使文档保持打开状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经提交了类似的问题,但我已将问题分解为最简单的形式,所以我要再次发布:

I've already submitted a similar question, but I've broken down the problem to its simplest form, so I'm gonna post it again:

问题是,如果我多次添加同一个文件,SolrJ似乎保持文件句柄打开。

The problem is, that SolrJ seems to keep file handles open, if I add the same file more than once.

我使用以下方法向Solr提交文档:

I use the following method to submit a document to Solr:

public boolean addDocument( File doc ) throws IOException, SolrServerException {

    ContentStreamUpdateRequest csur = new ContentStreamUpdateRequest( "/update/extract" );

    csur.addFile( doc );
    csur.setParam( "literal.id", Utils.getAbsolutePath( doc ) );
    csur.setAction( AbstractUpdateRequest.ACTION.COMMIT, true, true );
    NamedList<Object> result = this.solr.request( csur );


    return result != null;
}

这种删除文件的方法:

public void removeDocument( File doc ) throws IOException,
        SolrServerException {

    this.solr.deleteById( Utils.getAbsolutePath( doc ) );
    this.solr.commit();
}

但这似乎会让一些文件句柄挥之不去:

But that seems to leave some File Handles lingering:

以下代码段演示了此问题:

The following snippet demonstrates the problem:

File doc = new File( "../../testpdf/bbb.pdf" );
solr.addDocument( doc );
//solr.removeDocument( doc );   // Without these 2 lines, all handles
//solr.addDocument( doc );      // are released correctly

如果我添加两次相同的文档,SolrJ会以某种方式保持句柄处于活动状态,并且任何其他进程都无法修改添加的文档。

If I add the same document twice, SolrJ somehow keeps the handles alive, and the added document cannot be modified by any other processes.

我已经尝试使用调用csur.addContentStream()而不是 csur.addFile() addDocument 中,然后关闭添加的流的基础Stream和Reader,没有效果。

I've already tried calling using csur.addContentStream() instead of csur.addFile() in addDocument and then closing the underlying Stream and Reader of the added stream, with no effect.

thx提前任何建议

推荐答案

解决它,通过编写缓冲文档的自定义ContentStream来做一个解决方法。

Couldn't fix it, did a workaround by writing a custom ContentStream that buffers the document.

这篇关于SolrJ addFile使文档保持打开状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆