2016-07-26 45 views
1

我必須提取一些由Nutch在默認情況下不提供的Apache Nutch 2.3.1抓取數據的元數據信息。爲此我必須編寫一個插件。爲了學習的目的,我以Nutch tutorial爲起點。我知道這個教程是爲1.x版本。我已經改變了所有必要的分類,併成功地建立了它。以下是我所遵循的步驟。Apache Nutch 2.3.1插件不工作

  1. 創建類似$ NUTCH_HOME一個的/ src /插件/爲myplugin
  2. 複製指數的元數據,以我的plugina並創建一個文件myField.java CP -r索引元/ *爲myplugin/
  3. 目錄列表應該像
myPlugin/plugin.xml 
build.xml 
ivy.xml 
src/java/org/apache/nutch/indexer/AddField.java 
  • 插件/ myplgin/plugin.xml中應該是這樣的
  • <?xml version="1.0" encoding="UTF-8"?> 
    <plugin id="myPlugin" name="Add Field to Index" 
        version="1.0.0" provider-name="your name"> 
        <runtime> 
        <library name="myPlugin.jar"> 
         <export name="*"/> 
        </library> 
        </runtime> 
        <extension id="org.apache.nutch.indexer.myPlugin" 
         name="Add Field to Index" 
         point="org.apache.nutch.indexer.IndexingFilter"> 
        <implementation id="myPlugin" 
         class="org.apache.nutch.indexer.AddField"/> 
        </extension> 
    </plugin> 
    
  • 變化的build.xml像
  • <?xml version="1.0" encoding="UTF-8"?> 
    <project name="myPlugin" default="jar"> 
        <import file="../build-plugin.xml"/> 
    </project> 
    
    1. Then

    <ant dir="myPlugin" target="deploy" />

  • 編輯您./conf/nutch-site.xml

    <property> 
        <name>plugin.includes</name> 
        <value>plugin-1|plugin-2|myPlugin</value> 
        <description>Added myPlugin</description> 
    </property> 
    
  • 添加下列行分別在schema.xml和solrindex-mapping.xml中

    <field name="pageLength" type="long" stored="true" indexed="true"/> 
    <field dest="pageLength" source="pageLength"/> 
    
  • 然後我編我編寫的代碼(類似於網址給定的例子)

  • 當我以本地模式運行的Nutch,以下是索引到Solr步日誌信息

    Active IndexWriters : 
    SOLRIndexWriter 
        solr.server.url : URL of the SOLR instance (mandatory) 
        solr.commit.size : buffer size when sending to SOLR (default 1000) 
        solr.mapping.file : name of the mapping file for fields (default solrindex-mapping.xml) 
        solr.auth : use authentication (default false) 
        solr.auth.username : username for authentication 
        solr.auth.password : password for authentication  
    IndexingJob: done. 
    

    我在solr schema中也添加了field pageLength。根據我的預期,應該有一個新的字段pageLength具有適當的值,但solr中沒有字段。

    問題在哪裏?它是一個簡單的玩具例子。 這是nutch日誌文件(hadoop。日誌)輸出索引步驟

    2016-07-26 16:53:25,649 INFO solr.SolrMappingReader - source: content dest: content 
    2016-07-26 16:53:25,649 INFO solr.SolrMappingReader - source: title dest: title 
    2016-07-26 16:53:25,649 INFO solr.SolrMappingReader - source: host dest: host 
    2016-07-26 16:53:25,649 INFO solr.SolrMappingReader - source: batchId dest: batchId 
    2016-07-26 16:53:25,649 INFO solr.SolrMappingReader - source: boost dest: boost 
    2016-07-26 16:53:25,649 INFO solr.SolrMappingReader - source: digest dest: digest 
    2016-07-26 16:53:25,649 INFO solr.SolrMappingReader - source: tstamp dest: tstamp 
    2016-07-26 16:53:25,649 INFO solr.SolrMappingReader - source: pageLength dest: pageLength 
    2016-07-26 16:53:26,140 INFO solr.SolrIndexWriter - Total 1 document is added. 
    2016-07-26 16:53:26,140 INFO indexer.IndexingJob - IndexingJob: done. 
    

    如何確認插件是由nutch加載的? 其次,有沒有什麼辦法可以測試Nutch插件,然後將其配置爲無法抓取?

    回答

    1

    嘗試在plugin.xml中更改擴展名。將其更改爲「org.apache.nutch.indexer.AddField」並重新構建Nutch

    <extension id="org.apache.nutch.indexer.AddField" 
         name="Add Field to Index" 
         point="org.apache.nutch.indexer.IndexingFilter"> 
        <implementation id="myPlugin" 
         class="org.apache.nutch.indexer.AddField"/> 
    </extension> 
    

    我認爲應該解決問題。

    也正好驗證控件來你的插件類或不添加到代碼中的一些信息日誌像

    LOG.info(「從插件打印」);
    如果您能夠在hadoop.log中看到這些日誌,這意味着控件即將進入插件類。