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