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