欢迎光临
我们一直在努力

有关jive论坛搜索中文化的支持详解!-JSP教程,Java技巧及代码

建站超值云服务器,限时71元/月

jive的搜索借用了apche提供的lucene搜索引擎。lucene是一个纯java的高性能的全文搜索引擎,你可以到apache的网站找到lucene的更多信息:http://jakarta.apache.org/lucene/docs/index.html

但在jive使用的lucene包中,并不支持中文搜索,本站的系统也是构建在jive之上进行扩展,中文搜索问题由jr管理系统主要开发人员之一cherami解决。很多关注jive的朋友都来信向我们索取jive中文搜索问题的解决方法,我在这儿把我们的解决方法整理出来,希望能够给您提供帮助。1. 下载lucene中文搜索支持包将lucene_cn.jar放到您的lib目录下。

2:修改您的dbsearchmanager.java在com.jivesoftware.forum.database.dbsearchmanager.java中,首先导入lucene中文包:

import org.apache.lucene.analysis.cn.*;

在dbsearchmanager.java中找到如下代码:

    /**     * the analyzer governs how words are tokenized. the standard anaylyzer     * does a decent job in most cases, but could be replaced under certain     * circumstances. we make the analyzer protected so that the dbquery class     * can also reference it (indexing and searching should use the same     * analyzer).     */    protected static analyzer analyzer = new standardanalyzer();

替换为:

    protected static analyzer analyzer = new chineseanalyzer();

3. 重启jive,现在你的jive即支持中文搜索了。

4. 其它问题

要使用中文搜索,您的搜索的jsp的页面也需要使用gb2312的编码方式:<%@ page contenttype="text/html; charset=gb2312" %>在我们的实现中,还遇到一个问题。就是在搜索时,如果直接在search.jsp页面中使用可以正常,但如果是从另外一个页面的搜索框中跳转到search.jsp页面,则搜索输入框中的所有的中文字符都变成“?”了。这个问题是和平台有关的,引起原因很复杂。我的解决方法是在search.jsp中得到查询串时,可以参考使用:

    java.net.urlencoder.encode(querytext,"gb2312");

5:最后总结:     对于中文搜索还需要修改两个jsp页面:search.jsp以及post.jsp将其中的:java.net.urlencoder.encode(querytext)、urlencoder.encode(url.tostring())、java.net.urlencoder.encode(postlink.tostring())、urlencoder.encode(name)、urlencoder.encode(email)都在其encode()里面加入,"gbk"即可使你的jivc论坛完全支持中文化的搜索了。

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 有关jive论坛搜索中文化的支持详解!-JSP教程,Java技巧及代码
分享到: 更多 (0)