2016-11-23 63 views
2

我正在使用Nutch 1.12與彈性搜索,我想動態地添加一個字段到NutchDocument動態添加字段到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在解析後創建。所以,在此之前需要提供字段值(不知道我應該在哪裏提供)。爲此尋求解決方法。

任何幫助將不勝感激:)在索引步驟創建

回答

2

我會爲此提出解決方法。您可以使用Nutch REST api爲爬網運行創建具有自定義選項的自定義配置。然後在自定義索引器插件中讀取特定配置。這樣,您可以通過在從conf中讀取字段後設置NutchDocument中的字段來控制索引的內容。 HTH

2

的NutchDocument和,因爲你發現,通過IndexingFilters修改。後者通常使用來自解析的元數據,但是這些字段本身主要由IndexingFilters創建(有些是由主索引代碼創建的)。有許多插件允許您根據配置生成字段,例如索引元數據或索引靜態。