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

查看:21
本文介绍了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;
}

还有这种删除文件的方法:

And this method to remove documents:

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.

我已经尝试在 addDocument 中使用 csur.addContentStream() 而不是 csur.addFile() 进行调用,然后关闭底层添加的流的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 for any suggestions in advance

推荐答案

无法修复,通过编写缓冲文档的自定义 ContentStream 来解决.

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

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

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