动态添加字段到 NutchDocument
Dynamically add fields to NutchDocument
我将 Nutch 1.12 与 Elastic Search 一起使用,我想动态添加一个字段到 NutchDocument
。
目前,我可以将静态字段值添加到 NutchDocument
并能够将其索引到 Elastic Search。
这是我的索引过滤器的代码片段:
public class CustomIndexFilter implements IndexingFilter {
private Configuration conf;
public Configuration getConf() {
return conf;
}
public void setConf(Configuration conf) {
this.conf = conf;
}
@Override
public NutchDocument filter(NutchDocument doc, Parse parse, Text url, CrawlDatum datum, Inlinks inlinks) {
String content = parse.getText();
doc.add("pageLength", content.length());
return doc;
}
}
我认为NutchDocument
是解析后创建的。因此,在此之前需要提供字段值(不知道我应该在哪里提供)。寻求解决方法。
任何帮助将不胜感激:)
NutchDocument 是在索引步骤中创建的,正如您所发现的,它由 IndexingFilters 修改。后者通常使用来自解析的元数据,但字段本身主要由 IndexingFilters 创建(有些由主索引代码创建)。有许多插件允许您根据配置生成字段,例如索引元数据或索引静态。
我会建议一个解决方法。您可以使用 Nutch REST api 为爬网 运行 创建带有自定义选项的自定义配置。然后在您的自定义索引器插件中读取该特定配置。通过这种方式,您可以在从 conf 中读取 NutchDocument 中的字段来控制正在索引的内容。 HTH
我将 Nutch 1.12 与 Elastic Search 一起使用,我想动态添加一个字段到 NutchDocument
。
目前,我可以将静态字段值添加到 NutchDocument
并能够将其索引到 Elastic Search。
这是我的索引过滤器的代码片段:
public class CustomIndexFilter implements IndexingFilter {
private Configuration conf;
public Configuration getConf() {
return conf;
}
public void setConf(Configuration conf) {
this.conf = conf;
}
@Override
public NutchDocument filter(NutchDocument doc, Parse parse, Text url, CrawlDatum datum, Inlinks inlinks) {
String content = parse.getText();
doc.add("pageLength", content.length());
return doc;
}
}
我认为NutchDocument
是解析后创建的。因此,在此之前需要提供字段值(不知道我应该在哪里提供)。寻求解决方法。
任何帮助将不胜感激:)
NutchDocument 是在索引步骤中创建的,正如您所发现的,它由 IndexingFilters 修改。后者通常使用来自解析的元数据,但字段本身主要由 IndexingFilters 创建(有些由主索引代码创建)。有许多插件允许您根据配置生成字段,例如索引元数据或索引静态。
我会建议一个解决方法。您可以使用 Nutch REST api 为爬网 运行 创建带有自定义选项的自定义配置。然后在您的自定义索引器插件中读取该特定配置。通过这种方式,您可以在从 conf 中读取 NutchDocument 中的字段来控制正在索引的内容。 HTH