nutch对中文的支持还不完善,需要修改tomcat 文件夹下
conf/server.xml文件
[root@localhost tomcat]#vi conf/server.xml
增加两句,修改为
<Connector port="8080"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true"
URIEncoding="UTF-8" useBodyEncodingForURI="true" />
1.网页快照乱码问题
Nutch的网页快照是乱码,解决办法是修改tomcat/webapps/nutch目录下的cached.jsp文件,修改其中的第63行。
原来的代码是:content = new String(bean.getContent(details);
修改后的代码是:content = new String(bean.getContent(details),"gb2312");
2.搜索结果高亮显示
Nutch默认的搜索结果是没有高亮的,解决办法是在关键词中加入html颜色标签。
将 org.apache.nutch.searcher.Summary 第107行 代码 修改为:
public String toString() {
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < fragments.size(); i++) {
buffer.append(fragments.get(i));
}
return "<span style='color:red'>" + buffer.toString()+ "</span>";
}
3.抓取页面大小
Nutch默认只抓取一个页面的前65k的内容,在我抓取bbs的时候,会出现只能抓取前几个回帖的内容,所以想抓取整个页面的内容,就要解除65k的限制。解决方法是修改nutch/conf中的nutch-site.xml文件,在文件最后添加以下内容:
<property>
<name>http.content.limit</name>
<value>-1</value>
<description>The length limit for downloaded content, in bytes.
If this value is nonnegative (>=0), content longer than it will be truncated;
otherwise, no truncation at all.
</description>
</property>
本文介绍如何针对中文环境优化Nutch的配置,包括解决网页快照乱码、实现搜索结果高亮及调整抓取页面大小限制。
1390

被折叠的 条评论
为什么被折叠?



