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