使用 ElasticSearch and/or Solr 作为 MS Office 和 PDF 文档的数据存储

Using ElasticSearch and/or Solr as a datastore for MS Office and PDF documents

我目前正在设计一个全文搜索系统,用户可以在其中对 MS Office 和 PDF 文档执行文本查询,结果将 return 与查询最匹配的文档列表。然后,用户将 select 任何文档 returned 并在 MS Word、Excel 或 PDF 查看器中查看该文档。

我能否使用 ElasticSearch 或 Solr 将原始二进制文档(即 .docx、.xlsx、.pdf 文件)导入其 "data store",然后根据命令将文档导出到用户设备正在观看。

以前,我使用 MongoDB 2.6.6 将原始文件导入 GridFS,并将提取的文本导入一个单独的集合(该集合包含一个文本索引)并且工作正常。但是,MongoDB 全文搜索非常基础,因此我现在正在寻找 Solr 或 ElasticSearch 来执行更复杂的文本搜索。

尼克

关于 solr:

如果仅需要在元数据搜索中返回文档,Solr 具有 BinaryField 字段类型,您可以向其发送二进制数据库 base64 encoded.Keep 请记住,通常人们建议不要这样做,因为它可能增加索引(RAM requirements/performance),如果可能的话,在外部存储文件的设置(以及 solr 中文件的路径)可能是更好的选择。

如果您希望 solr 自动索引 pdf/doc 中的文本——使用 extractingrequesthandler 是可能的:https://wiki.apache.org/solr/ExtractingRequestHandler

我会尝试 Elasticsearch 附件插件。可以在这里找到详细信息:

https://www.elastic.co/guide/en/elasticsearch/plugins/2.2/mapper-attachments.html

https://github.com/elasticsearch/elasticsearch-mapper-attachments

它建立在 Apache Tika 之上:

http://tika.apache.org/1.7/formats.html

附件类型

The attachment type allows to index different "attachment" type field (encoded as base64), for example, Microsoft Office formats, open document formats, ePub, HTML, and so on (full list can be found here).

The attachment type is provided as a plugin extension. The plugin is a simple zip file that can be downloaded and placed under $ES_HOME/plugins location. It will be automatically detected and the attachment type will be added.

支持的文档格式

  • HyperText Markup Language

  • XML and derived formats

  • Microsoft Office document formats
  • OpenDocument Format
  • iWorks document formats
  • Portable Document Format
  • Electronic Publication Format
  • Rich Text Format
  • Compression and packaging formats
  • Text formats
  • Feed and Syndication formats
  • Help formats
  • Audio formats
  • Image formats
  • Video formats
  • Java class files and archives
  • Source code
  • Mail formats
  • CAD formats
  • Font formats
  • Scientific formats
  • Executable programs and libraries
  • Crypto formats

Solr 和 Elasticsearch 都会索引文档的内容。 Solr 具有内置功能,Elasticsearch 需要一个插件。无论哪种方式都很简单,并且都在幕后使用 Tika。

它们都不会存储文档本身。您可以尝试让他们这样做,但他们不是为此而设计的,您会受苦。

此外,目前不推荐将 Solr 和 Elasticsearch 作为主存储。他们可以做到,但这对他们来说并不像文件系统实现那样关键。

因此,我建议将文件放在其他地方并使用 Solr/Elasticsearch 仅用于搜索。这就是他们发光的地方。

Elasticsearch 在 _source 字段中存储文档(例如 .pdf、.doc)。它可以用作 NoSQL 数据存储(与 MongoDB 相同)。

聚会有点晚了,但这可能对某人有所帮助 :)

我遇到了类似的问题,一些研究让我找到了 fscrawler。说明:

This crawler helps to index binary documents such as PDF, Open Office, MS Office.

主要特点:

  • 本地文件系统(或安装的驱动器)爬网和索引新文件,
  • 更新现有的并删除旧的。通过 SSH 的远程文件系统 爬行。
  • REST 接口让你"upload"你的二进制文件到 elasticsearch。