search.jsp revision 59b6a8c0cc6ef741a7180504b3c371e67c2aa338
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark AndrewsCDDL HEADER START
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark AndrewsThe contents of this file are subject to the terms of the
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark AndrewsCommon Development and Distribution License (the "License").
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian WellingtonYou may not use this file except in compliance with the License.
068a66979695c77359e7a9181bb3f831c965b21cMark AndrewsSee LICENSE.txt included in this distribution for the specific
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellingtonlanguage governing permissions and limitations under the License.
0756445a735e2df39bf798d8de42ae5dd030aa3bMark AndrewsWhen distributing Covered Code, include this CDDL HEADER in each
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark Andrewsfile and include the License file at LICENSE.txt.
068a66979695c77359e7a9181bb3f831c965b21cMark AndrewsIf applicable, add the following below this CDDL HEADER, with the
f8f37672a57524560fbdde52484e6ae3de1c3354Mark Andrewsfields enclosed by brackets "[]" replaced with your own identifying
068a66979695c77359e7a9181bb3f831c965b21cMark Andrewsinformation: Portions Copyright [yyyy] [name of copyright owner]
a02a0a8a7eb461619931f4a0e896afa247b52c54Mark AndrewsCDDL HEADER END
0756445a735e2df39bf798d8de42ae5dd030aa3bMark AndrewsCopyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
a02a0a8a7eb461619931f4a0e896afa247b52c54Mark AndrewsPortions Copyright 2011 Jens Elkner.
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson--%><%@page session="false" errorPage="error.jsp" import="
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews private StringBuilder createUrl(SearchHelper sh, boolean menu) {
bac2ed6ec3fbb5420e6ce69dd1218745d4e02b1eMark Andrews StringBuilder url = new StringBuilder(64);
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews QueryBuilder qb = sh.builder;
bac2ed6ec3fbb5420e6ce69dd1218745d4e02b1eMark Andrews Util.appendQuery(url, "sort", sh.order.toString());
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews if (qb != null) {
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson Util.appendQuery(url, "path", qb.getPath());
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson if (sh.projects != null && sh.projects.size() != 0) {
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark Andrews Util.appendQuery(url, "project", cfg.getRequestedProjectsAsString());
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark Andrews/* ---------------------- search.jsp start --------------------- */
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews cfg = PageConfig.get(request);
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews long starttime = System.currentTimeMillis();
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews SearchHelper searchHelper = cfg.prepareSearch()
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews .prepareExec(cfg.getRequestedProjects()).executeQuery().prepareSummary();
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews && searchHelper.errorMsg.startsWith(SearchHelper.PARSE_ERROR_MSG))
eaccf5e805405de257b5a4840256c580fefe00e3Mark Andrews searchHelper.errorMsg = SearchHelper.PARSE_ERROR_MSG
cf33609457c0d3bffe915db9a437290b2fcd04d5Mark Andrews + "<br/>You might try to enclose your search term in quotes, "
cf33609457c0d3bffe915db9a437290b2fcd04d5Mark Andrews + "<a href=\"help.jsp#escaping\">escape special characters</a> "
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark Andrews + "with <b>\\</b>, or read the <a href=\"help.jsp\">Help</a> "
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews + "on the query language."
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson + "Error message from parser:<br/>" + searchHelper.errorMsg
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson .substring(SearchHelper.PARSE_ERROR_MSG.length());
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson cfg.setTitle("Search Error");
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson response.addCookie(new Cookie("OpenGrokSorting", searchHelper.order.toString()));
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington<div id="page">
c25080dc50542213058c240226c9f342186e6285Mark Andrews <div id="whole_header">
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews <div id="header"><%@
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews <div id="Masthead"></div>
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews <div id="bar">
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews <li><a href="<%= request.getContextPath()
c25080dc50542213058c240226c9f342186e6285Mark Andrews %>/"><span id="home"></span>Home</a></li>
413988c8166976498250c0ebb2e3a645d0366bd3Mark Andrews <%-- TODO: jel: IMHO it should be move to menu.jspf as combobox --%>
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews <div id="sortfield">
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews <label for="sortby">Sort by</label>
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews <ul id="sortby"><%
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews StringBuilder url = createUrl(searchHelper, true).append("&sort=");
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews for (SortOrder o : SortOrder.values()) {
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews %><li><span class="active"><%= o.getDesc() %></span></li><%
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews %><li><a href="<%= url %><%= o %>"><%= o.getDesc() %></a></li><%
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark Andrews <div id="menu"><%@
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark Andrews <div id="results"><%
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews // TODO spellchecking cycle below is not that great and we only create
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews // suggest links for every token in query, not for a query as whole
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews %><h3>Error</h3>
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews <p><%= Util.htmlize(searchHelper.errorMsg) %></p><%
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews } else if (searchHelper.hits == null) {
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews %><p>No hits</p><%
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews } else if (searchHelper.hits.length == 0) {
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews List<Suggestion> hints = searchHelper.getSuggestions();
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews for (Suggestion hint : hints) {
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews %><p><font color="#cc0000">Did you mean (for <%= hint.name %>)</font>:<%
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews for (String word : hint.freetext) {
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark Andrews %> <a href=search?q=<%= word %>><%= word %></a> <%
5752b9e296f14034f103149f18188770c2cc5239Mark Andrews for (String word : hint.refs) {
c25080dc50542213058c240226c9f342186e6285Mark Andrews %> <a href=search?refs=<%= word %>><%= word %></a> <%
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews for (String word : hint.defs) {
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews %> <a href=search?defs=<%= word %>><%= word %></a> <%
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews <p> Your search <b><%= searchHelper.query %></b> did not match any files.
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews <br/> Suggestions:<br/>
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark Andrews <li>Make sure all terms are spelled correctly.</li>
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark Andrews <li>Try different keywords.</li>
0756445a735e2df39bf798d8de42ae5dd030aa3bMark Andrews <li>Try more general keywords.</li>
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews <li>Use 'wil*' cards if you are looking for partial match.</li>
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson // We have a lots of results to show: create a slider for
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark Andrews String slider = "";
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews int thispage; // number of items to display on the current page
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington if (searchHelper.maxItems < searchHelper.totalHits) {
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark Andrews StringBuilder buf = new StringBuilder(4096);
09344332cf7840e7e219215128fd52ea4c3d6942Mark Andrews thispage = (start + max) < totalHits ? max : totalHits - start;
eaccf5e805405de257b5a4840256c580fefe00e3Mark Andrews StringBuilder urlp = createUrl(searchHelper, false);
fd42a013f17611b34cd49cc0abee0a6b0d251a6bMark Andrews int labelStart = 1;
09344332cf7840e7e219215128fd52ea4c3d6942Mark Andrews int sstart = start - max * (start / max % 10 + 1) ;
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson if (sstart < 0) {
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark Andrews labelStart = 1;
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark Andrews labelStart = sstart / max + 1;
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews int label = labelStart;
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews int labelEnd = label + 11;
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews for (int i = sstart; i < totalHits && label <= labelEnd; i+= max) {
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews if (i <= start && start < i + max) {
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews buf.append("<span class=\"sel\">").append(label).append("</span>");
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews buf.append("<a class=\"more\" href=\"s?n=").append(max)
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews .append("&start=").append(i).append(urlp).append("\">");
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews if (label == labelStart && label != 1) {
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews } else if (label == labelEnd && i < totalHits) {
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson // set the max index to max or last
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson thispage = totalHits - start;
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington <p class="pagetitle">Searched <b><%= searchHelper.query
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington %></b> (Results <b> <%= start + 1 %> - <%= thispage + start
eaccf5e805405de257b5a4840256c580fefe00e3Mark Andrews %></b> of <b><%= totalHits %></b>) sorted by <%=
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews <p class="slider"><%= slider %></p><%
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington Results.prettyPrint(out, searchHelper, start, start + thispage);
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington <p><b>Completed in <%= System.currentTimeMillis() - starttime
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington %> milliseconds</b></p><%
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington <p class="slider"><%= slider %></p><%
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington/* ---------------------- search.jsp end --------------------- */