search.jsp revision 226
327N/ASee LICENSE.txt included in this distribution for the specific
327N/Afile and include the License file at LICENSE.txt.
327N/A--%><%@ page import = "javax.servlet.*,
327N/AString q = request.getParameter("q");
327N/AString defs = request.getParameter("defs");
327N/AString refs = request.getParameter("refs");
327N/AString hist = request.getParameter("hist");
327N/AString path = request.getParameter("path");
327N/A%><%@ include file="projects.jspf" %><%
327N/ACookie[] cookies = request.getCookies();
327N/A sort = cookie.getValue();
327N/AString sortParam = request.getParameter("sort");
327N/A if (LASTMODTIME.equals(sortParam)) {
327N/A } else if (RELEVANCY.equals(sortParam)) {
327N/A Cookie cookie = new Cookie("OpenGrok/sorting", sort);
327N/A response.addCookie(cookie);
if( q!= null && q.equals("")) q = null;
if( defs != null && defs.equals("")) defs = null;
if( refs != null && refs.equals("")) refs = null;
if( hist != null && hist.equals("")) hist = null;
if( path != null && path.equals("")) path = null;
if (project != null && project.equals("")) project = null;
Searcher searcher = null; //the searcher used to open/search the index
IndexReader ireader = null; //the reader used to open/search the index
int thispage = 0; //used for the for/next either max or
String DATA_ROOT = env.getDataRootPath();
if(DATA_ROOT.equals("")) {
throw new Exception("DATA_ROOT parameter is not configured in web.xml!");
if(!data_root.isDirectory()) {
throw new Exception("DATA_ROOT parameter in web.xml does not exist or is not a directory!");
//String date = request.getParameter("date");
qstr = Util.buildQueryString(q, defs, refs, path, hist);
query = qparser.parse(qstr); //parse the
File root = new File(RuntimeEnvironment.getInstance().getDataRootFile(),
if (RuntimeEnvironment.getInstance().hasProjects()) {
ireader = IndexReader.open(root);
hits = searcher.search(query, new Sort("date", true));
hits = searcher.search(query);
} catch (BooleanQuery.TooManyClauses e) {
if (hits != null && hits.length() == 1 && request.getServletPath().equals("/s") && (query != null && query instanceof TermQuery)) {
String fragment = Util.URIEncode(((TermQuery)query).getTerm().text());
url.append("#");
url.append(fragment);
RuntimeEnvironment environment = RuntimeEnvironment.getInstance();
%><%@ include file="httpheader.jspf" %>
<div id="header"><%@ include file="pageheader.jspf" %></div>
<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();
int idx = querys.indexOf("sort=");
url.append(querys);
url.append('&');
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><%
url.append(RELEVANCY);
%><a href="<%=url.toString()%>">Sort by relevance</a> <b>Sort by last modified time</b><%
<%@ include file="menu.jspf"%>
} else if (hits.length() == 0) {
File spellIndex = new File(env.getDataRootPath(), "spellIndex");
if (RuntimeEnvironment.getInstance().hasProjects()) {
if (spellIndex.exists()) {
FSDirectory spellDirectory = FSDirectory.getDirectory(spellIndex);
toks = q.split("[\t ]+");
for(int j=0; j<toks.length; j++) {
String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 3);
for(int i = 0;i < ret.length; i++) {
toks = refs.split("[\t ]+");
for(int j=0; j<toks.length; j++) {
String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 3);
for(int i = 0;i < ret.length; i++) {
toks = defs.split("[\t ]+");
for(int j=0; j<toks.length; j++) {
String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 3);
for(int i = 0;i < ret.length; i++) {
%><p> Your search <b><%=query.toString()%></b> did not match any files.
if ( max < hits.length()) {
if((start + max) < hits.length()) {
thispage = hits.length() - start;
String url = (q == null ? "" : "&q=" + Util.URIEncode(q) ) +
(defs == null ? "" : "&defs=" + Util.URIEncode(defs)) +
(refs == null ? "" : "&refs=" + Util.URIEncode(refs)) +
(path == null ? "" : "&path=" + Util.URIEncode(path)) +
(hist == null ? "" : "&hist=" + Util.URIEncode(hist)) +
(sort == null ? "" : "&sort=" + Util.URIEncode(sort));
labelStart = sstart/max + 1;
for(int i=sstart; i<hits.length() && label <= labelEnd; i+= max) {
slider.append("<span class=\"sel\">" + label + "</span>");
} else if(label == labelEnd && i < hits.length()) {
arr = label < 10 ? " " + label : String.valueOf(label);
slider.append("<a class=\"more\" href=\"search?n=" + max + "&start=" + i + url + "\">"+
thispage = hits.length() - start; // set the max index to max or last
%> 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>
Results.prettyPrintHTML(hits, start, start+thispage,
ef.close();
<b> Completed in <%=(new Date()).getTime() - starttime.getTime()%> milliseconds </b> <br/>
%><br/></div><%@include file="foot.jspf"%><%