search.jsp revision 17b8789066a049bf676ebfd9062db6ec4871c997
10139N/ASee LICENSE.txt included in this distribution for the specific
10139N/Afile and include the License file at LICENSE.txt.
10139N/A--%><%@ page import = "javax.servlet.*,
10139N/AString q = request.getParameter("q");
10139N/AString defs = request.getParameter("defs");
10139N/AString refs = request.getParameter("refs");
10139N/AString hist = request.getParameter("hist");
10139N/AString path = request.getParameter("path");
10139N/A<%@ include file="projects.jspf" %>
10139N/ACookie[] cookies = request.getCookies();
13570N/A sort = cookie.getValue();
17392N/AString sortParam = request.getParameter("sort");
11965N/A if (LASTMODTIME.equals(sortParam)) {
15942N/A } else if (RELEVANCY.equals(sortParam)) {
10139N/A Cookie cookie = new Cookie("OpenGrok/sorting", sort);
15942N/A response.addCookie(cookie);
11933N/Aif( defs != null && defs.equals("")) defs = null;
10139N/Aif( refs != null && refs.equals("")) refs = null;
10139N/Aif( hist != null && hist.equals("")) hist = null;
15288N/Aif( path != null && path.equals("")) path = null;
10139N/Aif (project != null && project.equals("")) project = null;
10139N/A Searcher searcher = null; //the searcher used to open/search the index
10139N/A IndexReader ireader = null; //the reader used to open/search the index
10139N/A String DATA_ROOT = env.getDataRootPath();
15942N/A if(DATA_ROOT.equals("")) {
10139N/A if(!data_root.isDirectory()) {
10139N/A throw new Exception("DATA_ROOT parameter in web.xml does not exist or is not a directory!");
10139N/A ireader = IndexReader.open(DATA_ROOT + "/index");
15942N/A //String date = request.getParameter("date");
15942N/A for (String s : project.split(" ")) {
15942N/A qstr = sb.toString();
15942N/A query = qparser.parse(qstr); //parse the
10139N/A hits = searcher.search(query, new Sort("date", true));
18861N/A hits = searcher.search(query);
15942N/A } catch (BooleanQuery.TooManyClauses e) {
15989N/A errorMsg = "<b>Error:</b><br/>" + Util.Htmlize(qstr) + "<br/>" + Util.Htmlize(e.getMessage());
10139N/A if (hits != null && hits.length() == 1 && request.getServletPath().equals("/s") && (query != null && query instanceof TermQuery)) {
10139N/A File parent = file.getParentFile();
10139N/A url.append("/xref");
10139N/A url.append('/');
10139N/A url.append("#");
10139N/A url.append(((TermQuery)query).getTerm().text());
10139N/A RuntimeEnvironment environment = RuntimeEnvironment.getInstance();
10139N/A %><%@ include file="httpheader.jspf" %>
10139N/A <div id="header"><%@ include file="pageheader.jspf" %></div>
10139N/A <table border="0" width="100%"><tr><td><a href="<%=context%>" id="home">Home</a></td><td align="right"><%
10139N/A StringBuffer url = request.getRequestURL();
10139N/A url.append('?');
10139N/A String querys = request.getQueryString();
10139N/A int idx = querys.indexOf("sort=");
10139N/A url.append(querys);
10139N/A url.append('&');
10139N/A url.append("sort=");
10139N/A if (sort == null || RELEVANCY.equals(sort)) {
10139N/A url.append(LASTMODTIME);
10139N/A %><b>Sort by relevance</b> <a href="<%=url.toString()%>">Sort by last modified time</a><%
10139N/A url.append(RELEVANCY);
10139N/A %><a href="<%=url.toString()%>">Sort by relevance</a> <b>Sort by last modified time</b><%
10139N/A } else if (hits.length() == 0) {
10139N/A File spellIndex = new File(env.getDataRootPath(), "spellIndex");
10139N/A if (spellIndex.exists()) {
10139N/A FSDirectory spellDirectory = FSDirectory.getDirectory(spellIndex);
10139N/A for(int j=0; j<toks.length; j++) {
10139N/A String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 3);
10139N/A for(int i = 0;i < ret.length; i++) {
10139N/A toks = refs.split("[\t ]+");
10139N/A for(int j=0; j<toks.length; j++) {
10139N/A String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 3);
10139N/A for(int i = 0;i < ret.length; i++) {
10139N/A toks = defs.split("[\t ]+");
10139N/A for(int j=0; j<toks.length; j++) {
10139N/A String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 3);
10139N/A for(int i = 0;i < ret.length; i++) {
10139N/A %><p> Your search <b><%=query.toString()%></b> did not match any files.
14177N/A if ( max < hits.length()) {
17597N/A if((start + max) < hits.length()) {
17597N/A thispage = hits.length() - start;
17597N/A String url = (q == null ? "" : "&q=" + Util.URIEncode(q) ) +
17597N/A (defs == null ? "" : "&defs=" + Util.URIEncode(defs)) +
17597N/A (refs == null ? "" : "&refs=" + Util.URIEncode(refs)) +
11965N/A (path == null ? "" : "&path=" + Util.URIEncode(path)) +
11965N/A (hist == null ? "" : "&hist=" + Util.URIEncode(hist)) +
13931N/A (sort == null ? "" : "&sort=" + Util.URIEncode(sort));
15995N/A labelStart = sstart/max + 1;
13678N/A for(int i=sstart; i<hits.length() && label <= labelEnd; i+= max) {
13678N/A slider.append("<span class=\"sel\">" + label + "</span>");
10139N/A } else if(label == labelEnd && i < hits.length()) {
10139N/A arr = label < 10 ? " " + label : String.valueOf(label);
10139N/A slider.append("<a class=\"more\" href=\"search?n=" + max + "&start=" + i + url + "\">"+
13726N/A thispage = hits.length() - start; // set the max index to max or last
13806N/A %> Searched <b><%=query.toString()%></b> (Results <b><%=start+1%> -
16224N/A <%=thispage+start%></b> of <b><%=hits.length()%></b>) sorted by <%=sort%> <p><%=slider != null ?
16539N/A slider.toString(): ""%></p>
10139N/A Results.prettyPrintHTML(hits, start, start+thispage,
10139N/A <b> Completed in <%=(new Date()).getTime() - starttime.getTime()%> milliseconds </b> <br/>