search.jsp revision 1186
98N/A<%--
98N/A$Id$
287N/A
98N/ACDDL HEADER START
98N/A
98N/AThe contents of this file are subject to the terms of the
98N/ACommon Development and Distribution License (the "License").
98N/AYou may not use this file except in compliance with the License.
98N/A
98N/ASee LICENSE.txt included in this distribution for the specific
98N/Alanguage governing permissions and limitations under the License.
98N/A
98N/AWhen distributing Covered Code, include this CDDL HEADER in each
98N/Afile and include the License file at LICENSE.txt.
98N/AIf applicable, add the following below this CDDL HEADER, with the
98N/Afields enclosed by brackets "[]" replaced with your own identifying
98N/Ainformation: Portions Copyright [yyyy] [name of copyright owner]
98N/A
98N/ACDDL HEADER END
98N/A
98N/ACopyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
98N/APortions Copyright 2011 Jens Elkner.
98N/A
98N/A--%><%@page session="false" errorPage="error.jsp" import="
98N/Aorg.opensolaris.opengrok.search.Results,
98N/Aorg.opensolaris.opengrok.web.SearchHelper,
98N/Aorg.opensolaris.opengrok.web.SortOrder,
98N/Aorg.opensolaris.opengrok.web.Suggestion"
98N/A%><%@
98N/A
354N/Ainclude file="projects.jspf"
98N/A
98N/A%><%!
98N/A private StringBuilder createUrl(SearchHelper sh, boolean menu) {
354N/A StringBuilder url = new StringBuilder(64);
354N/A QueryBuilder qb = sh.builder;
354N/A if (menu) {
354N/A url.append("search?");
354N/A } else {
354N/A Util.appendQuery(url, "sort", sh.order.toString());
354N/A }
354N/A if (qb != null) {
354N/A Util.appendQuery(url, "q", qb.getFreetext());
354N/A Util.appendQuery(url, "defs", qb.getDefs());
354N/A Util.appendQuery(url, "refs", qb.getRefs());
354N/A Util.appendQuery(url, "path", qb.getPath());
98N/A Util.appendQuery(url, "hist", qb.getHist());
98N/A }
98N/A if (sh.projects != null && sh.projects.size() != 0) {
98N/A Util.appendQuery(url, "project", cfg.getRequestedProjectsAsString());
98N/A }
98N/A return url;
341N/A }
354N/A%><%
325N/A/* ---------------------- search.jsp start --------------------- */
325N/A{
354N/A cfg = PageConfig.get(request);
278N/A
98N/A long starttime = System.currentTimeMillis();
98N/A
98N/A SearchHelper searchHelper = cfg.prepareSearch()
151N/A .prepareExec(cfg.getRequestedProjects()).executeQuery().prepareSummary();
137N/A if (searchHelper.redirect != null) {
153N/A response.sendRedirect(searchHelper.redirect);
210N/A }
98N/A if (searchHelper.errorMsg != null
179N/A && searchHelper.errorMsg.startsWith(SearchHelper.PARSE_ERROR_MSG))
269N/A {
126N/A searchHelper.errorMsg = SearchHelper.PARSE_ERROR_MSG
98N/A + "<br/>You might try to enclose your search term in quotes, "
98N/A + "<a href=\"help.jsp#escaping\">escape special characters</a> "
98N/A + "with <b>\\</b>, or read the <a href=\"help.jsp\">Help</a> "
287N/A + "on the query language."
123N/A + "Error message from parser:<br/>" + searchHelper.errorMsg
98N/A .substring(SearchHelper.PARSE_ERROR_MSG.length());
98N/A }
98N/A if (searchHelper.errorMsg != null) {
98N/A cfg.setTitle("Search Error");
98N/A } else {
98N/A cfg.setTitle("Search");
98N/A }
98N/A response.addCookie(new Cookie("OpenGrokSorting", searchHelper.order.toString()));
98N/A%><%@
98N/A
98N/Ainclude file="httpheader.jspf"
98N/A
156N/A%><body>
156N/A<div id="page">
98N/A <div id="whole_header">
98N/A <div id="header"><%@
98N/A
98N/Ainclude file="pageheader.jspf"
98N/A
98N/A%>
98N/A </div>
98N/A <div id="Masthead"></div>
98N/A <div id="bar">
98N/A <ul>
98N/A <li><a href="<%= request.getContextPath()
98N/A %>/"><span id="home"></span>Home</a></li>
98N/A </ul>
98N/A <%-- TODO: jel: IMHO it should be move to menu.jspf as combobox --%>
98N/A <div id="sortfield">
98N/A <label for="sortby">Sort by</label>
98N/A <ul id="sortby"><%
98N/A StringBuilder url = createUrl(searchHelper, true).append("&amp;sort=");
98N/A for (SortOrder o : SortOrder.values()) {
98N/A if (searchHelper.order == o) {
98N/A %><li><span class="active"><%= o.getDesc() %></span></li><%
98N/A } else {
%><li><a href="<%= url %><%= o %>"><%= o.getDesc() %></a></li><%
}
}
%></ul>
</div>
</div>
<div id="menu"><%@
include file="menu.jspf"
%>
</div>
</div>
<div id="results"><%
// 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
if (searchHelper.errorMsg != null) {
%><h3>Error</h3>
<p><%= Util.htmlize(searchHelper.errorMsg) %></p><%
} else if (searchHelper.hits == null) {
%><p>No hits</p><%
} else if (searchHelper.hits.length == 0) {
List<Suggestion> hints = searchHelper.getSuggestions();
for (Suggestion hint : hints) {
%><p><font color="#cc0000">Did you mean (for <%= hint.name %>)</font>:<%
for (String word : hint.freetext) {
%> <a href=search?q=<%= word %>><%= word %></a> &nbsp; <%
}
for (String word : hint.refs) {
%> <a href=search?refs=<%= word %>><%= word %></a> &nbsp; <%
}
for (String word : hint.defs) {
%> <a href=search?defs=<%= word %>><%= word %></a> &nbsp; <%
}
%></p><%
}
%>
<p> Your search <b><%= searchHelper.query %></b> did not match any files.
<br/> Suggestions:<br/>
</p>
<ul>
<li>Make sure all terms are spelled correctly.</li>
<li>Try different keywords.</li>
<li>Try more general keywords.</li>
<li>Use 'wil*' cards if you are looking for partial match.</li>
</ul><%
} else {
// We have a lots of results to show: create a slider for
String slider = "";
int thispage; // number of items to display on the current page
int start = searchHelper.start;
int max = searchHelper.maxItems;
int totalHits = searchHelper.totalHits;
if (searchHelper.maxItems < searchHelper.totalHits) {
StringBuilder buf = new StringBuilder(4096);
thispage = (start + max) < totalHits ? max : totalHits - start;
StringBuilder urlp = createUrl(searchHelper, false);
int labelStart = 1;
int sstart = start - max * (start / max % 10 + 1) ;
if (sstart < 0) {
sstart = 0;
labelStart = 1;
} else {
labelStart = sstart / max + 1;
}
int label = labelStart;
int labelEnd = label + 11;
for (int i = sstart; i < totalHits && label <= labelEnd; i+= max) {
if (i <= start && start < i + max) {
buf.append("<span class=\"sel\">").append(label).append("</span>");
} else {
buf.append("<a class=\"more\" href=\"s?n=").append(max)
.append("&amp;start=").append(i).append(urlp).append("\">");
if (label == labelStart && label != 1) {
buf.append("&lt;&lt");
} else if (label == labelEnd && i < totalHits) {
buf.append("&gt;&gt;");
} else {
buf.append(label);
}
buf.append("</a>");
}
label++;
}
slider = buf.toString();
} else {
// set the max index to max or last
thispage = totalHits - start;
}
%>
<p class="pagetitle">Searched <b><%= searchHelper.query
%></b> (Results <b> <%= start + 1 %> - <%= thispage + start
%></b> of <b><%= totalHits %></b>) sorted by <%=
searchHelper.order %></p><%
if (slider.length() > 0) {
%>
<p class="slider"><%= slider %></p><%
}
%>
<table><%
Results.prettyPrint(out, searchHelper, start, start + thispage);
%>
</table>
<p><b>Completed in <%= System.currentTimeMillis() - starttime
%> milliseconds</b></p><%
if (slider.length() > 0) {
%>
<p class="slider"><%= slider %></p><%
}
%>
</div><%
}
searchHelper.destroy();
}
/* ---------------------- search.jsp end --------------------- */
%><%@
include file="foot.jspf"
%>