Created
October 16, 2012 09:21
-
-
Save topolik/3898265 to your computer and use it in GitHub Desktop.
Redirecting to the only one search result in wiki/search portlet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
// ... OLD CONTENT | |
searchContext.setEnd(searchContainer.getEnd()); | |
searchContext.setKeywords(keywords); | |
searchContext.setNodeIds(nodeIds); | |
searchContext.setStart(searchContainer.getStart()); | |
Hits results = indexer.search(searchContext); | |
int total = results.getLength(); | |
// !!!!!!!!!!!!!!!!! MY NEW CONTENT !!!!!!!!!!! | |
if(total == 1){ | |
PortletURL myURL = renderResponse.createRenderURL(); | |
myURL.setParameter("struts_action", "/wiki/view"); | |
myURL.setParameter("nodeId", results.doc(0).get("nodeId")); | |
%> | |
<script type="text/javascript">window.location.href="<%= HtmlUtil.escapeJS(myURL.toString()) %>";</script> | |
<% | |
} | |
// OLD CONTENT CONTINUES ... | |
searchContainer.setTotal(total); | |
List resultRows = searchContainer.getResultRows(); | |
for (int i = 0; i < results.getDocs().length; i++) { | |
Document doc = results.doc(i); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment