Apache Nutch 为 RSS Feed 中的每个项目创建一个文档
Apache Nutch one document for each item in RSS Feed
我正在尝试使用 Apache Nutch 构建一个应用程序,该应用程序将多个文档添加到数据库中,一个用于 RSS Feed 中的每个项目。
根据我的理解,现在它解析提要时,会创建一个唯一的 Solr 文档,所有内容都串联在一起
<item>
<title>Comment 1</title>
<link>http://www.link.com/a/#comment-2555842742</link>
<description>document text1</description>
<dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">12321 Borland</dc:creator>
<pubDate>Mon, 07 Mar 2016 06:48:35 -0000</pubDate>
</item>
<item>
<title>>Comment 2</title>
<link>http://www.link.com/a/#comment-2555590727</link>
<description>document text2</description>
<dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">12321</dc:creator>
<pubDate>Mon, 07 Mar 2016 00:48:34 -0000</pubDate>
</item>
相反,我希望能够 return 2 个 ParseResult 而不是只有一个:Feed 中的每个项目一个
默认情况下,RSS 提要由 parse-tika
插件解析,请参阅 https://github.com/apache/nutch/blob/master/conf/parse-plugins.xml#L31-L34,它默认将 RSS 提要内的链接标识为原始提要 URL 的外链。然后存储此外链以供以后获取、解析等。如果您 运行 命令可以检查此内容:
$ bin/nutch parsechecker http://humanos.uci.cu/feed/
输出应该是这样的:
...
---------
Url
---------------
http://humanos.uci.cu/feed/
---------
ParseData
---------
Version: 5
Status: success(1,0)
Title: humanOS
Outlinks: 10
...
这基本上报告了 1 URL 已成功解析并找到了 10 个外链。
要获得所需的输出,您需要使用 feed
插件。因此,首先,在 nutch-site.xml
文件的 plugin.include
属性中激活 feed
插件。
完成此操作后,您仍然需要指示 Nutch 首先使用 feed
解析器(它使用下面的 ROME 库)。要完成此操作,请编辑 conf/parse-plugins.xml
文件,找到条目:<mimeType name="application/rss+xml">
并将其保留为:
<mimeType name="application/rss+xml">
<plugin id="feed" />
<plugin id="parse-tika" />
</mimeType>
在这种情况下,如果您再次尝试 parsechecker
命令,输出将有所不同,一旦您索引到 Solr/ES,您应该会看到更多文档:1 个用于原始提要,另外一个用于每个提要Feed 中的项目。
请记住,此新文档的 content
字段只有从 Feed 中提取的 description
字段,这可能相当不完整。
如果您需要编写更自定义的逻辑,ParseResult
class 允许有 "subdocuments" (https://github.com/apache/nutch/blob/master/src/java/org/apache/nutch/parse/ParseResult.java#L30-L41)。
我正在尝试使用 Apache Nutch 构建一个应用程序,该应用程序将多个文档添加到数据库中,一个用于 RSS Feed 中的每个项目。
根据我的理解,现在它解析提要时,会创建一个唯一的 Solr 文档,所有内容都串联在一起
<item>
<title>Comment 1</title>
<link>http://www.link.com/a/#comment-2555842742</link>
<description>document text1</description>
<dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">12321 Borland</dc:creator>
<pubDate>Mon, 07 Mar 2016 06:48:35 -0000</pubDate>
</item>
<item>
<title>>Comment 2</title>
<link>http://www.link.com/a/#comment-2555590727</link>
<description>document text2</description>
<dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">12321</dc:creator>
<pubDate>Mon, 07 Mar 2016 00:48:34 -0000</pubDate>
</item>
相反,我希望能够 return 2 个 ParseResult 而不是只有一个:Feed 中的每个项目一个
默认情况下,RSS 提要由 parse-tika
插件解析,请参阅 https://github.com/apache/nutch/blob/master/conf/parse-plugins.xml#L31-L34,它默认将 RSS 提要内的链接标识为原始提要 URL 的外链。然后存储此外链以供以后获取、解析等。如果您 运行 命令可以检查此内容:
$ bin/nutch parsechecker http://humanos.uci.cu/feed/
输出应该是这样的:
...
---------
Url
---------------
http://humanos.uci.cu/feed/
---------
ParseData
---------
Version: 5
Status: success(1,0)
Title: humanOS
Outlinks: 10
...
这基本上报告了 1 URL 已成功解析并找到了 10 个外链。
要获得所需的输出,您需要使用 feed
插件。因此,首先,在 nutch-site.xml
文件的 plugin.include
属性中激活 feed
插件。
完成此操作后,您仍然需要指示 Nutch 首先使用 feed
解析器(它使用下面的 ROME 库)。要完成此操作,请编辑 conf/parse-plugins.xml
文件,找到条目:<mimeType name="application/rss+xml">
并将其保留为:
<mimeType name="application/rss+xml">
<plugin id="feed" />
<plugin id="parse-tika" />
</mimeType>
在这种情况下,如果您再次尝试 parsechecker
命令,输出将有所不同,一旦您索引到 Solr/ES,您应该会看到更多文档:1 个用于原始提要,另外一个用于每个提要Feed 中的项目。
请记住,此新文档的 content
字段只有从 Feed 中提取的 description
字段,这可能相当不完整。
如果您需要编写更自定义的逻辑,ParseResult
class 允许有 "subdocuments" (https://github.com/apache/nutch/blob/master/src/java/org/apache/nutch/parse/ParseResult.java#L30-L41)。