search.jsp revision 850
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)) {
819N/A } else if (BY_PATH.equals(sortParam)) {
98N/A Cookie cookie = new Cookie("OpenGrok/sorting", sort);
98N/A response.addCookie(cookie);
830N/A//List<org.apache.lucene.document.Document> docs=new ArrayList<org.apache.lucene.document.Document>();
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;
830N/Aif (project != null && project.size()<1) 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
830N/A int max=RuntimeEnvironment.getInstance().getHitsPerPage();
819N/A int hitsPerPage = RuntimeEnvironment.getInstance().getHitsPerPage();
819N/A int cachePages= RuntimeEnvironment.getInstance().getCachePages();
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");
819N/A //TODO merge paging hitsPerPage with parameter n (has to reflect the search if changed so proper number is cached first time)
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()) {
830N/A if (project.size() > 1) { //more projects
830N/A IndexSearcher[] searchables = new IndexSearcher[project.size()];
830N/A File droot = new File(RuntimeEnvironment.getInstance().getDataRootFile(), "index");
830N/A //TODO might need to rewrite to Project instead of String , need changes in projects.jspf too
830N/A ireader = (IndexReader.open(new File(droot, proj)));
830N/A if (Runtime.getRuntime().availableProcessors() > 1) {
830N/A root = new File(root, project.get(0));
830N/A ireader = IndexReader.open(root);
830N/A ireader = IndexReader.open(root);
830N/A //TODO check if below is somehow reusing sessions so we don't requery again and again, I guess 2min timeout sessions could be usefull, since you click on the next page within 2mins, if not, then wait ;)
819N/A if (LASTMODTIME.equals(sort)) {
819N/A TopFieldDocs fdocs=searcher.search(query, null,hitsPerPage*cachePages, sortf);
819N/A totalHits=fdocs.totalHits;
819N/A if (start>=hitsPerPage*cachePages && !allCollected) { //fetch ALL results only if above cachePages
819N/A fdocs=searcher.search(query, null, totalHits, sortf);
819N/A hits = fdocs.scoreDocs;
819N/A } else if (BY_PATH.equals(sort)) {
819N/A TopFieldDocs fdocs=searcher.search(query, null,hitsPerPage*cachePages, sortf);
819N/A totalHits=fdocs.totalHits;
819N/A if (start>=hitsPerPage*cachePages && !allCollected) { //fetch ALL results only if above cachePages
819N/A fdocs=searcher.search(query, null,totalHits, sortf);
819N/A hits = fdocs.scoreDocs;
819N/A searcher.search(query,collector);
819N/A totalHits=collector.getTotalHits();
819N/A if (start>=hitsPerPage*cachePages && !allCollected) { //fetch ALL results only if above cachePages
819N/A searcher.search(query,collector);
819N/A hits=collector.topDocs().scoreDocs;
819N/A// for (int i = 0; i < hits.length; i++) {
819N/A// Document d = searcher.doc(docId);
0N/A } catch (BooleanQuery.TooManyClauses e) {
510N/A errorMsg = "<b>Error parsing your query:</b><br/>" + 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/>" +
819N/A if (hits != null && hits.length == 1 && request.getServletPath().equals("/s") && (query != null && query instanceof TermQuery)) {
819N/A String preFragmentPath = Util.URIEncodePath(context + "/xref" + searcher.doc(hits[0].doc).get("path"));
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>
850N/A <table border="0" width="100%"><tr><td><a href="<%=context%>" id="home">Home</a></td><td align="right"><%
850N/A url = url + (q == null ? "" : "&q=" + Util.URIEncode(q)) +
850N/A (defs == null ? "" : "&defs=" + Util.URIEncode(defs)) +
850N/A (refs == null ? "" : "&refs=" + Util.URIEncode(refs)) +
850N/A (path == null ? "" : "&path=" + Util.URIEncode(path)) +
850N/A (hist == null ? "" : "&hist=" + Util.URIEncode(hist));
98N/A if (sort == null || RELEVANCY.equals(sort)) {
850N/A %><b>relevance</b> | <a href="<%=url+LASTMODTIME%>">last modified time</a> | <a href="<%=url+BY_PATH%>">path</a><%
819N/A } else if (LASTMODTIME.equals(sort)) {
850N/A %><a href="<%=url+RELEVANCY%>">relevance</a> | <b>last modified time</b> | <a href="<%=url+BY_PATH%>">path</a><%
819N/A } else if (BY_PATH.equals(sort)) {
850N/A %><a href="<%=url+RELEVANCY%>">relevance</a> | <a href="<%=url+LASTMODTIME%>">last modified time</a> | <b>path</b><%
850N/A %><a href="<%=url+RELEVANCY%>">relevance</a> | <a href="<%=url+LASTMODTIME%>">last modified time</a> | <a href="<%=url+BY_PATH%>">path</a><%
830N/A//TODO spellchecking cycle below is not that great and we only create suggest links for every token in query, not for a query as whole
819N/A } else if (hits.length == 0) {
99N/A File spellIndex = new File(env.getDataRootPath(), "spellIndex");
207N/A if (RuntimeEnvironment.getInstance().hasProjects()) {
830N/A if (project.size() > 1) { //more projects
830N/A spellIndexes = new File[project.size()];
830N/A //TODO might need to rewrite to Project instead of String , need changes in projects.jspf too
830N/A spellIndex = new File(spellIndex, project.get(0));
830N/A if (spellIndexes!=null) {count=spellIndexes.length;}
830N/A if (spellIndex.exists()) {
99N/A FSDirectory spellDirectory = FSDirectory.getDirectory(spellIndex);
0N/A for(int j=0; j<toks.length; j++) {
830N/A String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 5);
0N/A for(int i = 0;i < ret.length; i++) {
830N/A %><p><font color="#cc0000">Did you mean(for <%=spellIndex.getName()%>)</font>:<%
0N/A toks = refs.split("[\t ]+");
0N/A for(int j=0; j<toks.length; j++) {
830N/A String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 5);
0N/A for(int i = 0;i < ret.length; i++) {
830N/A %><p><font color="#cc0000">Did you mean(for <%=spellIndex.getName()%>)</font>:<%
830N/A //TODO it seems the only true spellchecker is for below field, see IndexDatabase createspellingsuggestions ...
0N/A toks = defs.split("[\t ]+");
0N/A for(int j=0; j<toks.length; j++) {
830N/A String[] ret = checker.suggestSimilar(toks[j].toLowerCase(), 5);
0N/A for(int i = 0;i < ret.length; i++) {
830N/A %><p><font color="#cc0000">Did you mean(for <%=spellIndex.getName()%>)</font>:<%
0N/A %><p> Your search <b><%=query.toString()%></b> did not match any files.
850N/A String urlp = (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)) +
830N/A (sort == null ? "" : "&sort=" + Util.URIEncode(sort));
0N/A labelStart = sstart/max + 1;
0N/A slider.append("<span class=\"sel\">" + label + "</span>");
0N/A arr = label < 10 ? " " + label : String.valueOf(label);
850N/A slider.append("<a class=\"more\" href=\"s?n=" + max + "&start=" + i + urlp + "\">"+
0N/A %> Searched <b><%=query.toString()%></b> (Results <b><%=start+1%> -
0N/A slider.toString(): ""%></p>
830N/A //TODO also fix the way what and how it is passed to prettyprint, can improve performance! SearchEngine integration is really needed here.
819N/A Results.prettyPrintHTML(searcher,hits, start, start+thispage,
0N/A <b> Completed in <%=(new Date()).getTime() - starttime.getTime()%> milliseconds </b> <br/>