Nutch的plugin开发一些心得,现在对此进行纪录。我现在要对hmtl中anchor中一些判断
1. 首先分析要对什么进行过滤。经过查看原代码。判断需要对org.apache.nutch.parse.HtmlParseFilter进行extension.
2. 对于 parseResult进一步的filter.
3. 在分析过程中, 先对
HtmlParse.java中的 ParseResult filteredParse = this.htmlParseFilters.filter(content, parseResult,
metaTags, root);
4. 查看htmlparsefilters 的代码,负责load htmlparsefilter的plugin实现的load进execute the filter方法. 只要是实现htmlparsefilter 的即可达到html parsef ilter效果 (请留意s)
5. 首先参考其他plugin,在plugin 目录下创建相关的plug in 的目录。但是在创建package是对应的目录要多试几次。package name就参考其他parse-js创建就好了
6. public class AnchorParseFilter implements HtmlParseFilter, Parser 实现 htmlparsefilter与parse的interface.
7. 现在纪录build.xml , ivy.xml, plugin.xml
build.xml:
<project name="parse-anchor" default="jar-core">
<import file="../build-plugin.xml"/>
<!-- Deploy Unit test dependencies -->
<target name="deps-test">
<ant target="deploy" inheritall="false" dir="../nutch-extensionpoints"/>
<ant target="deploy" inheritall="false" dir="../protocol-file"/>
</target>
</project>
ivy.xml 没有import 其他,所以没有变更
plugin.xml
<plugin
id="AnchorParseFilter"
name="AnchorParseFilter Parser"
version="1.0.0"
provider-name="nutch.org">
<runtime>
<library name="parse-anchor.jar">
<export name="*"/>
</library>
</runtime>
<requires>
<import plugin="nutch-extensionpoints"/>
</requires>
<extension id=" org.apache.nutch.parse.anchor"
name="Anchor Parser"
point="org.apache.nutch.parse.HtmlParseFilter">
<implementation id="AnchorParseFilter"
class="org.apache.nutch.parse.anchor.AnchorParseFilter">
</implementation>
</extension>
</plugin>
其中要留意这个plugin 实现的HtmlParseFilter 的interface.因此point要是org.apache.nutch.parse.HtmlParseFilter
8. 在plugin的folder 下的pluginx.ml增加
<ant dir="parse-anchor" target="deploy"/>
nutch中build的时间,会调plugin下在build.xml来编译。不在plugin下的build.xml增加的时候,ant找不到parse-anchor下的build.xml进行相关编译