【问题标题】:How to index entire local Hard Drive into Apache Solr?如何将整个本地硬盘索引到 Apache Solr?
【发布时间】:2013-10-10 00:48:32
【问题描述】:

Solr 或向 Solr 提供客户端库以索引整个硬盘驱动器的好方法是否存在。这应该包括 zip 文件中的内容,包括 zip 文件中递归的 zip 文件?

这应该能够在 Linux 上运行(没有仅限 Windows 的客户端)。

这当然会涉及从根目录(或者实际上是任何文件夹)对整个文件系统进行一次扫描。在这一点上,我并不关心保持索引是最新的,只是最初创建它。这将类似于 Google 停止使用的旧版“Google 桌面”应用程序。

【问题讨论】:

  • 你的问题是?

标签: java linux search solr lucene


【解决方案1】:

您可以使用 SolrJ API 操作 Solr。

这里是 API 文档:http://lucene.apache.org/solr/4_0_0/solr-solrj/index.html

还有一篇关于如何使用 SolrJ 为硬盘上的文件建立索引的文章。
http://blog.cloudera.com/blog/2012/03/indexing-files-via-solr-and-java-mapreduce/

文件由InputDocument 表示,您可以使用.addField 附加您希望稍后搜索的字段。

这是索引驱动程序的示例代码:

public class IndexDriver extends Configured implements Tool {     

  public static void main(String[] args) throws Exception {
    //TODO: Add some checks here to validate the input path
    int exitCode = ToolRunner.run(new Configuration(),
     new IndexDriver(), args);
    System.exit(exitCode);
  }

  @Override
  public int run(String[] args) throws Exception {
    JobConf conf = new JobConf(getConf(), IndexDriver.class);
    conf.setJobName("Index Builder - Adam S @ Cloudera");
    conf.setSpeculativeExecution(false);

    // Set Input and Output paths
    FileInputFormat.setInputPaths(conf, new Path(args[0].toString()));
    FileOutputFormat.setOutputPath(conf, new Path(args[1].toString()));
    // Use TextInputFormat
    conf.setInputFormat(TextInputFormat.class);

    // Mapper has no output
    conf.setMapperClass(IndexMapper.class);
    conf.setMapOutputKeyClass(NullWritable.class);
    conf.setMapOutputValueClass(NullWritable.class);
    conf.setNumReduceTasks(0);
    JobClient.runJob(conf);
    return 0;
  }
}

阅读article 了解更多信息。

压缩文件 以下是处理压缩文件的信息:Using Solr CELL's ExtractingRequestHandler to index/extract files from package formats

Solr 似乎存在一些错误,无法处理 zip 文件,这是修复的错误报告:https://issues.apache.org/jira/browse/SOLR-2416

【讨论】:

    猜你喜欢
    • 2014-06-22
    • 2012-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-31
    • 2014-12-16
    • 1970-01-01
    • 2011-01-21
    相关资源
    最近更新 更多