首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有办法集成spring-data-solr和Tika?

有没有办法集成spring-data-solr和Tika?
EN

Stack Overflow用户
提问于 2014-02-15 03:57:23
回答 1查看 475关注 0票数 0

有没有办法,通过配置,在Tika中使用spring-data-solr?否则,对于spring-data-solr,有没有什么方法可以替代solrj的ContentStreamUpdateRequest+addfile呢?

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

代码语言:javascript
复制
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指南获得了这个方法。

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

EN

回答 1

Stack Overflow用户

发布于 2014-02-17 12:43:46

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

代码语言:javascript
复制
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的文章可能会有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21788450

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档