%@ page import="java.io.*,
java.util.*,
java.text.*,
java.net.URL,
com.plumtree.remote.prc.*,
com.plumtree.remote.prc.search.*,
com.plumtree.openfoundation.util.*"
%>
Test Search Page
<%
//get the request params of search string and start page
String searchString = request.getParameter("searchString");
if (null == searchString)
{
searchString = "";
}
String startPage = request.getParameter("startPage");
if (null == startPage)
{
startPage = "1";
}
String startDate = request.getParameter("startDate");
if (null == startDate)
{
startDate = "";
}
int pageInt = 0;
pageInt = Integer.parseInt(startPage);
//startCount is the value we use for the first parameter is setResultsCount
int startCount = (pageInt * 10) -10;
%>
<%
//proceed if we have a search string
if (!(searchString.equals("")))
{
%>
Search for cards containing '<%= searchString %>'
<%
//set the endpoint to the value of your web services server
String endpoint =
"http://IP-GW-AS08:9080/ptapi/services/QueryInterfaceAPI";
URL url = new URL(endpoint);
//set username and password to log into your portal
//hard-coding the values is only for demo purposes
String username = "Administrator";
String password = "";
//get a remote session
IRemoteSession prcSession =
RemoteSessionFactory.getExplicitLoginContext(
url,
username,
password);
ISearchFactory searchFactory = prcSession.getSearchFactory();
IPortalSearchRequest searchRequest = searchFactory.createPortalSearchRequest();
//if we have a date, make a filter statement
if (null != startDate && (!(startDate.equals(""))))
{
DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
Date createdDate = format.parse(startDate);
IFilterClause filterClause = searchFactory.createAndFilterClause();
filterClause.addStatement(PlumtreeField.CREATED, Operator.GreaterThan, createdDate);
searchRequest.setQuery(searchString, filterClause);
}
else
{
searchRequest.setQuery(searchString);
}
//use 10 results at a time
searchRequest.setResultsCount(startCount, 10);
ISearchResponse searchResponse = searchRequest.execute();
int numResults = searchResponse.getReturnedCount();
int first_result = searchResponse.getFirstResultIndex();
int totalMatches = searchResponse.getTotalCount();
//print out overall info
out.println("
Overall Info
");
out.println("");
out.println("Total Matches: | " + totalMatches + " |
");
out.println("Number Returned: | " + numResults + " |
");
out.println("Warning: | " + searchResponse.getWarning() + " |
");
out.println("First Result (0-based): | " + first_result + " |
");
out.println("
");
//print out results if we have them
if (numResults > 0)
{
out.println("Results
");
out.print("");
ISearchResultSet resultSet = searchResponse.getResultSet();
Enumeration results = resultSet.getResults();
//print values and put results into hashmap to obtain properties in a new window
HashMap map = new HashMap();
while (results.hasMoreElements())
{
IPortalSearchResult result = (IPortalSearchResult) results.nextElement();
map.put("" + result.getRank(), result);
//results are 0 based- but we present them here to the end-user as 1 based.
out.print("" + (startCount + result.getRank() + 1) + " | ");
out.print(" + ") | ");
out.print("" + result.getName() +" | ");
out.print("Properties | ");
out.println("
");
out.println("" + result.getExcerpt() + " |
");
}//while (results.hasMoreElements())
session.setAttribute("resultsMap", map);
}// if (numResults > 0)
out.println("
");
//print the links at the bottom up to 150 results
out.println("");
int total = 15;
if (totalMatches < 150)
{
if ((totalMatches % 10) == 0)
{
total = totalMatches / 10;
}
else
{
total = (totalMatches / 10) + 1;
}
}
int currentPos = first_result;
currentPos = (currentPos / 10) + 1;
out.println("");
out.println("");
for (int i = 1; i <= total; i++)
{
if (i == currentPos)
{
out.print(i);
}
else
{
out.print("");
out.print(i);
out.println("");
}
out.print(" ");
}
out.println(" | ");
out.println("
");
out.println("
");
}
%>