<%@ page import="net.grcomputing.opencms.search.lucene.SearchHelper, org.apache.lucene.search.Hits,
org.apache.lucene.document.*, com.opencms.flex.jsp.*, java.util.Date" %>
<%
CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);
cms.include("system/modules/com.schiferli/jsptemplates/main.jsp", "head");
// This class has a bunch of useful methods for searching.
SearchHelper search = new SearchHelper(cms);
// Get the GET/POST parameter named "q"
String query = request.getParameter("q");
if(query != null) {
// This does a text search using the query provided.
// org.apache.lucene.hits are returned.
Hits hits = search.doSimpleSearch(query);
//out.println("Hits");
int i, j = hits.length();
if(j == 0) {
out.println("<h2>Your search found no matches. Please try again.</h2>");
} else {
float score;
Document doc;
String tLastMod;
if(j == 1)
out.println("<h2 class=\"search-mathces\">Your search found 1 match.</h2>");
else
out.println("<h2 class=\"search-matches\">Your search found " + Integer.toString(j) + " matches.</h2>");
// For each hit, get the Document and print out some information (including a link) about each item that
// matches.
for(i = 0; i<j; ++i) {
score = hits.score(i);
doc = hits.doc(i);
String lms = doc.get("last_modified");
if(lms != null && !"".equals(lms))
tLastMod = DateField.stringToDate(lms).toString();
else tLastMod = "unknown";
//tLastMod = "unknown";
out.println("<p class=\"search-hit\"><b class=\"search-hit-title\">"
+ "<a href=\"" + cms.link(doc.get("abs_path")) + "\" class=\"search-hit-link\">"
+ doc.get("title") + "</a></b><br><i class=\"search-hit-score\">");
//out.print(score); // Score is between 0.0 and 1.0
out.println("</i> " + doc.get("description") + " <br><span class=\"smalltext\">(Last modified: " + tLastMod + ")</span></p>");
}
}
}
%>
<form action="search.jsp">
<input type="text" name="q" value="">
<input type="submit">
</form>
<%
cms.include("system/modules/com.schiferli/jsptemplates/main.jsp", "foot");
%>