view src/nabble/view/web/help/SearchHelp.jtp @ 0:7ecd1a4ef557

add content
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 21 Mar 2019 19:15:52 -0600
parents
children
line wrap: on
line source

<%
package nabble.view.web.help;

import fschmidt.util.java.HtmlUtils;
import nabble.model.Lucene;
import nabble.view.lib.Jtp;
import nabble.view.lib.Shared;
import nabble.view.lib.help.Help;
import org.apache.lucene.queryParser.ParseException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;


public class SearchHelp extends HttpServlet {

	static {
		Help.index();
	}
	
	protected void service(HttpServletRequest request,HttpServletResponse response)
		throws ServletException, IOException
	{
		PrintWriter out = response.getWriter();
		String errorMessage = null;
		String query = request.getParameter("query");
		if (query != null) {
			query = query.trim().replaceAll("\\band\\b","AND").replaceAll("\\bor\\b","OR").replaceAll("\\bnot\\b","NOT");
		}
		if (query == null || "".equals(query)) {
			response.sendRedirect("Index.jtp");
			return;
		}

		Help[] help = null;
		try {
			help = Lucene.searchHelp(query);
		} catch(ParseException e) {
			errorMessage = "This query is invalid.\nFor more information, read [link]http://lucene.apache.org/java/2_4_1/queryparsersyntax.html[/link]";
		}
		%>
		<html>
			<head>
				<% Shared.title(request,response,"Help"); %>
			</head>
			<body>
				<% Shared.helpHeader(request,response); %>
				<div class="content-description">
					<h1>Search Results</h1>
					<form action="<%=response.encodeURL("SearchHelp.jtp")%>" name="searchform">
						<input name="query" size="40" value="<%=HtmlUtils.htmlEncode(Jtp.hideNull(query))%>" />
						<input type="submit" value="Search" />
						<span class="small" style="margin-left:2em;"><a href="<%=response.encodeURL("Index.jtp")%>">Return to Help Topics</a> &#187;</span>
					</form>
					<p>
					<% if (errorMessage != null) {
						Shared.errorMessage(request, response, errorMessage, "Please check our <a href=\""+Help.search.url()+"\">search tips</a> page.");
					} else if (help != null && help.length==0) {
						%>
						No help topics found for <strong><%=HtmlUtils.htmlEncode(query)%></strong>
						<%
					} else {
						%>
						<strong><%=help.length%></strong> help topics found for <strong><%=HtmlUtils.htmlEncode(query)%></strong>
					</p>
					<ul>
					<%
					for (int i=0; i<help.length; i++) {
						%>
						<li><%=help[i].link(request)%></li>
						<%
					}
					%>
					</ul>
					<%
					}
					%>
					<p><br />If you still have questions, visit the <%=Jtp.supportLink()%> forum.</p>
				</div>
				<% Shared.footer(request,response); %>
				<% Shared.analytics(request,response); %>
			</body>
		</html>
		<%
	}
}
%>