search.jsp revision 99
0N/ASee LICENSE.txt included in this distribution for the specific
0N/Afile and include the License file at LICENSE.txt.
0N/A--%><%@ page import = "javax.servlet.*,
0N/AString q = request.getParameter("q");
0N/AString defs = request.getParameter("defs");
0N/AString refs = request.getParameter("refs");
0N/AString hist = request.getParameter("hist");
0N/AString path = request.getParameter("path");
58N/A<%@ include file="projects.jspf" %>
98N/ACookie[] cookies = request.getCookies();
98N/A sort = cookie.getValue();
98N/AString sortParam = request.getParameter("sort");
98N/A if (LASTMODTIME.equals(sortParam)) {
98N/A } else if (RELEVANCY.equals(sortParam)) {
98N/A Cookie cookie = new Cookie("OpenGrok/sorting", sort);
98N/A response.addCookie(cookie);
0N/AString context = request.getContextPath();
0N/Aif( defs != null && defs.equals("")) defs = null;
0N/Aif( refs != null && refs.equals("")) refs = null;
0N/Aif( hist != null && hist.equals("")) hist = null;
0N/Aif( path != null && path.equals("")) path = null;
73N/Aif (project != null && project.equals("")) project = null;
0N/A Searcher searcher = null; //the searcher used to open/search the index
0N/A IndexReader ireader = null; //the reader used to open/search the index
58N/A String DATA_ROOT = env.getDataRootPath();
0N/A if(DATA_ROOT.equals("")) {
0N/A if(!data_root.isDirectory()) {
0N/A ireader = IndexReader.open(DATA_ROOT + "/index");
0N/A //String date = request.getParameter("date");
58N/A for (String s : project.split(" ")) {
58N/A qstr = sb.toString();
0N/A query = qparser.parse(qstr); //parse the
97N/A hits = searcher.search(query, new Sort("date", true));
97N/A hits = searcher.search(query);
0N/A } catch (BooleanQuery.TooManyClauses e) {
0N/A<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
0N/A<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
0N/A <link rel="alternate stylesheet" type="text/css" media="all" title="Paper White" href="print.css"/>
98N/A <table border="0" width="100%"><tr><td><a href="<%=context%>" id="home">Home</a></td><td align="right"><%
98N/A StringBuffer url = request.getRequestURL();
98N/A url.append('?');
98N/A String querys = request.getQueryString();
98N/A int idx = querys.indexOf("sort=");
98N/A url.append(querys);
98N/A url.append('&');
98N/A url.append("sort=");
98N/A if (sort == null || RELEVANCY.equals(sort)) {
98N/A url.append(LASTMODTIME);
98N/A %><b>Sort by relevance</b> <a href="<%=url.toString()%>">Sort by last modified time</a><%
98N/A url.append(RELEVANCY);
98N/A %><a href="<%=url.toString()%>">Sort by relevance</a> <b>Sort by last modified time</b><%
0N/A } else if (hits.length() == 0) {
99N/A File spellIndex = new File(env.getDataRootPath(), "spellIndex");
99N/A if (spellIndex.exists()) {
99N/A FSDirectory spellDirectory = FSDirectory.getDirectory(spellIndex);
0N/A for(int j=0; j<toks.length; j++) {
99N/A String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 3);
0N/A for(int i = 0;i < ret.length; i++) {
0N/A toks = refs.split("[\t ]+");
0N/A for(int j=0; j<toks.length; j++) {
99N/A String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 3);
0N/A for(int i = 0;i < ret.length; i++) {
0N/A toks = defs.split("[\t ]+");
0N/A for(int j=0; j<toks.length; j++) {
99N/A String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 3);
0N/A for(int i = 0;i < ret.length; i++) {
0N/A %><p> Your search <b><%=query.toString()%></b> did not match any files.
0N/A if ( max < hits.length()) {
0N/A if((start + max) < hits.length()) {
0N/A thispage = hits.length() - start;
0N/A String url = (q == null ? "" : "&q=" + Util.URIEncode(q) ) +
0N/A (defs == null ? "" : "&defs=" + Util.URIEncode(defs)) +
0N/A (refs == null ? "" : "&refs=" + Util.URIEncode(refs)) +
0N/A (path == null ? "" : "&path=" + Util.URIEncode(path)) +
97N/A (hist == null ? "" : "&hist=" + Util.URIEncode(hist)) +
97N/A (sort == null ? "" : "&sort=" + Util.URIEncode(sort));
0N/A labelStart = sstart/max + 1;
0N/A for(int i=sstart; i<hits.length() && label <= labelEnd; i+= max) {
0N/A slider.append("<span class=\"sel\">" + label + "</span>");
0N/A } else if(label == labelEnd && i < hits.length()) {
0N/A arr = label < 10 ? " " + label : String.valueOf(label);
0N/A slider.append("<a class=\"more\" href=\"search?n=" + max + "&start=" + i + url + "\">"+
0N/A thispage = hits.length() - start; // set the max index to max or last
0N/A %> Searched <b><%=query.toString()%></b> (Results <b><%=start+1%> -
97N/A <%=thispage+start%></b> of <b><%=hits.length()%></b>) sorted by <%=sort%> <p><%=slider != null ?
0N/A slider.toString(): ""%></p>
0N/A Results.prettyPrintHTML(hits, start, start+thispage,
0N/A <b> Completed in <%=(new Date()).getTime() - starttime.getTime()%> milliseconds </b> <br/>