Encountered "<EOF>" at line 1, column 0.
Was expecting one of:
<NOT> ...
"+" ...
"-" ...
"(" ...
<QUOTED> ...
<TERM> ...
<PREFIXTERM> ...
<WILDTERM> ...
<RANGEIN> ...
<RANGEEX> ...
<NUMBER> ...public class Results
extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
} //Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String QC = request.getParameter("QueryContent");
if (QC == null) {
QC = "";
}
else {
QC = input(QC);
}
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
try {
Search(QC, out);
}
catch (Exception ex) {
System.out.println(ex.getMessage());
}
} public void Search(String qc, PrintWriter out) throws Exception {
// 从索引目录创建索引
IndexSearcher _searcher = new IndexSearcher("c:\\news\\index");
// 创建标准分析器
Analyzer analyzer = new ChineseAnalyzer();
// 查询条件
String line = qc;
// Query是一个抽象类
Query query = QueryParser.parse(line, "title", analyzer); out.println("<html>");
out.println("<head><title>搜索结果</title></head>");
out.println("<body bgcolor=#ffffff>");
out.println("<center>" +
"<form action='/NewsServer/results' method='get'>" +
"<font face='华文中宋' color='#3399FF'>新闻搜索引擎</font>:" +
"<input type='text' name='QueryContent' size='20'>" +
"<input type='submit' name='submit' value='开始搜索'>" +
"</form></center>"
);
out.println("<p>搜索关键字:<font color=red>" + query.toString("title") +
"</font></p>");
Hits hits = _searcher.search(query);
out.println(" 总共找到<font color=red>" + hits.length() + "</font>条新闻<br>"); final int HITS_PER_PAGE = 10;
for (int start = 0; start < hits.length(); start += HITS_PER_PAGE) {
int end = Math.min(hits.length(), start + HITS_PER_PAGE);
for (int i = start; i < end; i++) {
Document doc = hits.doc(i);
String url = doc.get("url");
if (url != null) {
out.println( (i + 1) + " <a href='" + url + "'>" +
replace(doc.get("title"), qc) +
"</a><br>");
}
else {
System.out.println("没有找到!");
}
}
}
out.println("</body></html>");
_searcher.close();
}; public String input(String str) {
String temp = null;
if (str != null) {
try {
temp = new String(str.getBytes("ISO8859_1"));
}
catch (Exception e) {
}
}
return temp;
} public String replace(String title, String keyword) {
return title.replaceAll(keyword, "<font color='red'>" + keyword + "</font>");
}; //Clean up resources
public void destroy() {
}
Was expecting one of:
<NOT> ...
"+" ...
"-" ...
"(" ...
<QUOTED> ...
<TERM> ...
<PREFIXTERM> ...
<WILDTERM> ...
<RANGEIN> ...
<RANGEEX> ...
<NUMBER> ...public class Results
extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
} //Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String QC = request.getParameter("QueryContent");
if (QC == null) {
QC = "";
}
else {
QC = input(QC);
}
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
try {
Search(QC, out);
}
catch (Exception ex) {
System.out.println(ex.getMessage());
}
} public void Search(String qc, PrintWriter out) throws Exception {
// 从索引目录创建索引
IndexSearcher _searcher = new IndexSearcher("c:\\news\\index");
// 创建标准分析器
Analyzer analyzer = new ChineseAnalyzer();
// 查询条件
String line = qc;
// Query是一个抽象类
Query query = QueryParser.parse(line, "title", analyzer); out.println("<html>");
out.println("<head><title>搜索结果</title></head>");
out.println("<body bgcolor=#ffffff>");
out.println("<center>" +
"<form action='/NewsServer/results' method='get'>" +
"<font face='华文中宋' color='#3399FF'>新闻搜索引擎</font>:" +
"<input type='text' name='QueryContent' size='20'>" +
"<input type='submit' name='submit' value='开始搜索'>" +
"</form></center>"
);
out.println("<p>搜索关键字:<font color=red>" + query.toString("title") +
"</font></p>");
Hits hits = _searcher.search(query);
out.println(" 总共找到<font color=red>" + hits.length() + "</font>条新闻<br>"); final int HITS_PER_PAGE = 10;
for (int start = 0; start < hits.length(); start += HITS_PER_PAGE) {
int end = Math.min(hits.length(), start + HITS_PER_PAGE);
for (int i = start; i < end; i++) {
Document doc = hits.doc(i);
String url = doc.get("url");
if (url != null) {
out.println( (i + 1) + " <a href='" + url + "'>" +
replace(doc.get("title"), qc) +
"</a><br>");
}
else {
System.out.println("没有找到!");
}
}
}
out.println("</body></html>");
_searcher.close();
}; public String input(String str) {
String temp = null;
if (str != null) {
try {
temp = new String(str.getBytes("ISO8859_1"));
}
catch (Exception e) {
}
}
return temp;
} public String replace(String title, String keyword) {
return title.replaceAll(keyword, "<font color='red'>" + keyword + "</font>");
}; //Clean up resources
public void destroy() {
}
解决方案 »
- 使用HibernateTemplagte发生异常时事务没有回滚
- struts2和json集成编码问题
- textarea空提交servlet得到的是什么值
- 问题: 在jsp 页面接收参数的时候 怎么把一个String类型 转换成 DATE类型?
- JFreeChart ant javadoc失败
- java多线程如何停止一个线程
- This JDBC 2.0 method is not implemented
- 紧急求救,SOCKET方面的问题,如何用JAVA编写SOCKET与银行直联,包括拆包,组包,及何谓包头,谢谢
- 请问如何配置jboss以使客户端也可以访问其jndi上的数据源??!!
- 面试题:==和equals()的区别
- 急!!Hibernate查询出来的数据与数据库中的不一样???!!!
- Combobox选取值问题
=>
QueryParser parser = new QueryParser("title", analyzer);
Query query = parser.parse(line);