solrj - 索引后锁定的文件

标签 solrj solr4 apache-tika

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

  • 从存档下载 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);
          }
        }
    

    最佳答案

    这可能是由于文件系统获取了锁。您可以尝试以下操作,而不是 addFile()。

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

    石狮

    关于solrj - 索引后锁定的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22035777/

    相关文章:

    java - 如何防止 solr 在索引时解码 url?

    mysql - 使用 Solr 数据导入处理程序将多值字段从 mySQL 导入 Solr

    python-2.7 - 无法使用 python 和请求发布到 solr 服务器

    SolrCloud 和需要索引重建和/或修改代码的更新

    java - 如何解决我的 Apache Tika 代码中的以下 "NoClassDefFoundError"问题?

    Solrcloud 删除集合错误?

    java - Solr 中缺少强制 uniquekey 字段错误

    java - Tika 返回空字符串

    java - 使用 Solrj 进行基本身份验证时,出现错误 "Caused by: java.net.SocketException: Connection reset"

    pdfbox - java.lang.NoClassDefFoundError : Could not initialize class org. apache.pdfbox.pdmodel.font.PDFont