Lucene index page for examples
Abstract: Lucene index page for examples
</ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width = "100%" border = "0" cellspacing = "0" cellpadding = " 0 "> <tr> <td width="269" height="86" align="center" valign="top"> </ td> <td width="415" valign="top"> a key input word lucene.html
<body>
<form Name="form1" method="post" action="search.jsp">
Enter keyword: <input type = "text" name = "keyword">
<input Type="submit" name="Submit" value="æäº¤">
</ Form>
</ Body>
Drawings:
</ Td> </ tr> <tr> <td height="20" colspan="2">
Second, the search and displays the results search.jsp <% @ page contentType = "text / html; gb2312 charset ="%>
<% @ Page import = "java.util .*"%>
<% @ Page import = "java.text.SimpleDateFormat"%>
<% @ Page import = "org.apache.lucene.analysis.standard.StandardAnalyzer"%>
<% @ Page import = "org.apache.lucene.index.IndexReader"%>
<% @ Page import = "org.apache.lucene.document.Document"%>
<% @ Page import = "org.apache.lucene.search.IndexSearcher"%>
<% @ Page import = "org.apache.lucene.search.Hits"%>
<% @ Page import = "org.apache.lucene.search.Query"%>
<% @ Page import = "page.Pagination"%> <% @ page import = "org.apache.lucene.queryParser.QueryParser"%>
<% @ Page import = "org.apache.lucene.analysis.Analyzer"%>
<%
String queryString = request.getParameter ( "keyword"); if (queryString == null | | queryString.length () == 0) (out.println ( "Search keywords can not be empty");) else (= new queryString String (queryString.getBytes ( "ISO8859_1")); String indexPath = getServletContext (). getRealPath ("/")+" index "; boolean error = false; Document doc; IndexSearcher searcher = null; Query query = null; Hits hits = null; try (searcher = new IndexSearcher (IndexReader.open (indexPath));) catch (Exception e) (out.print ( "did not find index files!"); out.print (e.getMessage ()); error = true;) if (error == false) (Analyzer analyzer = new StandardAnalyzer (); query try (= QueryParser.parse (queryString, "Article_name" analyzer);) catch (Exception e) (out.print (e. getMessage ()); error = true;)) if (error == false & searcher! = null) (hits = searcher.search (query) if (hits.length () == 0) (out.print ( " Sorry! did not find the resources you need. "); error = true;)) if (error == false & searcher! = null) (out.print (" Search keywords: "+ + queryString" "); / / Pagination is the downloading, and we need to pass along a vector, you can change, and this is not done two times Vector list = new Vector (); for (int i = 0; i <hits.length (); i + +) (doc = hits.doc (i); list.add (doc);) out.print ( "find resources"); Pagination pagination = null; String pageNumber = request.getParameter ( "pageNumber"); int showItemNumber = 10; if (pageNumber == null) (pageNumber = "1";) String HTML = ""; if (list! = null & list.size ()> 0) (pagination = new Pagination (); pagination.setPageNumber (Integer.parseInt (pageNumber)); pagination.setShowItemNumber (showItemNumber); pagination.setVisitPageURL ( "search.jsp? keyword =" + queryString); list = (Vector) pagination.interceptListByStarItemNumber (list) for (int i = 0; i <list . size (); i + +) (doc = (Document) list.get (i); String A_id = doc.get ( "Article_id"); String doctitle = doc.get ( "Article_name"); String url = doc.get ( "File_name ")+"? id =" + A_id; out.print ( "<a href = 'http://127.0.0.1:8080/cwbwebhome/" + url +"'>( ★) "+ + doctitle" " );) = pagination.buildHTML HTML ( "600"); out.print (HTML);)))
Figure effect:
Thirdly, a paging class Pagination.java (download)
</ Td> </ tr> </ table> </ td> </ tr> <tr>
↑ Back






