search.jsp revision 1469
0N/A<%--
2362N/A$Id$
0N/A
0N/ACDDL HEADER START
0N/A
0N/AThe contents of this file are subject to the terms of the
2362N/ACommon Development and Distribution License (the "License").
0N/AYou may not use this file except in compliance with the License.
2362N/A
0N/ASee LICENSE.txt included in this distribution for the specific
0N/Alanguage governing permissions and limitations under the License.
0N/A
0N/AWhen distributing Covered Code, include this CDDL HEADER in each
0N/Afile and include the License file at LICENSE.txt.
0N/AIf applicable, add the following below this CDDL HEADER, with the
0N/Afields enclosed by brackets "[]" replaced with your own identifying
0N/Ainformation: Portions Copyright [yyyy] [name of copyright owner]
0N/A
0N/ACDDL HEADER END
0N/A
2362N/ACopyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
2362N/APortions Copyright 2011 Jens Elkner.
2362N/A
0N/A--%><%@page session="false" errorPage="error.jsp" import="
0N/Aorg.opensolaris.opengrok.search.Results,
0N/Aorg.opensolaris.opengrok.web.SearchHelper,
0N/Aorg.opensolaris.opengrok.web.SortOrder,
0N/Aorg.opensolaris.opengrok.web.Suggestion"
0N/A%><%@
0N/A
0N/Ainclude file="projects.jspf"
0N/A
0N/A%><%!
0N/A private StringBuilder createUrl(SearchHelper sh, boolean menu) {
0N/A StringBuilder url = new StringBuilder(64);
0N/A QueryBuilder qb = sh.builder;
0N/A if (menu) {
0N/A url.append(sh.contextPath).append(Prefix.SEARCH_P).append('?');
0N/A } else {
0N/A Util.appendQuery(url, "sort", sh.order.toString());
0N/A }
0N/A if (qb != null) {
0N/A Util.appendQuery(url, "q", qb.getFreetext());
0N/A Util.appendQuery(url, "defs", qb.getDefs());
0N/A Util.appendQuery(url, "refs", qb.getRefs());
0N/A Util.appendQuery(url, "path", qb.getPath());
0N/A Util.appendQuery(url, "hist", qb.getHist());
0N/A }
0N/A if (sh.projects != null && sh.projects.size() != 0) {
0N/A Util.appendQuery(url, "project", cfg.getRequestedProjectsAsString());
0N/A }
0N/A return url;
0N/A }
0N/A%><%
0N/A/* ---------------------- search.jsp start --------------------- */
0N/A{
0N/A cfg = PageConfig.get(request);
0N/A
0N/A long starttime = System.currentTimeMillis();
0N/A
0N/A SearchHelper searchHelper = cfg.prepareSearch()
0N/A .prepareExec(cfg.getRequestedProjects()).executeQuery().prepareSummary();
0N/A if (searchHelper.redirect != null) {
0N/A response.sendRedirect(searchHelper.redirect);
0N/A }
0N/A if (searchHelper.errorMsg != null) {
0N/A cfg.setTitle("Search Error");
0N/A } else {
0N/A cfg.setTitle("Search");
0N/A }
0N/A response.addCookie(new Cookie("OpenGrokSorting", searchHelper.order.toString()));
0N/A%><%@
0N/A
0N/Ainclude file="httpheader.jspf"
0N/A
0N/A%><body class="yui3-skin-sam">
0N/A<div id="page">
0N/A <div id="whole_header">
0N/A <div id="header"><%@
0N/A
0N/Ainclude file="pageheader.jspf"
0N/A
0N/A%>
0N/A </div>
0N/A <div id="Masthead"></div>
0N/A <div id="bar">
0N/A <ul>
0N/A <li><a href="<%= request.getContextPath()
0N/A %>/"><span id="home"></span>Home</a></li>
0N/A </ul>
0N/A <%-- TODO: jel: IMHO it should be move to menu.jspf as combobox --%>
0N/A <div id="sortfield">
0N/A <label for="sortby">Sort by</label>
0N/A <ul id="sortby"><%
0N/A StringBuilder url = createUrl(searchHelper, true).append("&amp;sort=");
0N/A for (SortOrder o : SortOrder.values()) {
0N/A if (searchHelper.order == o) {
0N/A %><li><span class="active"><%= o.getDesc() %></span></li><%
0N/A } else {
0N/A %><li><a href="<%= url %><%= o %>"><%= o.getDesc() %></a></li><%
0N/A }
0N/A }
0N/A %></ul>
0N/A </div>
0N/A </div>
0N/A <div id="menu"><%@
0N/A
0N/Ainclude file="menu.jspf"
0N/A
0N/A%>
0N/A </div>
0N/A </div>
0N/A <div id="results"><%
0N/A // TODO spellchecking cycle below is not that great and we only create
0N/A // suggest links for every token in query, not for a query as whole
0N/A if (searchHelper.errorMsg != null) {
0N/A %><h3>Error</h3><p><%
0N/A if (searchHelper.errorMsg.startsWith((SearchHelper.PARSE_ERROR_MSG))) {
0N/A %><%= Util.htmlize(SearchHelper.PARSE_ERROR_MSG) %>
0N/A <br/>You might try to enclose your search term in quotes,
0N/A <a href="help.jsp#escaping">escape special characters</a>
0N/A with <b>\</b>, or read the <a href="help.jsp">Help</a>
0N/A on the query language. Error message from parser:<br/>
0N/A <%= Util.htmlize(searchHelper.errorMsg.substring(
0N/A SearchHelper.PARSE_ERROR_MSG.length())) %><%
0N/A } else {
0N/A %><%= Util.htmlize(searchHelper.errorMsg) %><%
0N/A }%></p><%
0N/A } else if (searchHelper.hits == null) {
0N/A %><p>No hits</p><%
0N/A } else if (searchHelper.hits.length == 0) {
0N/A List<Suggestion> hints = searchHelper.getSuggestions();
0N/A String prefix = searchHelper.contextPath + Prefix.SEARCH_P + '?';
0N/A for (Suggestion hint : hints) {
0N/A %><p><font color="#cc0000">Did you mean (for <%= hint.name %>)</font>:<%
0N/A for (String word : hint.freetext) {
0N/A %><a href="<%= prefix + "q=" + Util.uriEncodeQueryValue(word) %>"
0N/A ><%= Util.htmlize(word) %></a> &nbsp; <%
}
for (String word : hint.refs) {
%> <a href="<%= prefix + "refs=" + Util.uriEncodeQueryValue(word) %>"
><%= Util.htmlize(word) %></a> &nbsp; <%
}
for (String word : hint.defs) {
%> <a href="<%= prefix + "defs=" + Util.uriEncodeQueryValue(word) %>"
><%= Util.htmlize(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;
String prefix = searchHelper.contextPath + Prefix.SEARCH_R + "?n=";
for (int i = sstart; i < totalHits && label <= labelEnd; i+= max) {
if (i <= start && start < i + max) {
buf.append("<span class=\"rsps\">").append(label).append("</span>");
} else {
buf.append("<a class=\"rspn\" href=\"").append(prefix).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><%=
Util.htmlize(searchHelper.query.toString())
%></b> (Results <b> <%= start + 1 %> - <%= thispage + start
%></b> of <b><%= totalHits %></b>) sorted by <%=
searchHelper.order.getDesc() %></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"
%>