0

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

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

我使用以下方法向 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();
}

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

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

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 会以某种方式使句柄保持活动状态,并且添加的文档不能被任何其他进程修改。

我已经尝试调用 usingcsur.addContentStream()而不是csur.addFile()inaddDocument然后关闭添加流的底层 Stream 和 Reader ,但没有任何效果。

感谢您提前提出任何建议

4

1 回答 1

0

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

于 2011-05-25T20:24:09.807 回答