【问题标题】:Is there a way to integrate spring-data-solr with Tika?有没有办法将 spring-data-solr 与 Tika 集成?
【发布时间】:2014-03-14 08:25:03
【问题描述】:

有没有办法通过配置将 spring-data-solr 与 Tika 一起使用?否则,对于 spring-data-solr 的 solrj 的 ContentStreamUpdateRequest+addfile 是否有替代方案?

目前我正在以这种方式使用 Solrj + Tika:

SolrServer server = new HttpSolrServer(URL);
...
Tika tika = new Tika();
...
String fileType = tika.detect(path.toFile());
up = new ContentStreamUpdateRequest("/update/extract"); 
up.addFile(path.toFile(), fileType);
up.setParam("literal.id", idField);
...
up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
NamedList<Object> request = server.request(up);

我通过成功遵循此ExtractingRequestHandler 指南得出了这种方法。

使用 solr 4.3.0,是否可以通过 spring-data-solr 获得相同的结果,而不必直接调用 Solrj?

【问题讨论】:

    标签: solr solrj apache-tika solr-cell spring-data-solr


    【解决方案1】:

    没有对ContentStreamUpdateRequest 的直接支持。后备方案是在由SolrTemplate 执行的SolrCallback 中执行此操作。

    NamedList<Object> result = solrTemplate.execute(new SolrCallback<NamedList<Object>>() {
    
      @Override
      public NamedList<Object> doInSolr(SolrServer solrServer) throws SolrServerException, IOException {
        Tika tika = new Tika();
        // ...
        String fileType = tika.detect(path.toFile());
        ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update/extract");
        up.addFile(path.toFile(), fileType);
        up.setParam("literal.id", idField);
        // ...
        up.setAction(org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION.COMMIT, true, true);
        NamedList<Object> request = solrServer.request(up);
      }
    
    });
    

    如果您在更多存储库中需要这种行为,那么这篇关于 adding custom methods to all repositories 的帖子可能会有所帮助。

    【讨论】:

    • 感谢@Chistoph,但我需要避免使用 ContentStreamUpdateRequest (solrj)
    猜你喜欢
    • 1970-01-01
    • 2011-09-05
    • 2020-07-16
    • 2011-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多