从 C# 客户端在 Solr 中索引 pdf 文档 [英] Index pdf documents in Solr from C# client

查看:25
本文介绍了从 C# 客户端在 Solr 中索引 pdf 文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我试图在 Solr 中索引 word 或 pdf 文档并找到了 ExtractingRequestHandler,但无法弄清楚如何在 C# 中编写代码来执行像 Solr wiki 中的 HTTP POST 请求:http://wiki.apache.org/solr/ExtractingRequestHandler.

Basically I'm trying to index word or pdf documents in Solr and found the ExtractingRequestHandler, but can't figure out how to write code in c# that performs the HTTP POST request like in the Solr wiki: http://wiki.apache.org/solr/ExtractingRequestHandler.

我已经使用 Solr zip 中 example/solr 目录中的文件在 Tomcat 7 (7.0.22) 上安装了 Solr 3.4,我没有更改任何内容.ExtractingRequestHandler 应该在 solrconfig.xml 中配置开箱即可使用,对吗?

I've installed Solr 3.4 on Tomcat 7 (7.0.22) using the files from the example/solr directory in the Solr zip and I haven't altered anything. The ExtractingRequestHandler should be configured out of the box in the solrconfig.xml and ready to use, right?

你们中的一些人能否举一个 C# (HttpWebRequest) 示例来说明如何发出 HTTP POST 请求并上传 PDF 文件,就像在 Solr wiki 中使用 curl 完成的一样?

Can some of you give an C# (HttpWebRequest) example of how you make the HTTP POST request and upload a PDF file like it is done using curl in the Solr wiki?

我已经浏览了该站点和许多其他站点,试图找到有关如何完成此操作的示例或教程,但没有找到任何内容.

I've look all over this site and many others trying to find an example or a tutorial on how this is done, but haven't found anything.

我终于设法使用 SolrNet 让它工作了!

I finally managed to get it to work using SolrNet!

为了使其工作,您需要将其从 Solr zip 复制到 Solr 安装目录中的 lib 文件夹:

In order for it to work you need to copy this to a lib-folder in your Solr installation directory from the Solr zip:

  • dist 文件夹中的 apache-solr-cell-3.4.0.jar 文件
  • contribextractionlib 目录的内容

在 SolrNet 0.4.0 beta 2 中,这段代码可以完成这项工作:

With SolrNet 0.4.0 beta 2, this code does the job:

Startup.Init<IndexDocument>("YOUR-SOLR-SERVICE-PATH");
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<IndexDocument>>();

using (FileStream fileStream = File.OpenRead("FILE-PATH-FOR-THE-FILE-TO-BE-INDEXED"))
{
    var response =
        solr.Extract(
            new ExtractParameters(fileStream, "doc1")
            {
                ExtractFormat = ExtractFormat.Text,
                ExtractOnly = false
            });
}

solr.Commit();

很抱歉给您带来麻烦.但是,我希望其他人会发现这很有用.

Sorry for the trouble. I hope however that others will find this useful.

推荐答案

我建议使用 SolrNet 客户.它支持 ExtractingRequestHandler.

I would recommend using the SolrNet client. It supports the ExtractingRequestHandler.

此处是 code.google.com 上的 已弃用的存储库

Here the Deprecated repo on code.google.com

这篇关于从 C# 客户端在 Solr 中索引 pdf 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆