search.jsp revision e8003fb3e52d438e9111a1833e48473f6e44e27d
47693af92e50a1ad81825eb01b7157a211269613mxCDDL HEADER START
47693af92e50a1ad81825eb01b7157a211269613mxThe contents of this file are subject to the terms of the
47693af92e50a1ad81825eb01b7157a211269613mxCommon Development and Distribution License (the "License").
47693af92e50a1ad81825eb01b7157a211269613mxYou may not use this file except in compliance with the License.
47693af92e50a1ad81825eb01b7157a211269613mxSee LICENSE.txt included in this distribution for the specific
47693af92e50a1ad81825eb01b7157a211269613mxlanguage governing permissions and limitations under the License.
47693af92e50a1ad81825eb01b7157a211269613mxWhen distributing Covered Code, include this CDDL HEADER in each
47693af92e50a1ad81825eb01b7157a211269613mxfile and include the License file at LICENSE.txt.
47693af92e50a1ad81825eb01b7157a211269613mxIf applicable, add the following below this CDDL HEADER, with the
47693af92e50a1ad81825eb01b7157a211269613mxfields enclosed by brackets "[]" replaced with your own identifying
47693af92e50a1ad81825eb01b7157a211269613mxinformation: Portions Copyright [yyyy] [name of copyright owner]
47693af92e50a1ad81825eb01b7157a211269613mxCDDL HEADER END
6f3e57ac9d0b054c3169579f3422080b8ba10105mxCopyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
6f3e57ac9d0b054c3169579f3422080b8ba10105mxPortions Copyright 2011 Jens Elkner.
6f3e57ac9d0b054c3169579f3422080b8ba10105mx<%@page session="false" errorPage="error.jsp" import="
6f3e57ac9d0b054c3169579f3422080b8ba10105mxinclude file="projects.jspf"
6f3e57ac9d0b054c3169579f3422080b8ba10105mx private StringBuilder createUrl(SearchHelper sh, boolean menu) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx StringBuilder url = new StringBuilder(64);
6f3e57ac9d0b054c3169579f3422080b8ba10105mx QueryBuilder qb = sh.builder;
6f3e57ac9d0b054c3169579f3422080b8ba10105mx if (menu) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx url.append("search?");
6f3e57ac9d0b054c3169579f3422080b8ba10105mx if (qb != null) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx Util.appendQuery(url, "project", cfg.getRequestedProjectsAsString());
6f3e57ac9d0b054c3169579f3422080b8ba10105mx return url;
6f3e57ac9d0b054c3169579f3422080b8ba10105mx/* ---------------------- search.jsp start --------------------- */
6f3e57ac9d0b054c3169579f3422080b8ba10105mx cfg = PageConfig.get(request);
6f3e57ac9d0b054c3169579f3422080b8ba10105mx String lastEditedDisplayMode = config.getInitParameter("lastEditedDisplayMode");
6f3e57ac9d0b054c3169579f3422080b8ba10105mx if (lastEditedDisplayMode != null) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx if(!(lastEditedDisplayMode.compareTo("true") == 0 ||
6f3e57ac9d0b054c3169579f3422080b8ba10105mx long starttime = System.currentTimeMillis();
6f3e57ac9d0b054c3169579f3422080b8ba10105mx SearchHelper searchHelper = cfg.prepareSearch();
6f3e57ac9d0b054c3169579f3422080b8ba10105mx request.setAttribute("SearchHelper", searchHelper);
6f3e57ac9d0b054c3169579f3422080b8ba10105mx searchHelper.prepareExec(cfg.getRequestedProjects()).executeQuery().prepareSummary();
6f3e57ac9d0b054c3169579f3422080b8ba10105mx if (searchHelper.redirect != null) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx if (searchHelper.errorMsg != null) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx cfg.setTitle("Search Error");
6f3e57ac9d0b054c3169579f3422080b8ba10105mx response.addCookie(new Cookie("OpenGrokSorting", URLEncoder.encode(searchHelper.order.toString(), "utf-8")));
6f3e57ac9d0b054c3169579f3422080b8ba10105mxinclude file="httpheader.jspf"
6f3e57ac9d0b054c3169579f3422080b8ba10105mx<div id="page">
6f3e57ac9d0b054c3169579f3422080b8ba10105mx <div id="whole_header">
6f3e57ac9d0b054c3169579f3422080b8ba10105mx <div id="header"><%@
6f3e57ac9d0b054c3169579f3422080b8ba10105mxinclude file="pageheader.jspf"
6f3e57ac9d0b054c3169579f3422080b8ba10105mx <div id="Masthead"></div>
6f3e57ac9d0b054c3169579f3422080b8ba10105mx <div id="bar">
6f3e57ac9d0b054c3169579f3422080b8ba10105mx <li><a href="<%= request.getContextPath()
6f3e57ac9d0b054c3169579f3422080b8ba10105mx %>/"><span id="home"></span>Home</a></li>
6f3e57ac9d0b054c3169579f3422080b8ba10105mx <%-- TODO: jel: IMHO it should be move to menu.jspf as combobox --%>
6f3e57ac9d0b054c3169579f3422080b8ba10105mx <div id="sortfield">
6f3e57ac9d0b054c3169579f3422080b8ba10105mx <label for="sortby">Sort by</label>
6f3e57ac9d0b054c3169579f3422080b8ba10105mx <ul id="sortby"><%
6f3e57ac9d0b054c3169579f3422080b8ba10105mx StringBuilder url = createUrl(searchHelper, true).append("&sort=");
6f3e57ac9d0b054c3169579f3422080b8ba10105mx for (SortOrder o : SortOrder.values()) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx %><li><span class="active"><%= o.getDesc() %></span></li><%
6f3e57ac9d0b054c3169579f3422080b8ba10105mx %><li><a href="<%= url %><%= o %>"><%= o.getDesc() %></a></li><%
6f3e57ac9d0b054c3169579f3422080b8ba10105mx <div id="menu"><%@
6f3e57ac9d0b054c3169579f3422080b8ba10105mxinclude file="menu.jspf"
6f3e57ac9d0b054c3169579f3422080b8ba10105mx <div id="results"> <%
6f3e57ac9d0b054c3169579f3422080b8ba10105mx // TODO spellchecking cycle below is not that great and we only create
6f3e57ac9d0b054c3169579f3422080b8ba10105mx // suggest links for every token in query, not for a query as whole
6f3e57ac9d0b054c3169579f3422080b8ba10105mx if (searchHelper.errorMsg != null) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx %><h3>Error</h3><p class="pagetitle"><%
6f3e57ac9d0b054c3169579f3422080b8ba10105mx if (searchHelper.errorMsg.startsWith((SearchHelper.PARSE_ERROR_MSG))) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx <br/>You might try to enclose your search term in quotes,
6f3e57ac9d0b054c3169579f3422080b8ba10105mx <a href="help.jsp#escaping">escape special characters</a>
6f3e57ac9d0b054c3169579f3422080b8ba10105mx with <b>\</b>, or read the <a href="help.jsp">Help</a>
6f3e57ac9d0b054c3169579f3422080b8ba10105mx on the query language. Error message from parser:<br/>
6f3e57ac9d0b054c3169579f3422080b8ba10105mx } else if (searchHelper.hits == null) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx %><p class="pagetitle">No hits</p><%
6f3e57ac9d0b054c3169579f3422080b8ba10105mx } else if (searchHelper.hits.length == 0) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx List<Suggestion> hints = searchHelper.getSuggestions();
6f3e57ac9d0b054c3169579f3422080b8ba10105mx for (Suggestion hint : hints) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx %><p class="suggestions"><font color="#cc0000">Did you mean (for <%= hint.name %>)</font>:<%
6f3e57ac9d0b054c3169579f3422080b8ba10105mx if (hint.freetext!=null) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx for (String word : hint.freetext) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx %> <a href="search?q=<%= Util.URIEncode(word) %>"><%=
6f3e57ac9d0b054c3169579f3422080b8ba10105mx Util.htmlize(word) %></a> <%
6f3e57ac9d0b054c3169579f3422080b8ba10105mx if (hint.refs!=null) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx for (String word : hint.refs) {
4045d94132614e1de2073685a6cdd4fbd86bec33sowmini %> <a href="search?refs=<%= Util.URIEncode(word) %>"><%=
6f3e57ac9d0b054c3169579f3422080b8ba10105mx Util.htmlize(word) %></a> <%
02d51d0d625c185ad277d9ad1ddf34b06f78b9b4jj if (hint.defs!=null) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx for (String word : hint.defs) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx %> <a href="search?defs=<%= Util.URIEncode(word) %>"><%=
6f3e57ac9d0b054c3169579f3422080b8ba10105mx Util.htmlize(word) %></a> <%
6f3e57ac9d0b054c3169579f3422080b8ba10105mx <p class="pagetitle"> Your search <b><%
6f3e57ac9d0b054c3169579f3422080b8ba10105mx did not match any files.
6f3e57ac9d0b054c3169579f3422080b8ba10105mx <br/> Suggestions:<br/>
6f3e57ac9d0b054c3169579f3422080b8ba10105mx <li>Make sure all terms are spelled correctly.</li>
6f3e57ac9d0b054c3169579f3422080b8ba10105mx <li>Try different keywords.</li>
6f3e57ac9d0b054c3169579f3422080b8ba10105mx <li>Try more general keywords.</li>
5a3d071821f538e6109877cf4a28881c159e8cfcmx <li>Use 'wil*' cards if you are looking for partial match.</li>
5a3d071821f538e6109877cf4a28881c159e8cfcmx <p><b>Completed in <%= System.currentTimeMillis() - starttime
afdda45f890ee5dfc86e5131a30b11b354d51633Vasumathi Sundaram - Sun Microsystems %> milliseconds</b></p>
5a3d071821f538e6109877cf4a28881c159e8cfcmx // We have a lots of results to show: create a slider for
4045d94132614e1de2073685a6cdd4fbd86bec33sowmini String slider = "";
5a3d071821f538e6109877cf4a28881c159e8cfcmx int thispage; // number of items to display on the current page
6f3e57ac9d0b054c3169579f3422080b8ba10105mx int totalHits = searchHelper.totalHits;
6f3e57ac9d0b054c3169579f3422080b8ba10105mx StringBuilder buf = new StringBuilder(4096);
6f3e57ac9d0b054c3169579f3422080b8ba10105mx thispage = (start + max) < totalHits ? max : totalHits - start;
6f3e57ac9d0b054c3169579f3422080b8ba10105mx StringBuilder urlp = createUrl(searchHelper, false);
6f3e57ac9d0b054c3169579f3422080b8ba10105mx int labelStart = 1;
6f3e57ac9d0b054c3169579f3422080b8ba10105mx int sstart = start - max * (start / max % 10 + 1) ;
6f3e57ac9d0b054c3169579f3422080b8ba10105mx if (sstart < 0) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx sstart = 0;
6f3e57ac9d0b054c3169579f3422080b8ba10105mx labelStart = 1;
6f3e57ac9d0b054c3169579f3422080b8ba10105mx labelStart = sstart / max + 1;
5a3d071821f538e6109877cf4a28881c159e8cfcmx int label = labelStart;
5a3d071821f538e6109877cf4a28881c159e8cfcmx int labelEnd = label + 11;
5a3d071821f538e6109877cf4a28881c159e8cfcmx for (int i = sstart; i < totalHits && label <= labelEnd; i+= max) {
5a3d071821f538e6109877cf4a28881c159e8cfcmx if (i <= start && start < i + max) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx buf.append("<span class=\"sel\">").append(label).append("</span>");
4045d94132614e1de2073685a6cdd4fbd86bec33sowmini buf.append("<a class=\"more\" href=\"s?n=").append(max)
4045d94132614e1de2073685a6cdd4fbd86bec33sowmini .append("&start=").append(i).append(urlp).append("\">");
4045d94132614e1de2073685a6cdd4fbd86bec33sowmini if (label == labelStart && label != 1) {
4045d94132614e1de2073685a6cdd4fbd86bec33sowmini } else if (label == labelEnd && i < totalHits) {
4045d94132614e1de2073685a6cdd4fbd86bec33sowmini // set the max index to max or last
6f3e57ac9d0b054c3169579f3422080b8ba10105mx thispage = totalHits - start;
6f3e57ac9d0b054c3169579f3422080b8ba10105mx <p class="pagetitle">Searched <b><%
6f3e57ac9d0b054c3169579f3422080b8ba10105mx %></b> (Results <b> <%= start + 1 %> - <%= thispage + start
6f3e57ac9d0b054c3169579f3422080b8ba10105mx %></b> of <b><%= totalHits %></b>) sorted by <%=
6f3e57ac9d0b054c3169579f3422080b8ba10105mx if (slider.length() > 0) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx <p class="slider"><%= slider %></p><%
6f3e57ac9d0b054c3169579f3422080b8ba10105mx Results.prettyPrint(out, searchHelper, start, start + thispage);
6f3e57ac9d0b054c3169579f3422080b8ba10105mx <p><b>Completed in <%= System.currentTimeMillis() - starttime
6f3e57ac9d0b054c3169579f3422080b8ba10105mx %> milliseconds</b></p><%
6f3e57ac9d0b054c3169579f3422080b8ba10105mx if (slider.length() > 0) {
6f3e57ac9d0b054c3169579f3422080b8ba10105mx <p class="slider"><%= slider %></p><%
6f3e57ac9d0b054c3169579f3422080b8ba10105mx // Note that searchHelper.destroy() is called via WebappListener.requestDestroyed().
6f3e57ac9d0b054c3169579f3422080b8ba10105mx/* ---------------------- search.jsp end --------------------- */
6f3e57ac9d0b054c3169579f3422080b8ba10105mxinclude file="foot.jspf"