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