我在我的(web)应用程序中有以下工作流程:

  • 从存档
  • 下载PDF文件
  • 索引文件
  • 删除文件

我的问题是,在索引文件后,它保持锁定,删除部分抛出异常。

这是我的代码片段,用于索引文件:

try
{
   ContentStreamUpdateRequest req = new ContentStreamUpdateRequest("/update/extract");
   req.addFile(file, type);
   req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);

   NamedList<Object> result = server.request(req);

   Assert.assertEquals(0, ((NamedList<?>) result.get("responseHeader")).get("status"));
}
.

我想念什么吗?

编辑:

我也尝试了这种方式,但是结果相同...

ContentStream contentStream = null;

    try
    {
      contentStream = new ContentStreamBase.FileStream(document);

      ContentStreamUpdateRequest req = new ContentStreamUpdateRequest(UPDATE_EXTRACT_REQUEST);
//      req.addFile(document, context.getProperty(FTSConstants.CONTENT_TYPE_APPLICATION_PDF));
      req.addContentStream(contentStream);
      req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);

      NamedList<Object> result = server.request(req);

      if (!((NamedList<?>) result.get("responseHeader")).get("status").equals(0))
      {
        throw new IDSystemException(LOG, "Document could not be indexed. Status returned: " +
                                         ((NamedList<?>) result.get("responseHeader")).get("status"));
      }
    }
    catch (FileNotFoundException fnfe)
    {
      throw new IDSystemException(LOG, fnfe.getMessage(), fnfe);
    }
    catch (IOException ioe)
    {
      throw new IDSystemException(LOG, ioe.getMessage(), ioe);
    }
    catch (SolrServerException sse)
    {
      throw new IDSystemException(LOG, sse.getMessage(), sse);
    }
    finally
    {
      try
      {
        if(contentStream != null && contentStream.getStream() != null)
        {
          contentStream.getStream().close();
        }
      }
      catch (IOException ioe)
      {
        throw new IDSystemException(LOG, ioe.getMessage(), ioe);
      }
    }
.

有帮助吗?

解决方案

这似乎是一个错误,

在此提出了一个补丁 https://issues.apache.org/jira/browse/solr-1744

还结账 http://lucene.472066.n3.n3.nabble.com / contentStreamupDateRequest-AddFile-Fails-to-close-to-td485429.html

可以检查流是否没有空头并关闭它。

其他提示

可能是由于文件系统获取的锁定。而不是AddFile(),可以尝试以下内容。

ContentStreamUpdateRequest req = new ContentStreamUpdateRequest("/update/extract");
ContentStreamBase.FileStream fileStream = new FileStream(file);
req.addContentStream(fileStream);
.

shishir

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top