sungnam_kim 2009-03-19 13:15
浏览 220
已采纳

中文分词器问题

我做了一个lucene的中文分词器, 但是当把它替换到IndexHtml的StandardAnalyzer的时候
程序是可以跑了。
但是用tomcat6。0去查询结果时出现了这样的错误。


An error occurred at line: 18 in the generated java file
Only a type can be imported. analyzer.ChineseAnalyzer resolves to a package

An error occurred at line: 81 in the jsp file: /results.jsp
ChineseAnalyzer cannot be resolved to a type
78:                                                                       //query string so you get the
79:                                                                       //treatment
80:
81:                 Analyzer analyzer = new ChineseAnalyzer();           //construct our usual analyzer
82:                 try {
83:                         QueryParser qp = new QueryParser("contents", analyzer);
84:                         query = qp.parse(queryString); //parse the

 

在这里tomcat 的webapps\luceneweb里面的 result.jsp里添加了这两行

 

<%@ page language="java" contentType="text/html; charset=GBK" %>


<%@ page import = "  javax.servlet.*, javax.servlet.http.*, java.io.*, org.apache.lucene.analysis.*,org.apache.lucene.analysis.standard.StandardAnalyzer, org.apache.lucene.document.*, org.apache.lucene.index.*, org.apache.lucene.search.*, org.apache.lucene.queryParser.*, org.apache.lucene.demo.*, org.apache.lucene.demo.html.Entities, java.net.URLEncoder" %>


<%@ page import="analyzer.ChineseAnalyzer, init.* " %>


谢谢。。。


问题补充:
我想在这里在补充一点。。
我的系统是ubuntu。
还有我这里没有web-inf/classes, 只是在bin里面有class。
根据提示之前也做过,
尤其是想刚才那样analyzer.*之后报错就不一样了

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 81 in the jsp file: /results.jsp
ChineseAnalyzer cannot be resolved to a type
78:                                                                       //query string so you get the
79:                                                                       //treatment
80:
81:                 Analyzer analyzer = new ChineseAnalyzer();           //construct our usual analyzer
82:                 try {
83:                         QueryParser qp = new QueryParser("contents", analyzer);
84:                         query = qp.parse(queryString); //parse the

我的result.jsp  /tomcat/webapps/luceneweb/里
问题补充:
能详细的说明一下吗?
我的是lucene-core-2.1.0
我的分析器是这样的
项目里面一共有四个包:
src:
analyzer\ ChineseAnalyzer.java  ChineseTokenizer.java
init\ Dictionary.java Seperator.java, StopWord.java
org.apache.lucene.demo\IndexHTML.java
org.apache.lucene.demo.html<br />问题补充:
还是不能解决。
报错还是一样的。
问题补充:
我这个原本是在windows里面做过的
这个跟linux一样。
就是之前在用StandardAnalyzer的时候是可以的。
就是当该一个中文分析器后把tomCat里面的jsp需要改动一下
不过就在那里出现了问题。
我把范例上传。。。帮一下忙好吗?
问题补充:
回:jianghuidong

我的代码是这样的。
不过就是有上面的错误。

==========

if (error == false) {                                           //did we open the index?
                queryString = new String(request.getParameter("query").getBytes("iso8859-1"));           //get the search criteria
                startVal    = request.getParameter("startat");         //get the start index
                maxresults  = request.getParameter("maxresults");      //get max results per page
                try {
                        maxpage    = Integer.parseInt(maxresults);    //parse the max results first
                        startindex = Integer.parseInt(startVal);      //then the start index 
                } catch (Exception e) { } //we don't care if something happens we'll just start at 0
                                          //or end at 50

               

                if (queryString == null)
                        throw new ServletException("no query "+       //if you don't have a query then
                                                   "specified");      //you probably played on the
                                                                      //query string so you get the
                                                                      //treatment

                Analyzer analyzer = new ChineseAnalyzer();           //construct our usual analyzer
                try {
                        QueryParser qp = new QueryParser("contents", analyzer);
                        query = qp.parse(queryString); //parse the
                } catch (ParseException e) {                          //query and construct the Query
                                                                      //object
                                                                      //if it's just "operator error"
                                                                      //send them a nice error HTML
                                                                     
%>
                        <p>Error while parsing query: <%=escapeHTML(e.getMessage())%></p>
<%
                        error = true;                                 //don't bother with the rest of
                                                                      //the page
                }
        }
问题补充:
回jianghuidong

那个你写的代码是什么意思
问题补充:
回: iampurse

那个片段部署和手动发布是什么意思
  • 写回答

9条回答 默认 最新

  • playfish05 2009-03-19 14:59
    关注

    analyzer\ ChineseAnalyzer.java ChineseTokenizer.java

    你的jsp是不是可以找到org.apache.lucene.demo\IndexHTML.java这个类?如果可以的话,你试试把2个java文件放到这里编译成class。

    然后再看看jsp能否调用得到

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(8条)

报告相同问题?

悬赏问题

  • ¥100 c语言,请帮蒟蒻看一个题
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)