我做了一个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
那个片段部署和手动发布是什么意思