implemented UI for find posts, debugged and tweaked the engine implementation

This commit is contained in:
Eric J. Bowersox
2001-12-08 05:02:00 +00:00
parent 4b1acef325
commit ae129e5410
15 changed files with 730 additions and 116 deletions

View File

@@ -123,10 +123,9 @@ public interface UserContext extends SearchMode
public abstract boolean canSetUserPhoto() throws DataException;
public abstract List searchPosts(String search_terms, int offset, int count)
throws AccessError, DataException;
public abstract List searchPosts(String search_terms, int offset, int count) throws DataException;
public abstract int getSearchPostCount(String search_terms) throws AccessError, DataException;
public abstract int getSearchPostCount(String search_terms) throws DataException;
} // end interface UserContext

View File

@@ -1404,6 +1404,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
throw new IllegalArgumentException("invalid offset parameter");
if (count<=0)
throw new IllegalArgumentException("invalid count parameter");
testConferenceAccess();
Connection conn = null;
ArrayList rc = new ArrayList();
@@ -1416,11 +1417,11 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
// create the SQL statement
StringBuffer sql =
new StringBuffer("SELECT c.confid, t.topicid, t.topicnum, p.postid, p.num, p.creator_uid, "
+ "p.posted, p.linecount, d.data FROM confs c, sigtoconf s, topics t, posts p, "
+ "postdata d, users u LEFT JOIN sigmember m ON (s.sigid = m.sigid "
+ "AND u.uid = m.uid) LEFT JOIN confmember x ON (c.confid = x.confid AND "
+ "u.uid = x.uid) WHERE u.uid = ");
new StringBuffer("SELECT c.confid, t.topicid, t.num, p.postid, p.num, p.creator_uid, p.posted, "
+ "p.linecount, d.data FROM confs c, sigtoconf s, topics t, posts p, postdata d, "
+ "users u LEFT JOIN sigmember m ON (s.sigid = m.sigid AND u.uid = m.uid) "
+ "LEFT JOIN confmember x ON (c.confid = x.confid AND u.uid = x.uid) "
+ "WHERE u.uid = ");
sql.append(env.getUserID()).append(" AND c.confid = s.confid AND s.sigid = ");
sql.append(cid);
sql.append(" AND GREATEST(u.base_lvl,IFNULL(m.granted_lvl,0),s.granted_lvl,IFNULL(x.granted_lvl,0)) "
@@ -1462,6 +1463,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
logger.debug("getSearchPostCount('" + search_terms + ") entry");
if (search_terms==null)
throw new NullPointerException("invalid search terms");
testConferenceAccess();
Connection conn = null;

View File

@@ -1635,7 +1635,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
throw new IllegalArgumentException("invalid offset parameter");
if (count<=0)
throw new IllegalArgumentException("invalid count parameter");
if (getConferenceData().canReadConference(level))
if (!(getConferenceData().canReadConference(level)))
throw new AccessError("You are not permitted to search for posts within this conference.");
Connection conn = null;
@@ -1649,8 +1649,8 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
// create the SQL statement
StringBuffer sql =
new StringBuffer("SELECT t.topicid, t.topicnum, p.postid, p.num, p.creator_uid, p.posted, "
+ "p.linecount, d.data FROM topics t, posts p, postdata d WHERE t.confid = ");
new StringBuffer("SELECT t.topicid, t.num, p.postid, p.num, p.creator_uid, p.posted, p.linecount, "
+ "d.data FROM topics t, posts p, postdata d WHERE t.confid = ");
sql.append(confid);
sql.append(" AND t.topicid = p.topicid AND p.scribble_uid IS NULL AND p.postid = d.postid "
+ "AND MATCH(d.data) AGAINST(");
@@ -1691,7 +1691,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
if (search_terms==null)
throw new NullPointerException("invalid search terms");
if (getConferenceData().canReadConference(level))
if (!(getConferenceData().canReadConference(level)))
throw new AccessError("You are not permitted to search for posts within this conference.");
Connection conn = null;

View File

@@ -73,7 +73,10 @@ class TopicMessageFoundImpl implements TopicMessageFound
private static final String transformText(String text)
{
return text; // TEMP
// TEMPORARY IMPLEMENTATION
if (text.length()<60)
return text;
return text.substring(0,60) + "...";
} // end transformText

View File

@@ -27,6 +27,7 @@ import com.silverwrist.venice.core.internals.*;
import com.silverwrist.venice.db.*;
import com.silverwrist.venice.except.*;
import com.silverwrist.venice.security.*;
import com.silverwrist.venice.svc.ServiceControl;
class UserContextImpl implements UserContext, UserBackend
{
@@ -1431,7 +1432,7 @@ class UserContextImpl implements UserContext, UserBackend
} // end canSetUserPhoto
public List searchPosts(String search_terms, int offset, int count) throws AccessError, DataException
public List searchPosts(String search_terms, int offset, int count) throws DataException
{
if (logger.isDebugEnabled())
logger.debug("searchPosts('" + search_terms + "', " + offset + ", " + count + ") entry");
@@ -1442,6 +1443,7 @@ class UserContextImpl implements UserContext, UserBackend
if (count<=0)
throw new IllegalArgumentException("invalid count parameter");
ServiceToken conf_token = env.getSCM().getTokenForSymbol(ServiceControl.SVCGRP_COMMUNITY,"Conference");
Connection conn = null;
ArrayList rc = new ArrayList();
@@ -1453,15 +1455,16 @@ class UserContextImpl implements UserContext, UserBackend
// create the SQL statement
StringBuffer sql =
new StringBuffer("SELECT s.sigid, c.confid, t.topicid, t.topicnum, p.postid, p.num, p.creator_uid, "
new StringBuffer("SELECT s.sigid, c.confid, t.topicid, t.num, p.postid, p.num, p.creator_uid, "
+ "p.posted, p.linecount, d.data FROM confs c, sigtoconf s, topics t, posts p, "
+ "postdata d, users u, sigmember m LEFT JOIN confmember x "
+ "postdata d, users u, sigmember m, sigftrs f LEFT JOIN confmember x "
+ "ON (c.confid = x.confid AND u.uid = x.uid) WHERE u.uid = ");
sql.append(uid);
sql.append(" AND c.confid = s.confid AND s.sigid = m.sigid AND m.uid = u.uid AND "
+ "GREATEST(u.base_lvl,m.granted_lvl,s.granted_lvl,IFNULL(x.granted_lvl,0)) >= c.read_lvl "
+ "AND t.confid = c.confid AND t.topicid = p.topicid AND p.scribble_uid IS NULL AND "
+ "p.postid = d.postid AND MATCH(d.data) AGAINST (");
sql.append(" AND s.sigid = m.sigid AND m.uid = u.uid AND s.sigid = f.sigid AND f.ftr_code = ");
sql.append(conf_token.getIndex());
sql.append(" AND c.confid = s.confid AND GREATEST(u.base_lvl,m.granted_lvl,s.granted_lvl,"
+ "IFNULL(x.granted_lvl,0)) >= c.read_lvl AND t.confid = c.confid AND t.topicid = p.topicid "
+ "AND p.scribble_uid IS NULL AND p.postid = d.postid AND MATCH(d.data) AGAINST (");
sql.append(SQLUtil.encodeStringArg(search_terms)).append(") LIMIT ").append(offset).append(", ");
sql.append(count).append(';');
@@ -1492,13 +1495,14 @@ class UserContextImpl implements UserContext, UserBackend
} // end searchPosts
public int getSearchPostCount(String search_terms) throws AccessError, DataException
public int getSearchPostCount(String search_terms) throws DataException
{
if (logger.isDebugEnabled())
logger.debug("getSearchPostCount('" + search_terms + ") entry");
if (search_terms==null)
throw new NullPointerException("invalid search terms");
ServiceToken conf_token = env.getSCM().getTokenForSymbol(ServiceControl.SVCGRP_COMMUNITY,"Conference");
Connection conn = null;
try
@@ -1509,13 +1513,14 @@ class UserContextImpl implements UserContext, UserBackend
// create the SQL statement
StringBuffer sql =
new StringBuffer("SELECT COUNT(*) FROM confs c, sigtoconf s, topics t, posts p, postdata d, "
+ "users u, sigmember m LEFT JOIN confmember x ON (c.confid = x.confid AND "
+ "u.uid = x.uid) WHERE u.uid = ");
+ "users u, sigmember m, sigftrs f LEFT JOIN confmember x ON (c.confid = x.confid "
+ "AND u.uid = x.uid) WHERE u.uid = ");
sql.append(uid);
sql.append(" AND c.confid = s.confid AND s.sigid = m.sigid AND m.uid = u.uid AND "
+ "GREATEST(u.base_lvl,m.granted_lvl,s.granted_lvl,IFNULL(x.granted_lvl,0)) >= c.read_lvl "
+ "AND t.confid = c.confid AND t.topicid = p.topicid AND p.scribble_uid IS NULL AND "
+ "p.postid = d.postid AND MATCH(d.data) AGAINST (");
sql.append(" AND s.sigid = m.sigid AND m.uid = u.uid AND s.sigid = f.sigid AND f.ftr_code = ");
sql.append(conf_token.getIndex());
sql.append(" AND c.confid = s.confid AND GREATEST(u.base_lvl,m.granted_lvl,s.granted_lvl,"
+ "IFNULL(x.granted_lvl,0)) >= c.read_lvl AND t.confid = c.confid AND t.topicid = p.topicid "
+ "AND p.scribble_uid IS NULL AND p.postid = d.postid AND MATCH(d.data) AGAINST (");
sql.append(SQLUtil.encodeStringArg(search_terms)).append(");");
// execute the query and load the results

View File

@@ -0,0 +1,113 @@
/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.servlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.except.*;
import com.silverwrist.venice.servlets.format.*;
public class FindPost extends VeniceServlet
{
/*--------------------------------------------------------------------------------
* Overrides from class HttpServlet
*--------------------------------------------------------------------------------
*/
public String getServletInfo()
{
String rc = "FindPost servlet - Searches for posts in communities, conferences, and/or topics\n"
+ "Part of the Venice Web Communities System\n";
return rc;
} // end getServletInfo
/*--------------------------------------------------------------------------------
* Overrides from class VeniceServlet
*--------------------------------------------------------------------------------
*/
protected VeniceContent doVeniceGet(HttpServletRequest request, VeniceEngine engine,
UserContext user, RenderData rdat)
throws ServletException, IOException, VeniceServletResult
{
CommunityContext comm = getCommunityParameter(request,user,true,"top");
changeMenuCommunity(request,comm);
String locator = "sig=" + comm.getCommunityID();
ConferenceContext conf = getConferenceParameter(request,comm,false,"confops?" + locator);
TopicContext topic = null;
if (conf!=null)
{ // find the topic parameter
locator += ("&conf=" + conf.getConfID());
topic = getTopicParameter(request,conf,false,"confdisp?" + locator);
if (topic!=null)
locator += ("&top=" + topic.getTopicNumber());
} // end if
setMyLocation(request,"findpost?" + locator);
return new FindPostData(comm,conf,topic);
} // end doVeniceGet
protected VeniceContent doVenicePost(HttpServletRequest request, VeniceEngine engine,
UserContext user, RenderData rdat)
throws ServletException, IOException, VeniceServletResult
{
CommunityContext comm = getCommunityParameter(request,user,true,"top");
changeMenuCommunity(request,comm);
String locator = "sig=" + comm.getCommunityID();
ConferenceContext conf = getConferenceParameter(request,comm,false,"confops?" + locator);
TopicContext topic = null;
if (conf!=null)
{ // find the topic parameter
locator += ("&conf=" + conf.getConfID());
topic = getTopicParameter(request,conf,false,"confdisp?" + locator);
if (topic!=null)
locator += ("&top=" + topic.getTopicNumber());
} // end if
setMyLocation(request,"findpost?" + locator);
FindPostData data = new FindPostData(comm,conf,topic);
try
{ // attempt to configure the display
data.doSearch(request,engine);
} // end try
catch (AccessError ae)
{ // error in find parameters
return new ErrorBox("Find Error",ae.getMessage(),"top");
} // end catch
catch (DataException de)
{ // database error, man
return new ErrorBox("Database Error","Database error on find: " + de.getMessage(),"top");
} // end catch
return data;
} // end doVenicePost
} // end class FindPost

View File

@@ -39,6 +39,7 @@ public class FindData implements JSPRender, SearchMode
public static final int FD_COMMUNITIES = 0;
public static final int FD_USERS = 1;
public static final int FD_CATEGORIES = 2;
public static final int FD_POSTS = 3;
// The titles and URLs of the header data
private static Vector header_titles = null;
@@ -78,12 +79,14 @@ public class FindData implements JSPRender, SearchMode
header_titles.add("Communities");
header_titles.add("Users");
header_titles.add("Categories");
header_titles.add("Posts");
header_titles.trimToSize();
header_urls = new Vector();
header_urls.add("find?disp=" + String.valueOf(FD_COMMUNITIES));
header_urls.add("find?disp=" + String.valueOf(FD_USERS));
header_urls.add("find?disp=" + String.valueOf(FD_CATEGORIES));
header_urls.add("find?disp=" + String.valueOf(FD_POSTS));
header_urls.trimToSize();
} // end if
@@ -128,7 +131,7 @@ public class FindData implements JSPRender, SearchMode
public static int getNumChoices()
{
return FD_CATEGORIES + 1;
return FD_POSTS + 1;
} // end getNumChoices
@@ -303,7 +306,8 @@ public class FindData implements JSPRender, SearchMode
break;
case FD_CATEGORIES:
// no parameters to set here - there's no "field" for category search
case FD_POSTS:
// no parameters to set here - there's no "field" for category/post search
break;
default:
@@ -311,10 +315,13 @@ public class FindData implements JSPRender, SearchMode
} // end switch
// Validate the search mode parameter.
mode = getParamInt(request,"mode",SEARCH_PREFIX);
if ((mode!=SEARCH_PREFIX) && (mode!=SEARCH_SUBSTRING) && (mode!=SEARCH_REGEXP))
throw new ValidationException("The search mode parameter is not valid.");
if (disp!=FD_POSTS)
{ // Validate the search mode parameter.
mode = getParamInt(request,"mode",SEARCH_PREFIX);
if ((mode!=SEARCH_PREFIX) && (mode!=SEARCH_SUBSTRING) && (mode!=SEARCH_REGEXP))
throw new ValidationException("The search mode parameter is not valid.");
} // end if
// Retrieve the search term parameter.
term = request.getParameter("term");
@@ -379,6 +386,12 @@ public class FindData implements JSPRender, SearchMode
find_count = user.getSearchCategoryCount(mode,term);
break;
case FD_POSTS:
results = user.searchPosts(term,offset,count);
if (find_count<0)
find_count = user.getSearchPostCount(term);
break;
} // end switch
} // end loadPost

View File

@@ -0,0 +1,275 @@
/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.servlets.format;
import java.io.Writer;
import java.io.IOException;
import java.util.*;
import javax.servlet.*;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.except.*;
public class FindPostData implements JSPRender
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
// Attribute name for request attribute
protected static final String ATTR_NAME = "com.silverwrist.venice.content.FindPostData";
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private CommunityContext comm;
private ConferenceContext conf;
private TopicContext topic;
private String term = "";
private int offset = 0;
private int find_count = 0;
private List results = null;
private int max_results = 0;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
public FindPostData(CommunityContext comm, ConferenceContext conf, TopicContext topic)
{
this.comm = comm;
this.conf = conf;
this.topic = topic;
} // end constructor
/*--------------------------------------------------------------------------------
* Internal static functions
*--------------------------------------------------------------------------------
*/
private static int getParamInt(ServletRequest request, String name, int default_val)
{
String str = request.getParameter(name);
if (str==null)
return -1;
try
{ // parse the integer value
return Integer.parseInt(str);
} // end try
catch (NumberFormatException nfe)
{ // in case of conversion error, fall through
} // end catch
return default_val;
} // end getParamInt
private static boolean isImageButtonClicked(ServletRequest request, String name)
{
String val = request.getParameter(name + ".x");
return (val!=null);
} // end isImageButtonClicked
/*--------------------------------------------------------------------------------
* External static functions
*--------------------------------------------------------------------------------
*/
public static FindPostData retrieve(ServletRequest request)
{
return (FindPostData)(request.getAttribute(ATTR_NAME));
} // end retrieve
/*--------------------------------------------------------------------------------
* Implementations from interface VeniceContent
*--------------------------------------------------------------------------------
*/
public String getPageTitle(RenderData rdat)
{
return "Find Posts";
} // end getPageTitle
public String getPageQID()
{
return null;
} // end getPageQID
/*--------------------------------------------------------------------------------
* Implementations from interface JSPRender
*--------------------------------------------------------------------------------
*/
public void store(ServletRequest request)
{
request.setAttribute(ATTR_NAME,this);
} // end store
public String getTargetJSPName()
{
return "findpost.jsp";
} // end getTargetJSPName
/*--------------------------------------------------------------------------------
* External operations
*--------------------------------------------------------------------------------
*/
public final void doSearch(ServletRequest request, VeniceEngine engine) throws AccessError, DataException
{
max_results = engine.getStdNumSearchResults();
// Retrieve the search term parameter.
term = request.getParameter("term");
if (term==null)
term = "";
// Retrieve the offset and find count parameters.
offset = getParamInt(request,"ofs",0);
find_count = getParamInt(request,"fcount",-1);
// Adjust the search return offset based on the command button click.
if (isImageButtonClicked(request,"search"))
offset = 0;
else if (isImageButtonClicked(request,"previous"))
{ // adjust the offset in the reverse direction
offset -= max_results;
if (offset<0)
offset = 0;
} // end else if
else if (isImageButtonClicked(request,"next"))
offset += max_results; // go forwards instead
else
throw new InternalStateError("Unable to determine what action triggered the form.");
if (topic!=null)
{ // search the topic
results = topic.searchPosts(term,offset,max_results);
if (find_count<0)
find_count = topic.getSearchPostCount(term);
} // end if
else if (conf!=null)
{ // search the conference
results = conf.searchPosts(term,offset,max_results);
if (find_count<0)
find_count = conf.getSearchPostCount(term);
} // end else if
else
{ // search the community
results = comm.searchPosts(term,offset,max_results);
if (find_count<0)
find_count = comm.getSearchPostCount(term);
} // end else
} // end doSearch
public final String getExtraParameters()
{
StringBuffer buf = new StringBuffer("<INPUT TYPE=\"HIDDEN\" NAME=\"sig\" VALUE=\"");
buf.append(comm.getCommunityID()).append("\">");
if (conf!=null)
{ // append the conference number parameter
buf.append("\n<INPUT TYPE=\"HIDDEN\" NAME=\"conf\" VALUE=\"").append(conf.getConfID()).append("\">");
if (topic!=null)
{ // append the topic number parameter
buf.append("\n<INPUT TYPE=\"HIDDEN\" NAME=\"top\" VALUE=\"").append(topic.getTopicNumber());
buf.append("\">");
} // end if
} // end if
return buf.toString();
} // end getExtraParameters
public final String getReturnLink(RenderData rdat)
{
if (topic!=null)
return "<A HREF=\"" + rdat.getEncodedServletPath("confdisp?sig=" + comm.getCommunityID()
+ "&conf=" + conf.getConfID() + "&top="
+ topic.getTopicNumber()) + "\">Return to Topic</A>";
else if (conf!=null)
return "<A HREF=\"" + rdat.getEncodedServletPath("confdisp?sig=" + comm.getCommunityID()
+ "&conf=" + conf.getConfID())
+ "\">Return to Topic List</A>";
else
return "<A HREF=\"" + rdat.getEncodedServletPath("confops?sig=" + comm.getCommunityID())
+ "\">Return to Topic List</A>";
} // end getReturnLink
public final String getSubtitle()
{
if (topic!=null)
return "Topic: " + topic.getName();
else if (conf!=null)
return "Conference: " + conf.getName();
else
return "Community: " + comm.getName();
} // end getSubtitle
public final String getTerm()
{
return term;
} // end getTerm
public final int getOffset()
{
return offset;
} // end getOffset
public final int getFindCount()
{
return find_count;
} // end getFindCount
public final List getResults()
{
return results;
} // end getResults
public final int getMaxResults()
{
return max_results;
} // end getMaxResults
} // end class FindPostData