search.jsp revision 603
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");
207N/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/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 //String date = request.getParameter("date");
226N/A qstr = Util.buildQueryString(q, defs, refs, path, hist);
0N/A query = qparser.parse(qstr); //parse the
207N/A File root = new File(RuntimeEnvironment.getInstance().getDataRootFile(),
207N/A if (RuntimeEnvironment.getInstance().hasProjects()) {
207N/A ireader = IndexReader.open(root);
207N/A hits = searcher.search(query, new Sort("date", true));
207N/A hits = searcher.search(query);
0N/A } catch (BooleanQuery.TooManyClauses e) {
510N/A errorMsg = "<b>Error parsing your query:</b><br/>" + Util.htmlize(qstr) +
510N/A "<a href=search?q=\"" + qstr + "\">\"" + Util.htmlize(qstr) +
510N/A "\"</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/>" +
107N/A if (hits != null && hits.length() == 1 && request.getServletPath().equals("/s") && (query != null && query instanceof TermQuery)) {
158N/A String fragment = Util.URIEncode(((TermQuery)query).getTerm().text());
152N/A url.append("#");
158N/A url.append(fragment);
147N/A RuntimeEnvironment environment = RuntimeEnvironment.getInstance();
144N/A %><%@ include file="httpheader.jspf" %>
144N/A <div id="header"><%@ include file="pageheader.jspf" %></div>
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");
207N/A if (RuntimeEnvironment.getInstance().hasProjects()) {
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)) +
331N/A (sort == null ? "" : "&sort=" + Util.URIEncode(sort)) +
331N/A (project == null ? "" : "&project=" + Util.URIEncode(project));
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/>