search.jsp revision 8d5daad4d9da04018b562f0dd12044f5f53c1a66
1167fc7904c5f0a472f8df207ac46dd52c7f1ec8Automatic UpdaterCDDL HEADER START
46da3117812814a29432a8d9a9ccf8acdbfdadceAutomatic UpdaterThe contents of this file are subject to the terms of the
2bb3422dc683c013db7042f5736240de6b86f182Automatic UpdaterCommon Development and Distribution License (the "License").
cd0aa2d941d1438fabb5337f1f38c49478edf71dAutomatic UpdaterYou may not use this file except in compliance with the License.
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian WellingtonSee LICENSE.txt included in this distribution for the specific
ac4e70ff8955669341f435bc0a734a17c01af124Mark Andrewslanguage governing permissions and limitations under the License.
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian WellingtonWhen distributing Covered Code, include this CDDL HEADER in each
9cd5eb6fe0f26d65724b99216cb31dcdd12e4afdAutomatic Updaterfile and include the License file at LICENSE.txt.
e171a4137c6ba348957e61b7c4c3541493c0da02Automatic UpdaterIf applicable, add the following below this CDDL HEADER, with the
e171a4137c6ba348957e61b7c4c3541493c0da02Automatic Updaterfields enclosed by brackets "[]" replaced with your own identifying
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrewsinformation: Portions Copyright [yyyy] [name of copyright owner]
3cc98b8ecedcbc8465f1cf2740b966b315662430Automatic UpdaterCDDL HEADER END
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark AndrewsCopyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
e171a4137c6ba348957e61b7c4c3541493c0da02Automatic UpdaterPortions Copyright 2011 Jens Elkner.
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews--%><%@page session="false" errorPage="error.jsp" import="
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater private StringBuilder createUrl(SearchHelper sh, boolean menu) {
aa9c561961e9d877946ebaa8795fa2be054ab7bfEvan Hunt StringBuilder url = new StringBuilder(64);
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater QueryBuilder qb = sh.builder;
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater Util.appendQuery(url, "sort", sh.order.toString());
aa9c561961e9d877946ebaa8795fa2be054ab7bfEvan Hunt if (qb != null) {
2d2dc37599979c83495510f8af8d1756753aa2c5Automatic Updater Util.appendQuery(url, "q", qb.getFreetext());
2d2dc37599979c83495510f8af8d1756753aa2c5Automatic Updater Util.appendQuery(url, "defs", qb.getDefs());
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater Util.appendQuery(url, "path", qb.getPath());
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater Util.appendQuery(url, "hist", qb.getHist());
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater Util.appendQuery(url, "type", qb.getType());
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater if (sh.projects != null && sh.projects.size() != 0) {
cdfc81e048bd34c1d628380247bda6b80a89e20eAutomatic Updater Util.appendQuery(url, "project", cfg.getRequestedProjectsAsString());
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater/* ---------------------- search.jsp start --------------------- */
eabc9c3c07cd956d3c436bd7614cb162dabdda76Mark Andrews cfg = PageConfig.get(request);
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington String lastEditedDisplayMode = config.getInitParameter("lastEditedDisplayMode");
9cd5eb6fe0f26d65724b99216cb31dcdd12e4afdAutomatic Updater if (lastEditedDisplayMode != null) {
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews if(!(lastEditedDisplayMode.compareTo("true") == 0 ||
129090f0f6f91753b4a085ab635e28549fd018adAutomatic Updater lastEditedDisplayMode.compareTo("1") == 0 ||
80faf1588895fd26490f82f95a7a1b771df1c324Automatic Updater long starttime = System.currentTimeMillis();
1a06700908f5a1d9f4a8d51285a0fd971e2f9117Automatic Updater SearchHelper searchHelper = cfg.prepareSearch()
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews .prepareExec(cfg.getRequestedProjects()).executeQuery().prepareSummary();
693c4232dfdffaff672197d4b9fea944c64cf80aAutomatic Updater response.sendRedirect(searchHelper.redirect);
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson cfg.setTitle("Search Error");
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater response.addCookie(new Cookie("OpenGrokSorting", URLEncoder.encode(searchHelper.order.toString(), "utf-8")));
dd65eb1efb40b1c47d57963192bfc54873b219beAutomatic Updater<div id="page">
dd65eb1efb40b1c47d57963192bfc54873b219beAutomatic Updater <div id="whole_header">
78f3ed4bc2fcd3d270bfd599804f3b27a1db4d91Mark Andrews <div id="header"><%@
0c39b3ed9409ecb277d5e32fa763a4e4d6598df8Automatic Updater <div id="Masthead"></div>
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont <div id="bar">
f9119ad8f6114b2255e7545bf5cd187f4db0a89bAutomatic Updater <li><a href="<%= request.getContextPath()
e23256e740b238bddb4ba41ffac5f81a01c92245Automatic Updater %>/"><span id="home"></span>Home</a></li>
78f3ed4bc2fcd3d270bfd599804f3b27a1db4d91Mark Andrews <%-- TODO: jel: IMHO it should be move to menu.jspf as combobox --%>
08e3b6797706a13054bad749dea04e94b514b8e7Automatic Updater <div id="sortfield">
dd65eb1efb40b1c47d57963192bfc54873b219beAutomatic Updater <label for="sortby">Sort by</label>
78f3ed4bc2fcd3d270bfd599804f3b27a1db4d91Mark Andrews <ul id="sortby"><%
78f3ed4bc2fcd3d270bfd599804f3b27a1db4d91Mark Andrews StringBuilder url = createUrl(searchHelper, true).append("&sort=");
b29e5c56eb74a6de1a84c29879afc90ffc6b1436Automatic Updater for (SortOrder o : SortOrder.values()) {
78f3ed4bc2fcd3d270bfd599804f3b27a1db4d91Mark Andrews %><li><span class="active"><%= o.getDesc() %></span></li><%
0977f3f39ef6728516be7976452b9122c8f5607aAutomatic Updater %><li><a href="<%= url %><%= o %>"><%= o.getDesc() %></a></li><%
cdfc81e048bd34c1d628380247bda6b80a89e20eAutomatic Updater <div id="menu"><%@
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater <div id="results"><%
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson // TODO spellchecking cycle below is not that great and we only create
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater // suggest links for every token in query, not for a query as whole
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson %><h3>Error</h3><p class="pagetitle"><%
dd65eb1efb40b1c47d57963192bfc54873b219beAutomatic Updater if (searchHelper.errorMsg.startsWith((SearchHelper.PARSE_ERROR_MSG))) {
dd65eb1efb40b1c47d57963192bfc54873b219beAutomatic Updater %><%= Util.htmlize(SearchHelper.PARSE_ERROR_MSG) %>
dd65eb1efb40b1c47d57963192bfc54873b219beAutomatic Updater <br/>You might try to enclose your search term in quotes,
133e6d43fa82e80d3798be4de00f4540f485ec6cAutomatic Updater <a href="help.jsp#escaping">escape special characters</a>
133e6d43fa82e80d3798be4de00f4540f485ec6cAutomatic Updater with <b>\</b>, or read the <a href="help.jsp">Help</a>
133e6d43fa82e80d3798be4de00f4540f485ec6cAutomatic Updater on the query language. Error message from parser:<br/>
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater <%= Util.htmlize(searchHelper.errorMsg.substring(
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson SearchHelper.PARSE_ERROR_MSG.length())) %><%
4104e236f71eb5108fcfda6711878a97f6f4a8e7Automatic Updater %><%= Util.htmlize(searchHelper.errorMsg) %><%
27794bebe2634b5ac374e78972649c79300b876aAutomatic Updater } else if (searchHelper.hits == null) {
0ce87e5749aabb8eef1e0a37e4bd6e6ffa1d7196Automatic Updater %><p class="pagetitle">No hits</p><%
0ce87e5749aabb8eef1e0a37e4bd6e6ffa1d7196Automatic Updater } else if (searchHelper.hits.length == 0) {
27794bebe2634b5ac374e78972649c79300b876aAutomatic Updater List<Suggestion> hints = searchHelper.getSuggestions();
be63e68c516117af6af8850904e46a89c7d4423eAutomatic Updater for (Suggestion hint : hints) {
ede7b1df75ac53a9530bbbc9fc9db534cab82f44Automatic Updater %><p class="suggestions"><font color="#cc0000">Did you mean (for <%= hint.name %>)</font>:<%
f4029eb7463e99df00618de89f0bee5ac062a237Automatic Updater for (String word : hint.freetext) {
19b3dc94bce93fa76bd7e066f9298630dbc9dcb4Automatic Updater %> <a href="search?q=<%= Util.URIEncode(word) %>"><%=
d145b64cacc8d9cda51f9924ec70cd4661c3e2cfAutomatic Updater Util.htmlize(word) %></a> <%
f4029eb7463e99df00618de89f0bee5ac062a237Automatic Updater for (String word : hint.refs) {
e628576d3b3d91c8954679077f4c208f1e43b433Automatic Updater %> <a href="search?refs=<%= Util.URIEncode(word) %>"><%=
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater Util.htmlize(word) %></a> <%
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater for (String word : hint.defs) {
59528addd704f8d5757b54e540520f74e588a7c7Automatic Updater %> <a href="search?defs=<%= Util.URIEncode(word) %>"><%=
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater Util.htmlize(word) %></a> <%
c453a50776145e9c1c3fc9c846cfa11f42505081Automatic Updater <p class="pagetitle"> Your search <b><%
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater Util.htmlize(searchHelper.query.toString(), out); %></b>
19b3dc94bce93fa76bd7e066f9298630dbc9dcb4Automatic Updater did not match any files.
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater <br/> Suggestions:<br/>
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater <li>Make sure all terms are spelled correctly.</li>
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater <li>Try different keywords.</li>
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater <li>Try more general keywords.</li>
59528addd704f8d5757b54e540520f74e588a7c7Automatic Updater <li>Use 'wil*' cards if you are looking for partial match.</li>
71bd43eebd9d6e42dbcae62b730f5b6508d5acd8Automatic Updater <p><b>Completed in <%= System.currentTimeMillis() - starttime
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater %> milliseconds</b></p>
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater // We have a lots of results to show: create a slider for
9cd5eb6fe0f26d65724b99216cb31dcdd12e4afdAutomatic Updater String slider = "";
bbb069be941f649228760edcc241122933c066d2Automatic Updater int thispage; // number of items to display on the current page
9cd5eb6fe0f26d65724b99216cb31dcdd12e4afdAutomatic Updater if (searchHelper.maxItems < searchHelper.totalHits) {
80faf1588895fd26490f82f95a7a1b771df1c324Automatic Updater StringBuilder buf = new StringBuilder(4096);
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews thispage = (start + max) < totalHits ? max : totalHits - start;
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater StringBuilder urlp = createUrl(searchHelper, false);
e628576d3b3d91c8954679077f4c208f1e43b433Automatic Updater int labelStart = 1;
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews int sstart = start - max * (start / max % 10 + 1) ;
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews if (sstart < 0) {
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews labelStart = 1;
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews labelStart = sstart / max + 1;
957a8884fb712885cdd8ef0474f5ff95ddc46b20Automatic Updater int label = labelStart;
b109432c3a939bff66a463be86c371bd88efe3aaAutomatic Updater int labelEnd = label + 11;
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater for (int i = sstart; i < totalHits && label <= labelEnd; i+= max) {
995eaa289ba9709c64ef89b3776e53c36adc0010Automatic Updater if (i <= start && start < i + max) {
9cd5eb6fe0f26d65724b99216cb31dcdd12e4afdAutomatic Updater buf.append("<span class=\"sel\">").append(label).append("</span>");
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington buf.append("<a class=\"more\" href=\"s?n=").append(max)
9cd5eb6fe0f26d65724b99216cb31dcdd12e4afdAutomatic Updater .append("&start=").append(i).append(urlp).append("\">");
cf7e98f59148b559946a7f1ca728471374f1eef3Automatic Updater if (label == labelStart && label != 1) {
bf9b61c7904437745aeeb0f7d5036b35dad2a8a5Automatic Updater } else if (label == labelEnd && i < totalHits) {
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater // set the max index to max or last
3857cb6fcabeb79d85de4b3e3e4ab99912b701f8Mark Andrews thispage = totalHits - start;
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews <p class="pagetitle">Searched <b><%
9174e44c14b1cb91a651fa1dc29470438c246ab9Automatic Updater Util.htmlize(searchHelper.query.toString(), out);
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson %></b> (Results <b> <%= start + 1 %> - <%= thispage + start
e2caa7536302de34de6cc04025abcd53dc3a499aAutomatic Updater %></b> of <b><%= totalHits %></b>) sorted by <%=
0b57424d28c9a67018107133f9fbc0a7dcf057e2Mark Andrews <p class="slider"><%= slider %></p><%
78f3ed4bc2fcd3d270bfd599804f3b27a1db4d91Mark Andrews Results.prettyPrint(out, searchHelper, start, start + thispage);
78f3ed4bc2fcd3d270bfd599804f3b27a1db4d91Mark Andrews <p><b>Completed in <%= System.currentTimeMillis() - starttime
78f3ed4bc2fcd3d270bfd599804f3b27a1db4d91Mark Andrews %> milliseconds</b></p><%
78f3ed4bc2fcd3d270bfd599804f3b27a1db4d91Mark Andrews <p class="slider"><%= slider %></p><%
0b57424d28c9a67018107133f9fbc0a7dcf057e2Mark Andrews/* ---------------------- search.jsp end --------------------- */