search.jsp revision 510
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen<%--
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom GundersenCDDL HEADER START
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom GundersenThe contents of this file are subject to the terms of the
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom GundersenCommon Development and Distribution License (the "License").
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom GundersenYou may not use this file except in compliance with the License.
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom GundersenSee LICENSE.txt included in this distribution for the specific
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenlanguage governing permissions and limitations under the License.
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom GundersenWhen distributing Covered Code, include this CDDL HEADER in each
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenfile and include the License file at LICENSE.txt.
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom GundersenIf applicable, add the following below this CDDL HEADER, with the
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenfields enclosed by brackets "[]" replaced with your own identifying
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gunderseninformation: Portions Copyright [yyyy] [name of copyright owner]
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom GundersenCDDL HEADER END
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom GundersenCopyright 2007 Sun Microsystems, Inc. All rights reserved.
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom GundersenUse is subject to license terms.
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenident "%Z%%M% %I% %E% SMI"
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen
2b70d172a7b2ba741df7d6ca89c915e17d6f3e84Tom Gundersen--%><%@ page import = "javax.servlet.*,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenjava.lang.Integer,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenjavax.servlet.http.*,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenjava.util.Hashtable,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenjava.util.Vector,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenjava.util.Date,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenjava.util.ArrayList,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenjava.util.List,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenjava.lang.*,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenjava.io.*,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenjava.io.StringReader,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenorg.opensolaris.opengrok.analysis.*,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenorg.opensolaris.opengrok.index.IndexDatabase,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenorg.opensolaris.opengrok.search.*,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenorg.opensolaris.opengrok.web.*,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenorg.opensolaris.opengrok.search.context.*,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenorg.opensolaris.opengrok.configuration.*,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenorg.apache.lucene.search.spell.LuceneDictionary,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenorg.apache.lucene.search.spell.SpellChecker,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenorg.apache.lucene.store.FSDirectory,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenorg.apache.lucene.analysis.*,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenorg.apache.lucene.document.*,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenorg.apache.lucene.index.*,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenorg.apache.lucene.search.*,
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenorg.apache.lucene.queryParser.*"
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen%><%@ page session="false" %><%@ page errorPage="error.jsp" %><%
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom GundersenDate starttime = new Date();
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom GundersenString q = request.getParameter("q");
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom GundersenString defs = request.getParameter("defs");
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom GundersenString refs = request.getParameter("refs");
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom GundersenString hist = request.getParameter("hist");
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom GundersenString path = request.getParameter("path");
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen%><%@ include file="projects.jspf" %><%
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom GundersenString sort = null;
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenfinal String LASTMODTIME = "lastmodtime";
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenfinal String RELEVANCY = "relevancy";
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom GundersenCookie[] cookies = request.getCookies();
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenif (cookies != null) {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen for (Cookie cookie : cookies) {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen if (cookie.getName().equals("OpenGrok/sorting")) {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen sort = cookie.getValue();
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen if (!LASTMODTIME.equals(sort) && !RELEVANCY.equals(sort)) {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen sort = null;
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen }
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen break;
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen }
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen }
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen}
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom GundersenString sortParam = request.getParameter("sort");
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenif (sortParam != null) {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen if (LASTMODTIME.equals(sortParam)) {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen sort = LASTMODTIME;
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen } else if (RELEVANCY.equals(sortParam)) {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen sort = RELEVANCY;
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen }
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen if (sort != null) {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen Cookie cookie = new Cookie("OpenGrok/sorting", sort);
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen response.addCookie(cookie);
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen }
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen}
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom GundersenHits hits = null;
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom GundersenString errorMsg = null;
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenif( q!= null && q.equals("")) q = null;
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenif( defs != null && defs.equals("")) defs = null;
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenif( refs != null && refs.equals("")) refs = null;
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenif( hist != null && hist.equals("")) hist = null;
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenif( path != null && path.equals("")) path = null;
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenif (project != null && project.equals("")) project = null;
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersenif (q != null || defs != null || refs != null || hist != null || path != null) {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen Searcher searcher = null; //the searcher used to open/search the index
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen IndexReader ireader = null; //the reader used to open/search the index
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen Query query = null, defQuery = null; //the Query created by the QueryParser
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen int start = 0; //the first index displayed on this page
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen int max = 25; //the maximum items displayed on this page
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen int thispage = 0; //used for the for/next either max or
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen String moreUrl = null;
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen CompatibleAnalyser analyzer = new CompatibleAnalyser();
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen String qstr = "";
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen String result = "";
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen try {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen String DATA_ROOT = env.getDataRootPath();
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen if(DATA_ROOT.equals("")) {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen throw new Exception("DATA_ROOT parameter is not configured in web.xml!");
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen }
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen File data_root = new File(DATA_ROOT);
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen if(!data_root.isDirectory()) {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen throw new Exception("DATA_ROOT parameter in web.xml does not exist or is not a directory!");
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen }
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen //String date = request.getParameter("date");
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen try {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen start = Integer.parseInt(request.getParameter("start")); //parse the max results first
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen max = Integer.parseInt(request.getParameter("n")); //then the start index
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen if(max < 0 || (max % 10 != 0) || max > 50) max = 25;
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen if(start < 0 ) start = 0;
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen } catch (Exception e) { }
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen qstr = Util.buildQueryString(q, defs, refs, path, hist);
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen QueryParser qparser = new QueryParser("full", analyzer);
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen qparser.setDefaultOperator(QueryParser.AND_OPERATOR);
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen qparser.setAllowLeadingWildcard(env.isAllowLeadingWildcard());
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen query = qparser.parse(qstr); //parse the
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen File root = new File(RuntimeEnvironment.getInstance().getDataRootFile(),
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen "index");
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen if (RuntimeEnvironment.getInstance().hasProjects()) {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen if (project == null) {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen errorMsg = "<b>Error:</b> You must select a project!";
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen } else {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen root = new File(root, project);
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen }
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen }
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen if (errorMsg == null) {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen ireader = IndexReader.open(root);
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen searcher = new IndexSearcher(ireader);
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen if ("lastmodtime".equals(sort)) {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen hits = searcher.search(query, new Sort("date", true));
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen } else {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen hits = searcher.search(query);
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen }
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen }
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen thispage = max;
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen } catch (BooleanQuery.TooManyClauses e) {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen errorMsg = "<b>Error:</b> Too many results for wildcard!";
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen } catch (ParseException e) {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen errorMsg = "<b>Error parsing your query:</b><br/>" + Util.htmlize(qstr) +
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen "<p/>You might try to enclose your search term in quotes: <br/>" +
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen "<a href=search?q=\"" + qstr + "\">\"" + Util.htmlize(qstr) +
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen "\"</a><p/> or read the <a href=\"help.jsp\">Help</a> on query language(eventually <a href=\"help.jsp#escaping\">escape special characters</a> with <b>\\</b>)<p/>" +
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen "Error message from parser:<br/>" + Util.htmlize(e.getMessage());
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen } catch (FileNotFoundException e) {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen errorMsg = "<b>Error:</b> Index database not found";
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen } catch (Exception e) {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen errorMsg = "<b>Error:</b> " + Util.htmlize(e.getMessage());
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen }
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen // @TODO fix me. I should try to figure out where the exact hit is instead
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen // of returning a page with just _one_ entry in....
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen if (hits != null && hits.length() == 1 && request.getServletPath().equals("/s") && (query != null && query instanceof TermQuery)) {
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen String preFragmentPath = Util.URIEncodePath(context + "/xref" + hits.doc(0).get("path"));
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen String fragment = Util.URIEncode(((TermQuery)query).getTerm().text());
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen StringBuilder url = new StringBuilder(preFragmentPath);
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen url.append("#");
46b0925d4febce47d2d3b4cf83518c330730c3f6Tom Gundersen url.append(fragment);
response.sendRedirect(url.toString());
} else {
String pageTitle = "Search";
RuntimeEnvironment environment = RuntimeEnvironment.getInstance();
environment.register();
%><%@ include file="httpheader.jspf" %>
<body>
<div id="page">
<div id="header"><%@ include file="pageheader.jspf" %></div>
<div id="Masthead"></div>
<div id="bar">
<table border="0" width="100%"><tr><td><a href="<%=context%>" id="home">Home</a></td><td align="right"><%
{
StringBuffer url = request.getRequestURL();
url.append('?');
String querys = request.getQueryString();
if (querys != null) {
int idx = querys.indexOf("sort=");
if (idx == -1) {
url.append(querys);
url.append('&');
} else {
url.append(querys.substring(0, idx));
}
}
url.append("sort=");
if (sort == null || RELEVANCY.equals(sort)) {
url.append(LASTMODTIME);
%><b>Sort by relevance</b> <a href="<%=url.toString()%>">Sort by last modified time</a><%
} else {
url.append(RELEVANCY);
%><a href="<%=url.toString()%>">Sort by relevance</a> <b>Sort by last modified time</b><%
}
} %></td></tr></table>
</div>
<div id="menu">
<%@ include file="menu.jspf"%>
</div>
<div id="results">
<%
if( hits == null || errorMsg != null) {
%><%=errorMsg%><%
} else if (hits.length() == 0) {
File spellIndex = new File(env.getDataRootPath(), "spellIndex");
if (RuntimeEnvironment.getInstance().hasProjects()) {
spellIndex = new File(spellIndex, project);
}
if (spellIndex.exists()) {
FSDirectory spellDirectory = FSDirectory.getDirectory(spellIndex);
SpellChecker checker = new SpellChecker(spellDirectory);
Date sstart = new Date();
%><p><font color="#cc0000">Did you mean</font>:<%
String[] toks;
if(q != null) {
toks = q.split("[\t ]+");
if(toks != null){
for(int j=0; j<toks.length; j++) {
if(toks[j].length() > 3) {
String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 3);
for(int i = 0;i < ret.length; i++) {
%> <a href=search?q=<%=ret[i]%>><%=ret[i]%></a> &nbsp; <%
}
}
}
}
}
if(refs != null) {
toks = refs.split("[\t ]+");
if(toks != null){
for(int j=0; j<toks.length; j++) {
if(toks[j].length() > 3) {
String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 3);
for(int i = 0;i < ret.length; i++) {
%> <a href=search?q=<%=ret[i]%>><%=ret[i]%></a> &nbsp; <%
}
}
}
}
}
if(defs != null) {
toks = defs.split("[\t ]+");
if(toks != null){
for(int j=0; j<toks.length; j++) {
if(toks[j].length() > 3) {
String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 3);
for(int i = 0;i < ret.length; i++) {
%> <a href=search?q=<%=ret[i]%>><%=ret[i]%></a> &nbsp; <%
}
}
}
}
}
spellDirectory.close();
%></p><%
}
%><p> Your search <b><%=query.toString()%></b> did not match any files.
<br />
Suggestions:<br/><blockquote>- Make sure all terms are spelled correctly.<br/>
- Try different keywords.<br/>
- Try more general keywords.<br/>
- Use 'wil*' cards if you are looking for partial match.
</blockquote>
</p><%
} else { // We have a lots of results to show
StringBuilder slider = null;
if ( max < hits.length()) {
if((start + max) < hits.length()) {
thispage = max;
} else {
thispage = hits.length() - start;
}
String url = (q == null ? "" : "&amp;q=" + Util.URIEncode(q) ) +
(defs == null ? "" : "&amp;defs=" + Util.URIEncode(defs)) +
(refs == null ? "" : "&amp;refs=" + Util.URIEncode(refs)) +
(path == null ? "" : "&amp;path=" + Util.URIEncode(path)) +
(hist == null ? "" : "&amp;hist=" + Util.URIEncode(hist)) +
(sort == null ? "" : "&amp;sort=" + Util.URIEncode(sort)) +
(project == null ? "" : "&amp;project=" + Util.URIEncode(project));
slider = new StringBuilder();
int labelStart =1;
int sstart = start - max* (start / max % 10 + 1) ;
if(sstart < 0) {
sstart = 0;
labelStart = 1;
} else {
labelStart = sstart/max + 1;
}
int label = labelStart;
int labelEnd = label + 11;
String arr;
for(int i=sstart; i<hits.length() && label <= labelEnd; i+= max) {
if (i <= start && start < i+ max) {
slider.append("<span class=\"sel\">" + label + "</span>");
} else {
if(label == labelStart && label != 1) {
arr = "&lt;&lt";
} else if(label == labelEnd && i < hits.length()) {
arr = "&gt;&gt;";
} else {
arr = label < 10 ? " " + label : String.valueOf(label);
}
slider.append("<a class=\"more\" href=\"search?n=" + max + "&amp;start=" + i + url + "\">"+
arr + "</a>");
}
label++;
}
} else {
thispage = hits.length() - start; // set the max index to max or last
}
%>&nbsp; &nbsp; Searched <b><%=query.toString()%></b> (Results <b><%=start+1%> -
<%=thispage+start%></b> of <b><%=hits.length()%></b>) sorted by <%=sort%> <p><%=slider != null ?
slider.toString(): ""%></p>
<table width="100%" cellpadding="3" cellspacing="0" border="0"><%
Context sourceContext = null;
Summarizer summer = null;
if (query != null) {
try{
sourceContext = new Context(query);
if(sourceContext != null)
summer = new Summarizer(query, analyzer);
} catch (Exception e) {
}
}
HistoryContext historyContext = null;
try {
historyContext = new HistoryContext(query);
} catch (Exception e) {
}
EftarFileReader ef = null;
try{
ef = new EftarFileReader(env.getDataRootPath() + "/index/dtags.eftar");
} catch (Exception e) {
}
Results.prettyPrintHTML(hits, start, start+thispage,
out,
sourceContext, historyContext, summer,
context + "/xref",
context + "/more",
env.getSourceRootPath(),
env.getDataRootPath(),
ef);
if(ef != null) {
try{
ef.close();
} catch (IOException e) {
}
}
%></table><br/>
<b> Completed in <%=(new Date()).getTime() - starttime.getTime()%> milliseconds </b> <br/>
<%=slider != null ? "<p>" + slider + "</p>" : ""%>
<%
}
%><br/></div><%@include file="foot.jspf"%><%
}
if (ireader != null)
ireader.close();
} else { // Entry page show the map
response.sendRedirect(context + "/index.jsp");
}
%>