[opencms-dev] Search Help | OpenCms 6
Kelley, Kevin
kkelley at onetooneinteractive.com
Mon Aug 22 16:13:27 CEST 2005
Greetings All,
This is a general question in getting search to work. I have copied the
following code from the alkacon-documentation module. On my template
jsp, I put the following:
<%@ page buffer="none" import="org.opencms.main.*, org.opencms.search.*,
org.opencms.file.*, org.opencms.jsp.*, java.util.*" %>
<%
org.opencms.jsp.CmsJspActionElement cms = new
CmsJspActionElement(pageContext, request, response);
CmsSearchManager searchManager = OpenCms.getSearchManager();
%>
<jsp:useBean id="search" scope="request"
class="org.opencms.search.CmsSearch">
<jsp:setProperty name="search" property="*"/>
<% search.init(cms.getCmsObject()); %>
</jsp:useBean>
<form method="post" action="<cms:link>/search/result.jsp</cms:link>">
<input type="hidden" name="matchesperpage" value="20">
<tr>
<nobr><input type="text" name="query" size="10"
value="<%=(cms.property("query") != null) ? cms.property("query") :
""%>"> <input type="submit" value="Search"></nobr>
</td>
</tr>
</form>
On my result.jsp, I copied the code exactly from the result.jsp in the
alkacon-documentation module. I then updated the search index page.
When I performed a search, the search result page showed up with no
results on it. The code is below: Is there any detailed docs on
integrating search? Thanks!
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
<%@ page buffer="none" import="org.opencms.main.*, org.opencms.search.*,
org.opencms.file.*, org.opencms.jsp.*, java.util.*" %><%
// Create a JSP action element
org.opencms.jsp.CmsJspActionElement cms = new
CmsJspActionElement(pageContext, request, response);
// Get the search manager
CmsSearchManager searchManager = OpenCms.getSearchManager();
%>
<jsp:useBean id="search" scope="request"
class="org.opencms.search.CmsSearch">
<jsp:setProperty name = "search" property="matchesPerPage"
param="matchesperpage"/>
<jsp:setProperty name = "search" property="*"/>
<%
search.init(cms.getCmsObject());
%>
</jsp:useBean>
<cms:include property="template" element="head" />
<h1>Search result</h1>
<%
int resultno = 1;
int pageno = 0;
if (request.getParameter("page")!=null) {
pageno = Integer.parseInt(request.getParameter("page"))-1;
}
resultno = (pageno*search.getMatchesPerPage())+1;
String fields = search.getFields();
if (fields==null) {
fields = request.getParameter("fields");
}
List result = search.getSearchResult();
if (result == null) {
%>
<%
if (search.getLastException() != null) {
%>
<h3>Error</h3>
<%= search.getLastException().toString() %>
<%
}
} else {
ListIterator iterator = result.listIterator();
%>
<h3><%= search.getSearchResult().size() %> Results found for query
<<%= search.getQuery() %>> in fields <%= fields %></h3>
<%
while (iterator.hasNext()) {
CmsSearchResult entry = (CmsSearchResult)iterator.next();
%>
<h3><%= resultno %>. <a href="<%=
cms.link(cms.getRequestContext().removeSiteRoot(entry.getPath()))
%>"><%= entry.getTitle() %></a> (<%= entry.getScore() %>%)</h3>
<h6>Keywords</h6>
<%= entry.getKeywords() %>
<h6>Excerpt</h6>
<%= entry.getExcerpt() %>
<h6>Description</h6>
<%= entry.getDescription() %>
<h6>Last modified</h6>
<%= entry.getDateLastModified() %>
<%
resultno++;
}
}
%>
<%
if (search.getPreviousUrl() != null) {
%>
<input type="button" value="<< previous"
onclick="location.href='<%= cms.link(search.getPreviousUrl())
%>&fields=<%= fields %>';">
<%
}
Map pageLinks = search.getPageLinks();
Iterator i = pageLinks.keySet().iterator();
while (i.hasNext()) {
int pageNumber = ((Integer)i.next()).intValue();
String pageLink = cms.link((String)pageLinks.get(new
Integer(pageNumber)));
out.print(" ");
if (pageNumber != search.getPage()) {
%>
<a href="<%= pageLink %>&fields=<%= fields %>"><%=
pageNumber %></a>
<%
} else {
%>
<span class="currentpage"><%= pageNumber %></span>
<%
}
}
if (search.getNextUrl() != null) {
%>
<input type="button" value="next >>"
onclick="location.href='<%= cms.link(search.getNextUrl()) %>&fields=<%=
fields %>';">
<%
}
%>
</body>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20050822/f4f1d120/attachment.htm>
More information about the opencms-dev
mailing list