search.jsp revision 66
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Graff<%--
c46bcd7c6908745e19b0b1fe18a23bbaaee553edBob HalleyCDDL HEADER START
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Graff
1840745dd553b2ff5b114a03cde40a2a404aa559Michael GraffThe contents of this file are subject to the terms of the
1840745dd553b2ff5b114a03cde40a2a404aa559Michael GraffCommon Development and Distribution License (the "License").
1840745dd553b2ff5b114a03cde40a2a404aa559Michael GraffYou may not use this file except in compliance with the License.
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Graff
1840745dd553b2ff5b114a03cde40a2a404aa559Michael GraffSee LICENSE.txt included in this distribution for the specific
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Grafflanguage governing permissions and limitations under the License.
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Graff
1840745dd553b2ff5b114a03cde40a2a404aa559Michael GraffWhen distributing Covered Code, include this CDDL HEADER in each
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Grafffile and include the License file at LICENSE.txt.
1840745dd553b2ff5b114a03cde40a2a404aa559Michael GraffIf applicable, add the following below this CDDL HEADER, with the
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Grafffields enclosed by brackets "[]" replaced with your own identifying
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Graffinformation: Portions Copyright [yyyy] [name of copyright owner]
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Graff
1840745dd553b2ff5b114a03cde40a2a404aa559Michael GraffCDDL HEADER END
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Graff
1840745dd553b2ff5b114a03cde40a2a404aa559Michael GraffCopyright 2005 Sun Microsystems, Inc. All rights reserved.
1840745dd553b2ff5b114a03cde40a2a404aa559Michael GraffUse is subject to license terms.
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Graff
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Graffident "%Z%%M% %I% %E% SMI"
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Graff
b8257bd2d872546e7cc358fdf32331ce8850bca4Bob Halley--%><%@ page import = "javax.servlet.*,
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Graffjava.lang.Integer,
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafssonjavax.servlet.http.*,
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Graffjava.util.Hashtable,
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafssonjava.util.Vector,
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Graffjava.util.Date,
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Graffjava.util.ArrayList,
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Graffjava.util.List,
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafssonjava.lang.*,
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Graffjava.io.*,
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafssonjava.io.StringReader,
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafssonorg.opensolaris.opengrok.analysis.*,
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Grafforg.opensolaris.opengrok.search.*,
440be4c866f6935ac069db79a414304507a664c2Michael Grafforg.opensolaris.opengrok.web.*,
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Grafforg.opensolaris.opengrok.web.*,
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafssonorg.opensolaris.opengrok.search.context.*,
fd15c8e32ed0c1cfd3ed737858a81966e7fbaeacAndreas Gustafssonorg.opensolaris.opengrok.configuration.*,
c6e10b826ec1df8da01a7b1b4620d7e0adfcb247James Bristerorg.apache.lucene.spell.*,
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafssonorg.apache.lucene.analysis.*,
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafssonorg.apache.lucene.document.*,
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafssonorg.apache.lucene.index.*,
173b32c660c1e4d5141b5ca740e8fab3c593652fBob Halleyorg.apache.lucene.search.*,
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Grafforg.apache.lucene.queryParser.*"
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Graff%><%@ page session="false" %><%@ page errorPage="error.jsp" %><%
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas GustafssonDate starttime = new Date();
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas GustafssonString q = request.getParameter("q");
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas GustafssonString defs = request.getParameter("defs");
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas GustafssonString refs = request.getParameter("refs");
173b32c660c1e4d5141b5ca740e8fab3c593652fBob HalleyString hist = request.getParameter("hist");
c6e10b826ec1df8da01a7b1b4620d7e0adfcb247James BristerString path = request.getParameter("path");
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Graff%>
b03758b04ea5134c805d44fcc5315c878c6f7996Andreas Gustafsson<%@ include file="projects.jspf" %>
533b0475054882ea1c81cb1ec4aa3e6750711bbcBob Halley<%
a55d0a9080c8ef4117d2fc27f63220a56afb2434Andreas Gustafsson
a55d0a9080c8ef4117d2fc27f63220a56afb2434Andreas GustafssonHits hits = null;
a4b6a1622b1b6672a6e0c7186167bbe3997568c6Bob HalleyString errorMsg = null;
92583b722bfdcc5714dfd77711c54fee55f51c5dBob HalleyString context = request.getContextPath();
533b0475054882ea1c81cb1ec4aa3e6750711bbcBob Halley
a55d0a9080c8ef4117d2fc27f63220a56afb2434Andreas Gustafssonif( q!= null && q.equals("")) q = null;
1840745dd553b2ff5b114a03cde40a2a404aa559Michael Graffif( defs != null && defs.equals("")) defs = null;
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafssonif( refs != null && refs.equals("")) refs = null;
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafssonif( hist != null && hist.equals("")) hist = null;
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafssonif( path != null && path.equals("")) path = null;
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafssonif (project == null) project = null;
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafssonif (q != null || defs != null || refs != null || hist != null || path != null) {
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson Searcher searcher = null; //the searcher used to open/search the index
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson IndexReader ireader = null; //the reader used to open/search the index
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson Query query = null, defQuery = null; //the Query created by the QueryParser
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson int start = 0; //the first index displayed on this page
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson int max = 25; //the maximum items displayed on this page
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson int thispage = 0; //used for the for/next either max or
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson String moreUrl = null;
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson CompatibleAnalyser analyzer = new CompatibleAnalyser();
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson String qstr = "";
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson String result = "";
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson try {
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson String DATA_ROOT = env.getDataRootPath();
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson if(DATA_ROOT.equals("")) {
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson throw new Exception("DATA_ROOT parameter is not configured in web.xml!");
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson }
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson File data_root = new File(DATA_ROOT);
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson if(!data_root.isDirectory()) {
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson throw new Exception("DATA_ROOT parameter in web.xml does not exist or is not a directory!");
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson }
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson ireader = IndexReader.open(DATA_ROOT + "/index");
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson searcher = new IndexSearcher(ireader);
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley //String date = request.getParameter("date");
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley try {
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley start = Integer.parseInt(request.getParameter("start")); //parse the max results first
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson max = Integer.parseInt(request.getParameter("n")); //then the start index
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley if(max < 0 || (max % 10 != 0) || max > 50) max = 25;
c6e10b826ec1df8da01a7b1b4620d7e0adfcb247James Brister if(start < 0 ) start = 0;
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson } catch (Exception e) { }
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson StringBuilder sb = new StringBuilder();
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson if (q != null) {
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson sb.append(q);
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson }
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley if (defs != null) {
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson sb.append(" defs:(");
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley sb.append(defs);
fd15c8e32ed0c1cfd3ed737858a81966e7fbaeacAndreas Gustafsson sb.append(")");
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley }
8f79820c6930ee5ef6b4a54f36d2559400bdf47dAndreas Gustafsson
bf08eb90e44ed8717d538442600c4ad11adac61dBrian Wellington if (refs != null) {
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley sb.append(" refs:(");
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson sb.append(refs);
173b32c660c1e4d5141b5ca740e8fab3c593652fBob Halley sb.append(")");
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley }
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley if (path != null) {
fd15c8e32ed0c1cfd3ed737858a81966e7fbaeacAndreas Gustafsson sb.append(" path:(");
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson sb.append(path);
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson sb.append(")");
fd15c8e32ed0c1cfd3ed737858a81966e7fbaeacAndreas Gustafsson }
8f79820c6930ee5ef6b4a54f36d2559400bdf47dAndreas Gustafsson
8f79820c6930ee5ef6b4a54f36d2559400bdf47dAndreas Gustafsson if (hist != null) {
8f79820c6930ee5ef6b4a54f36d2559400bdf47dAndreas Gustafsson sb.append(" hist:(");
fd15c8e32ed0c1cfd3ed737858a81966e7fbaeacAndreas Gustafsson sb.append(hist);
325c88703c78ddb975994f7123ab4f93b6650a87Bob Halley sb.append(")");
73ca2fa48635c5386b4df809ee6ae9a51bb6c8b3Bob Halley }
73ca2fa48635c5386b4df809ee6ae9a51bb6c8b3Bob Halley
73ca2fa48635c5386b4df809ee6ae9a51bb6c8b3Bob Halley if (project != null) {
73ca2fa48635c5386b4df809ee6ae9a51bb6c8b3Bob Halley sb.append(" (");
73ca2fa48635c5386b4df809ee6ae9a51bb6c8b3Bob Halley
73ca2fa48635c5386b4df809ee6ae9a51bb6c8b3Bob Halley boolean first = true;
73ca2fa48635c5386b4df809ee6ae9a51bb6c8b3Bob Halley for (String s : project.split(" ")) {
73ca2fa48635c5386b4df809ee6ae9a51bb6c8b3Bob Halley if (first) {
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson first = false;
73ca2fa48635c5386b4df809ee6ae9a51bb6c8b3Bob Halley } else {
73ca2fa48635c5386b4df809ee6ae9a51bb6c8b3Bob Halley sb.append(" OR ");
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley }
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley sb.append("project:(");
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley sb.append(s);
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley sb.append(")");
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley }
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson sb.append(")");
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson }
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson
173b32c660c1e4d5141b5ca740e8fab3c593652fBob Halley qstr = sb.toString();
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley QueryParser qparser = new QueryParser("full", analyzer);
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley qparser.setOperator(QueryParser.DEFAULT_OPERATOR_AND);
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson query = qparser.parse(qstr); //parse the
206a60c0d78303feaf407eb8806c60dd34aabb0bAndreas Gustafsson hits = searcher.search(query);
173b32c660c1e4d5141b5ca740e8fab3c593652fBob Halley thispage = max;
bf08eb90e44ed8717d538442600c4ad11adac61dBrian Wellington } catch (BooleanQuery.TooManyClauses e) {
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson errorMsg = "<b>Error:</b> Too many results for wildcard!";
bf08eb90e44ed8717d538442600c4ad11adac61dBrian Wellington } catch (ParseException e) {
bf08eb90e44ed8717d538442600c4ad11adac61dBrian Wellington errorMsg = "<b>Error:</b><br/>" + Util.Htmlize(qstr) + "<br/>" + Util.Htmlize(e.getMessage());
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson } catch (FileNotFoundException e) {
bf08eb90e44ed8717d538442600c4ad11adac61dBrian Wellington errorMsg = "<b>Error:</b> Index database not found";
bf08eb90e44ed8717d538442600c4ad11adac61dBrian Wellington } catch (Exception e) {
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley errorMsg = "<b>Error:</b> " + Util.Htmlize(e.getMessage());
173b32c660c1e4d5141b5ca740e8fab3c593652fBob Halley }
173b32c660c1e4d5141b5ca740e8fab3c593652fBob Halley if (hits != null && hits.length() == 1 && request.getServletPath().equals("/s")) {
173b32c660c1e4d5141b5ca740e8fab3c593652fBob Halley if (query != null && query instanceof TermQuery) {
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson response.sendRedirect(context + "/xref" + hits.doc(0).get("path")
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson + "#" + ((TermQuery)query).getTerm().text());
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson } else {
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson response.sendRedirect(context + "/xref" + hits.doc(0).get("path"));
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson }
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson } else {
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson %><?xml version="1.0" encoding="iso-8859-1"?>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson<head>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson <meta name="robots" content="noindex,nofollow">
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson <link rel="icon" href="img/icon.png" type="image/png"/>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson <link rel="stylesheet" type="text/css" href="style.css"/>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson <link rel="stylesheet" type="text/css" href="print.css" media="print" />
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson <link rel="alternate stylesheet" type="text/css" media="all" title="Paper White" href="print.css"/>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson <title>Search</title>
8ac1e9e3dab3b3c4682b0fcd217cff700c75a32bAndreas Gustafsson</head>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson<body>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson<div id="page">
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson <div id="header">
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson <%= getServletContext().getInitParameter("HEADER") %>
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson </div>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson<div id="Masthead"></div>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson<div id="bar">
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson <%@ include file="menu.jspf"%>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson<!-- table cellpadding="0" cellspacing="0" border="0" width="100%">
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson <tr>
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson <td valign="top"><br /> &nbsp;</td>
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson <td align="left" valign="middle">
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson <br/><form action="search" name="sbox">
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson <table cellpadding="2" border="0" cellspacing="0">
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson <tr valign="top">
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson <td>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson <table cellpadding="2" border="0" cellspacing="0">
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson <tr><td align="right"> Full&nbsp;Search </td><td><input class="q" name="q" size="45" style="width: 300px" value="<%=Util.formQuoteEscape(q)%>"/></td></tr>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson <tr><td align="right"> Definition </td><td><input class="q" name="defs" size="25" style="width: 300px" value="<%=Util.formQuoteEscape(defs)%>"/></td></tr>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson <tr><td align="right"> Symbol </td><td><input class="q" name="refs" size="25" style="width: 300px" value="<%=Util.formQuoteEscape(refs)%>"/></td></tr>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson <tr><td align="right"> File&nbsp;Path </td><td><input class="q" name="path" size="25" style="width: 300px" value="<%=Util.formQuoteEscape(path)%>"/></td></tr>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson <tr><td align="right"> History </td><td><input class="q" name="hist" size="25" style="width: 300px" value="<%=Util.formQuoteEscape(hist)%>"/></td></tr>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson </table>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson </td>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson <% if (hasProjects) { %>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson <td>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson Project:<br>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson <select class="q" name="project" size="6" multiple="true" style="width: 300px">
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson <% for (Project p : env.getProjects()) {
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson %><option value="<%=Util.formQuoteEscape(p.getPath())%>"<%=p.getPath().equals(project) ? " selected" : ""%>><%=Util.formQuoteEscape(p.getDescription())%></option><%
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson } %>
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson </select>
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson </td>
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson <% } %>
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson </tr>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson <tr><td></td><td> &nbsp; <input class="submit" type="submit" value="Search"/> | <input class="submit"
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson onClick="document.sbox.q.value='';document.sbox.defs.value='';document.sbox.refs.value='';document.sbox.path.value='';document.sbox.hist.value='';" type="button" value=" Clear "
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson /> | <a href="help.html">Help</a></td></tr>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson </table></form>
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson </td>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson <td valign="top" align="right"></td></tr>
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson</table -->
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson</div>
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson<div id="results">
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson<%
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafssonif( hits == null || errorMsg != null) {
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson %><%=errorMsg%><%
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson } else if (hits.length() == 0) {
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson String ngramIndex = env.getDataRootPath() + "/spellIndex";
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson if (ngramIndex != null && (new
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson File(ngramIndex+"/segments")).exists()) {
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson Date sstart = new Date();
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson IndexReader spellReader = IndexReader.open(ngramIndex);
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson IndexSearcher spellSearcher = new IndexSearcher(spellReader);
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson %><p><font color="#cc0000">Did you mean</font>:<%
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson String[] toks;
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson if(q != null) {
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson toks = q.split("[\t ]+");
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson if(toks != null){
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson for(int j=0; j<toks.length; j++) {
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson if(toks[j].length() > 3) {
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson String[] ret = NGramSpeller.suggestUsingNGrams(spellSearcher,toks[j].toLowerCase(), 3, 4, 3, 5, 3, 2, 0, null, false);
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson for(int i = 0;i < ret.length; i++) {
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson %> <a href=search?q=<%=ret[i]%>><%=ret[i]%></a> &nbsp; <%
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson }
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson }
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson }
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson }
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson }
9bd232838e08e9fcb070dd1aa2ce17604ce88469Andreas Gustafsson if(refs != null) {
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson toks = refs.split("[\t ]+");
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson if(toks != null){
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson for(int j=0; j<toks.length; j++) {
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson if(toks[j].length() > 3) {
173b32c660c1e4d5141b5ca740e8fab3c593652fBob Halley String[] ret = NGramSpeller.suggestUsingNGrams(spellSearcher,toks[j].toLowerCase(),3, 4, 3, 5, 3, 2, 0, null, false);
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson for(int i = 0;i < ret.length; i++) {
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley %> <a href=search?q=<%=ret[i]%>><%=ret[i]%></a> &nbsp; <%
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley }
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson }
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson }
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson }
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson }
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson if(defs != null) {
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson toks = defs.split("[\t ]+");
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson if(toks != null){
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley for(int j=0; j<toks.length; j++) {
173b32c660c1e4d5141b5ca740e8fab3c593652fBob Halley if(toks[j].length() > 3) {
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson String[] ret = NGramSpeller.suggestUsingNGrams(spellSearcher,toks[j].toLowerCase(),3, 4, 3, 5, 3, 2, 0, null, false);
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson for(int i = 0;i < ret.length; i++) {
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson %> <a href=search?q=<%=ret[i]%>><%=ret[i]%></a> &nbsp; <%
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson }
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson }
173b32c660c1e4d5141b5ca740e8fab3c593652fBob Halley }
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson }
173b32c660c1e4d5141b5ca740e8fab3c593652fBob Halley }
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson spellSearcher.close();
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson spellReader.close();
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson %></p><%
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson }
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson %><p> Your search <b><%=query.toString()%></b> did not match any files.
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson <br />
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson Suggestions:<br/><blockquote>- Make sure all terms are spelled correctly.<br/>
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson - Try different keywords.<br/>
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson - Try more general keywords.<br/>
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson - Use 'wil*' cards if you are looking for partial match.
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley </blockquote>
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson </p><%
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley } else { // We have a lots of results to show
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley StringBuilder slider = null;
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson if ( max < hits.length()) {
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson if((start + max) < hits.length()) {
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson thispage = max;
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson } else {
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson thispage = hits.length() - start;
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson }
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson String url = (q == null ? "" : "&amp;q=" + Util.URIEncode(q) ) +
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson (defs == null ? "" : "&amp;defs=" + Util.URIEncode(defs)) +
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson (refs == null ? "" : "&amp;refs=" + Util.URIEncode(refs)) +
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson (path == null ? "" : "&amp;path=" + Util.URIEncode(path)) +
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson (hist == null ? "" : "&amp;hist=" + Util.URIEncode(hist));
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson slider = new StringBuilder();
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson int labelStart =1;
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson int sstart = start - max* (start / max % 10 + 1) ;
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson if(sstart < 0) {
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson sstart = 0;
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson labelStart = 1;
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson } else {
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson labelStart = sstart/max + 1;
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson }
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson int label = labelStart;
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson int labelEnd = label + 11;
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson String arr;
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson for(int i=sstart; i<hits.length() && label <= labelEnd; i+= max) {
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson if (i <= start && start < i+ max) {
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley slider.append("<span class=\"sel\">" + label + "</span>");
173b32c660c1e4d5141b5ca740e8fab3c593652fBob Halley } else {
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley if(label == labelStart && label != 1) {
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson arr = "&lt;&lt";
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson } else if(label == labelEnd && i < hits.length()) {
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson arr = "&gt;&gt;";
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson } else {
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson arr = label < 10 ? " " + label : String.valueOf(label);
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson }
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson slider.append("<a class=\"more\" href=\"search?n=" + max + "&amp;start=" + i + url + "\">"+
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley arr + "</a>");
582732ce15d48cb521a32a551de3ce5ad2cc3290Andreas Gustafsson }
6b99e640f34b3e9b3f2b4dcb10986f78e85fe1a4Andreas Gustafsson label++;
6b99e640f34b3e9b3f2b4dcb10986f78e85fe1a4Andreas Gustafsson }
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley } else {
582732ce15d48cb521a32a551de3ce5ad2cc3290Andreas Gustafsson thispage = hits.length() - start; // set the max index to max or last
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley }
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley %>&nbsp; &nbsp; Searched <b><%=query.toString()%></b> (Results <b><%=start+1%> -
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson <%=thispage+start%></b> of <b><%=hits.length()%></b>) <p><%=slider != null ?
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson slider.toString(): ""%></p>
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson <table width="100%" cellpadding="3" cellspacing="0" border="0"><%
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson Context sourceContext = null;
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson Summarizer summer = null;
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson if (query != null) {
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson try{
173b32c660c1e4d5141b5ca740e8fab3c593652fBob Halley sourceContext = new Context(query);
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley if(sourceContext != null)
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson summer = new Summarizer(query, analyzer);
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson } catch (Exception e) {
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson }
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson }
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson HistoryContext historyContext = null;
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson try {
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson historyContext = new HistoryContext(query);
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson } catch (Exception e) {
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson }
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson EftarFileReader ef = null;
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson try{
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson ef = new EftarFileReader(env.getDataRootPath() + "/index/dtags.eftar");
173b32c660c1e4d5141b5ca740e8fab3c593652fBob Halley } catch (Exception e) {
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson }
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson Results.prettyPrintHTML(hits, start, start+thispage,
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson out,
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson sourceContext, historyContext, summer,
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson context + "/xref",
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson context + "/more",
325c88703c78ddb975994f7123ab4f93b6650a87Bob Halley env.getSourceRootPath(),
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson env.getDataRootPath(),
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson ef);
cb74b247bfdf63674fd406b8a4cb35d0d6e957d1Andreas Gustafsson if(ef != null) {
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson try{
173b32c660c1e4d5141b5ca740e8fab3c593652fBob Halley ef.close();
d60f5b9bc8c1e1f7ddebc6c7834f7550a8e8be6fBob Halley } catch (IOException e) {
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley }
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley }
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley %></table><br/>
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley <b> Completed in <%=(new Date()).getTime() - starttime.getTime()%> milliseconds </b> <br/>
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley <%=slider != null ? "<p>" + slider + "</p>" : ""%>
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley <%
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley }
016326d111130b2810cb453d6bf2ff94f398b050Bob Halley %><br/></div><%@include file="foot.jspf"%><%
173b32c660c1e4d5141b5ca740e8fab3c593652fBob Halley }
173b32c660c1e4d5141b5ca740e8fab3c593652fBob Halley if (ireader != null)
325c88703c78ddb975994f7123ab4f93b6650a87Bob Halley ireader.close();
325c88703c78ddb975994f7123ab4f93b6650a87Bob Halley} else { // Entry page show the map
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson response.sendRedirect(context + "/index.jsp");
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson}
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson%>
c0564c15e73fc366a9200fc47dfcc7894382aa98Andreas Gustafsson