search.jsp revision 1292
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync<%--
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync$Id$
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncCDDL HEADER START
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncThe contents of this file are subject to the terms of the
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncCommon Development and Distribution License (the "License").
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncYou may not use this file except in compliance with the License.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncSee LICENSE.txt included in this distribution for the specific
deb4998ba50060c48cce222fd18a8eed053918d7vboxsynclanguage governing permissions and limitations under the License.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncWhen distributing Covered Code, include this CDDL HEADER in each
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncfile and include the License file at LICENSE.txt.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncIf applicable, add the following below this CDDL HEADER, with the
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncfields enclosed by brackets "[]" replaced with your own identifying
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncinformation: Portions Copyright [yyyy] [name of copyright owner]
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncCDDL HEADER END
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncCopyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncPortions Copyright 2011 Jens Elkner.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync--%><%@page session="false" errorPage="error.jsp" import="
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncorg.opensolaris.opengrok.search.Results,
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncorg.opensolaris.opengrok.web.SearchHelper,
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncorg.opensolaris.opengrok.web.SortOrder,
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncorg.opensolaris.opengrok.web.Suggestion"
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync%><%@
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncinclude file="projects.jspf"
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync%><%!
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync private StringBuilder createUrl(SearchHelper sh, boolean menu) {
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync StringBuilder url = new StringBuilder(64);
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync QueryBuilder qb = sh.builder;
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync if (menu) {
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync url.append("search?");
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync } else {
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync Util.appendQuery(url, "sort", sh.order.toString());
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync }
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync if (qb != null) {
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync Util.appendQuery(url, "q", qb.getFreetext());
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync Util.appendQuery(url, "defs", qb.getDefs());
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync Util.appendQuery(url, "refs", qb.getRefs());
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync Util.appendQuery(url, "path", qb.getPath());
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync Util.appendQuery(url, "hist", qb.getHist());
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync }
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync if (sh.projects != null && sh.projects.size() != 0) {
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync Util.appendQuery(url, "project", cfg.getRequestedProjectsAsString());
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync }
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync return url;
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync }
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync%><%
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/* ---------------------- search.jsp start --------------------- */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync{
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync cfg = PageConfig.get(request);
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync long starttime = System.currentTimeMillis();
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync SearchHelper searchHelper = cfg.prepareSearch()
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync .prepareExec(cfg.getRequestedProjects()).executeQuery().prepareSummary();
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync if (searchHelper.redirect != null) {
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync response.sendRedirect(searchHelper.redirect);
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync }
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync if (searchHelper.errorMsg != null) {
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync cfg.setTitle("Search Error");
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync } else {
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync cfg.setTitle("Search");
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync }
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync response.addCookie(new Cookie("OpenGrokSorting", searchHelper.order.toString()));
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync%><%@
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncinclude file="httpheader.jspf"
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync%><body>
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync<div id="page">
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync <div id="whole_header">
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync <div id="header"><%@
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncinclude file="pageheader.jspf"
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync%>
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync </div>
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync <div id="Masthead"></div>
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync <div id="bar">
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync <ul>
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync <li><a href="<%= request.getContextPath()
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync %>/"><span id="home"></span>Home</a></li>
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync </ul>
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync <%-- TODO: jel: IMHO it should be move to menu.jspf as combobox --%>
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync <div id="sortfield">
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync <label for="sortby">Sort by</label>
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync <ul id="sortby"><%
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync StringBuilder url = createUrl(searchHelper, true).append("&amp;sort=");
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync for (SortOrder o : SortOrder.values()) {
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync if (searchHelper.order == o) {
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync %><li><span class="active"><%= o.getDesc() %></span></li><%
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync } else {
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync %><li><a href="<%= url %><%= o %>"><%= o.getDesc() %></a></li><%
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync }
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync }
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync %></ul>
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync </div>
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync </div>
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync <div id="menu"><%@
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncinclude file="menu.jspf"
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
%>
</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><%
if (searchHelper.errorMsg.startsWith((SearchHelper.PARSE_ERROR_MSG))) {
%><%= Util.htmlize(SearchHelper.PARSE_ERROR_MSG) %>
<br/>You might try to enclose your search term in quotes,
<a href="help.jsp#escaping">escape special characters</a>
with <b>\</b>, or read the <a href="help.jsp">Help</a>
on the query language. Error message from parser:<br/>
<%= Util.htmlize(searchHelper.errorMsg.substring(
SearchHelper.PARSE_ERROR_MSG.length())) %><%
} else {
%><%= 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.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"
%>