Apache Lucene open-source search software
update webapp demo to non deprecated usage
Mark Robert Miller974b6861622a
diff --git a/src/jsp/results.jsp b/src/jsp/results.jspindex 71c76adc351..391fd12f87c 100755--- a/src/jsp/results.jsp+++ b/src/jsp/results.jsp@@ -1,4 +1,4 @@-<%@ 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 = " 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.store.*, org.apache.lucene.search.*, org.apache.lucene.queryParser.*, org.apache.lucene.demo.*, org.apache.lucene.demo.html.Entities, java.net.URLEncoder, org.apache.lucene.util.Version" %><%/*@@ -31,18 +31,19 @@ public String escapeHTML(String s) {String indexName = indexLocation; //local copy of the configuration variableIndexSearcher searcher = null; //the searcher used to open/search the indexQuery query = null; //the Query created by the QueryParser- Hits hits = null; //the search results+ TopDocs hits = null; //the search resultsint startindex = 0; //the first index displayed on this pageint maxpage = 50; //the maximum items displayed on this pageString queryString = null; //the query entered in the previous pageString startVal = null; //string version of startindexString maxresults = null; //string version of maxpageint thispage = 0; //used for the for/next either maxpage or- //hits.length() - startindex - whichever is+ //hits.totalHits - startindex - whichever is//lesstry {- searcher = new IndexSearcher(indexName); //create an indexSearcher for our page+ IndexReader reader = IndexReader.open(FSDirectory.open(new File(indexName)), true); // only searching, so read-only=true+ searcher = new IndexSearcher(reader); //create an indexSearcher for our page//NOTE: this operation is slow for large//indices (much slower than the search itself)//so you might want to keep an IndexSearcher@@ -76,7 +77,7 @@ public String escapeHTML(String s) {//query string so you get the//treatment- Analyzer analyzer = new StandardAnalyzer(); //construct our usual analyzer+ Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT); //construct our usual analyzertry {QueryParser qp = new QueryParser("contents", analyzer);query = qp.parse(queryString); //parse the@@ -98,8 +99,8 @@ public String escapeHTML(String s) {// searcher != null was to handle// a weird compilation bugthispage = maxpage; // default last element to maxpage- hits = searcher.search(query); // run the query- if (hits.length() == 0) { // if we got no results tell the user+ hits = searcher.search(query, maxpage); // run the query+ if (hits.totalHits == 0) { // if we got no results tell the user%><p> I'm sorry I couldn't find what you were looking for. </p><%@@ -116,15 +117,15 @@ public String escapeHTML(String s) {<td>Summary</td></tr><%- if ((startindex + maxpage) > hits.length()) {- thispage = hits.length() - startindex; // set the max index to maxpage or last+ if ((startindex + maxpage) > hits.totalHits) {+ thispage = hits.totalHits - startindex; // set the max index to maxpage or last} // actual search result whichever is lessfor (int i = startindex; i < (thispage + startindex); i++) { // for each element%><tr><%- Document doc = hits.doc(i); //get the next document+ Document doc = searcher.doc(hits.scoreDocs[i].doc); //get the next documentString doctitle = doc.get("title"); //get its titleString url = doc.get("path"); //get its path fieldif (url != null && url.startsWith("../webapps/")) { // strip off ../webapps prefix if present@@ -140,7 +141,7 @@ public String escapeHTML(String s) {<%}%>-<% if ( (startindex + maxpage) < hits.length()) { //if there are more results...display+<% if ( (startindex + maxpage) < hits.totalHits) { //if there are more results...display//the more linkString moreurl="results.jsp?query=" +