/**
* $RCSfile: search.jsp,v $
* $Revision: 1.4 $
* $Date: 2000/12/21 03:14:58 $
*/
%>
import="java.util.*,
java.text.*,
com.coolservlets.forum.*,
com.coolservlets.forum.Query,
com.coolservlets.forum.util.*,
com.coolservlets.util.*"
errorPage="error.jsp"
%>
// global vars
private final String[] months =
{"January","February","March","April","May","June","July","August","September","October","November","December"};
private final int[] results =
{10,25,50,100};
private final SimpleDateFormat dateFormatter
= new SimpleDateFormat( "MMMM dd, yyyy 'at' h:mm:ss a z" );
%>
// Authorization check
// check for the existence of an authorization token
Authorization authToken = SkinUtils.getUserAuthorization(request,response);
// if the token was null, they're not authorized. Since this skin will
// allow guests to view forums, we'll set a "guest" authentication
// token
if( authToken == null ) {
authToken = AuthorizationFactory.getAnonymousAuthorization();
}
%>
// page forum variables
// do not delete these
ForumFactory forumFactory = ForumFactory.getInstance(authToken);
User user = forumFactory.getProfileManager().getUser(authToken.getUserID());
long userLastVisitedTime = SkinUtils.getLastVisited(request,response);
%>
// get parameters
boolean doSearch = ParamUtils.getBooleanParameter(request,"doSearch");
boolean advancedSearch = ParamUtils.getBooleanParameter(request,"adv");
String queryText = ParamUtils.getParameter(request,"q");
int forumID = ParamUtils.getIntParameter(request,"forum",-1);
int range = ParamUtils.getIntParameter(request,"numResults",10);
int start = ParamUtils.getIntParameter(request,"start",0);
int threadID = ParamUtils.getIntParameter(request,"thread",-1);
String between = ParamUtils.getParameter(request,"between");
String when = ParamUtils.getParameter(request,"when");
int month = ParamUtils.getIntParameter(request,"month",-1);
int day = ParamUtils.getIntParameter(request,"day",-1);
int fromMonth = ParamUtils.getIntParameter(request,"fromMonth",-1);
int fromDay = ParamUtils.getIntParameter(request,"fromDay",-1);
int toMonth = ParamUtils.getIntParameter(request,"toMonth",-1);
int toDay = ParamUtils.getIntParameter(request,"toDay",-1);
%>
ProfileManager manager = forumFactory.getProfileManager();
%>
// try loading up forums (exceptions may be thrown)
Forum forum = null;
boolean notAuthorizedToViewForum = false;
boolean forumNotFound = false;
forum = forumFactory.getForum(forumID);
String forumName = forum.getName();
ForumThread thread = null;
if( threadID > -1 ) {
thread = forum.getThread(threadID);
}
%>
// perform a search
Iterator searchResults = null;
Query query = null;
int numResults = -1;
if( doSearch && queryText!=null && forumID>0 ) {
query = forum.createQuery();
query.setQueryString(queryText);
// dates
if( between != null ) {
Calendar cal = Calendar.getInstance();
int todayMonth = cal.get(Calendar.MONTH);
int todayDay = cal.get(Calendar.DAY_OF_MONTH);
if( between.equals("false") ) {
if( month > -1 ) { cal.set(Calendar.MONTH,month); }
if( day > -1 ) { cal.set(Calendar.DAY_OF_MONTH,day); }
// before or after
if( when!=null && when.equals("before") && month > -1 && day > -1 ) {
query.setBeforeDate( cal.getTime() );
}
else if( when!=null && when.equals("after") && month > -1 && day > -1 ) {
query.setAfterDate( cal.getTime() );
}
}
else if( between.equals("true") ) {
if( fromMonth > -1 ) { cal.set(Calendar.MONTH,fromMonth); }
if( fromDay > -1 ) { cal.set(Calendar.DAY_OF_MONTH,fromDay); }
if( fromMonth > -1 && fromDay > -1 ) {
query.setBeforeDate( cal.getTime() );
}
// reset cal obj to today
cal.set(Calendar.MONTH,todayMonth);
cal.set(Calendar.DAY_OF_MONTH,todayDay);
if( toMonth > -1 ) { cal.set(Calendar.MONTH,toMonth); }
if( toDay > -1 ) { cal.set(Calendar.DAY_OF_MONTH,toDay); }
if( toMonth > -1 && toDay > -1 ) {
query.setAfterDate( cal.getTime() );
}
}
}
//query.filterOnUser( manager.getUser("bill") );
//if( thread != null ) {
// query.filterOnThread( thread );
//}
// run the search
searchResults = query.results(start,range);
// get the number of results
numResults = query.resultCount();
}
%>
// page title variable for header
String title = "Jive Forums: search";
%>
// page header
%>
// breadcrumb variable
String[][] breadcrumbs = {
{ "Home", "index.jsp" },
{ forumName, ("viewForum.jsp?forum="+forumID) },
{ "Search", "" }
};
%>
// toolbar variables
boolean showToolbar = true;
String viewLink = "viewForum.jsp?forum="+forumID;
String postLink = "post.jsp?mode=new&forum="+forumID;
String replyLink = null;
String searchLink = null;
String accountLink = "userAccount.jsp";
%>
value="">
>» Search
int todayMonth = today.get(Calendar.MONTH);
int todayDay = today.get(Calendar.DAY_OF_MONTH);
%>
function today( obj1, obj2, idx ) {
obj1.selectedIndex = ;
obj2.selectedIndex = ;
document.searchForm.between[idx].checked=true;
return false;
}
Date
AfterBefore this date
2000
[ onclick="return today(document.searchForm.month,document.searchForm.day,0);">today]
Between
2000
[ onclick="return today(document.searchForm.fromMonth,document.searchForm.fromDay,1);">today]and
2000
[ onclick="return today(document.searchForm.toMonth,document.searchForm.toDay,1);">today]
Number of Results
Show me
results per page.
document.searchForm.q.focus();
//-->
No results were found. Please try another search.
total results for ""
ForumMessage message = (ForumMessage)searchResults.next();
int messageID = message.getID();
int thisThreadID = message.getForumThread().getID();
User msgUser = message.getUser();
String name = msgUser.getName();
if( msgUser.isAnonymous() ) {
name = message.getProperty("name");
}
if( name == null ) {
name = "Anonymous";
}
String body = StringUtils.escapeHTMLTags(message.getUnfilteredBody());
body = StringUtils.chopAtWord(body, 150) + " ...";
body = StringUtils.highlightWords( body, queryWords, "", "" );
%>
)
>
Posted by: , on
"&adv="+advancedSearch+"&q="+((queryText!=null)?queryText:"")+
"&range="+range;
%>
int total = (numResults/range)+1;
int i = (start/range)+1;
int lTotal = i-1;
int rTotal = total-i;
int lCount, rCount;
if (i < 5) { lCount = lTotal; }
else { lCount = 5; }
if (i+5 > total) {
rCount = total-i;
//now, add as much as we can to other side
lCount += 5-(total-i) > lTotal-lCount? lTotal-lCount: 5-(total-i);
}
else {
rCount = 5;
//Add in more to right if possible;
if (lCount < 5) {
rCount += 5-lCount > rTotal-rCount? rTotal-rCount: 5-lCount;
}
}
%>
= 0 ) { %>
« Previous
>
Next »
Search Page:
>
// page footer
%>