📄 searchthreadaction.java
字号:
if (index != null && index.size()>0) {
String message = "对不起,您在 " + searchctrl+ " 秒内只能进行一次搜索,请返回。";
request.setAttribute("errorInfo", message);
return mapping.findForward("showMessage");
}
index = null;
}
if (!maxspm.equals("0")) {
int times = timestamp - 60;
String maxhql = "select count(*) from Searchindex as s where s.useip='" + ip + "' and uid=" + uid + " and s.dateline>=" + times;
int count = searchServer.findseachindexcountbyHql(maxhql);
if (count >= convertInt(maxspm)) {
String message = "对不起,管理员设置了每分钟系统最多响应搜索请求 " + maxspm + " 次,请返回并稍后再试。";
request.setAttribute("errorInfo", message);
return mapping.findForward("showMessage");
}
}
StringBuffer threadhql = new StringBuffer();
if (srchtype.equals("fulltext")) {
threadhql.append("select t.tid from jrun_threads as t left join jrun_posts as p on t.tid=p.tid where t.displayorder>='0' and ");
} else {
threadhql.append("select t.tid from jrun_threads as t where t.displayorder>='0' and ");
}
if (!srchtxt.equals("")) {
srchtxt = srchtxt.replaceAll("\\*", "%");
srchtxt = srchtxt.toLowerCase();
if (Common.matches(srchtxt,"[and|\\+|&|\\s+]") && !Common.matches(srchtxt,"[or|\\|]")) {
srchtxt = srchtxt.replaceAll("( and |&| )", "+");
String[] keyword = srchtxt.split("\\+");
for (int i = 0; i < keyword.length; i++) {
if (srchtype.equals("fulltext")) {
threadhql.append("p.message like '%" + keyword[i].trim()+ "%' and ");
} else {
threadhql.append("t.subject like '%" + keyword[i].trim()+ "%' and ");
}
}
} else {
srchtxt = srchtxt.replaceAll("( or |\\|)", "+");
String[] keyword = srchtxt.split("\\+");
if(srchtype.equals("fulltext")){
threadhql.append("(");
for (int i = 0; i < keyword.length; i++) {
threadhql.append("p.message like '%" + keyword[i].trim()+ "%' or ");
}
}else{
threadhql.append("(");
for (int i = 0; i < keyword.length; i++) {
threadhql.append("t.subject like '%" + keyword[i].trim()+ "%' or ");
}
}
}
}
int lastor = threadhql.lastIndexOf("or ");
if (lastor > 0) {
threadhql.delete(lastor, threadhql.length());
threadhql.append(") and ");
}
if (!srchuname.equals("")) {
String uids = "-1";
srchuname = srchuname.replaceAll("\\*", "%");
String memhql = "select uid from jrun_members as m where m.username like '"+ srchuname.trim() + "' limit 0,50";
List<Map<String,String>> memberlist = dataBaseService.executeQuery(memhql, new String[]{"uid"});
if (memberlist != null && memberlist.size() > 0) {
for (Map<String,String> members : memberlist) {
uids += "," + members.get("uid");
}
}
if (!uids.equals("")) {
if (srchtype.equals("fulltext")) {
threadhql.append("p.authorid in ( " + uids + " ) and ");
} else {
threadhql.append("t.authorid in ( " + uids + " ) and ");
}
}
}
if(srchuid!=null && !srchuid.equals("0")){
threadhql.append("t.authorid="+srchuid+" and ");
}
if (srchtype.equals("blog")) {
threadhql.append("t.blog=1 and ");
} else if (srchtype.equals("trade")) {
threadhql.append("t.special=2 and ");
}
if (srchfilter.equals("digest")) {
threadhql.append("t.digest > 0 and ");
} else if (srchfilter.equals("top")) {
threadhql.append("t.displayorder > 0 and ");
}
if (!space.equals("")) {
threadhql.append("t.special in ( " + space+ " ) and ");
}
if (!forums.toString().equals("")) {
threadhql.append("t.fid in ( " + forums.toString() + " ) and ");
}
if (srchfrom!=null && !srchfrom.equals("0")) {
int datetime = timestamp- Integer.valueOf(srchfrom);
if (before.equals("0")) {
threadhql.append("t.lastpost >= " + datetime + " and ");
} else {
threadhql.append("t.lastpost <=" + datetime + " and ");
}
}
int lastand = threadhql.lastIndexOf("and");
if (lastand > 0) {
threadhql.delete(lastand, threadhql.length());
}
threadhql.append("order by t." + orderby + " " + ascdesc+" limit 0,"+maxsearchresult);
List<Map<String,String>> threadlist = dataBaseService.executeQuery(threadhql.toString());
String tids = "0";
int threadcount = 0;
if (threadlist != null && threadlist.size() > 0) {
threadcount = threadlist.size();
for (Map<String,String> t : threadlist) {
tids += ","+t.get("tid");
}
}
threadlist = null;
Searchindex searchdex = new Searchindex();
searchdex.setDateline(timestamp);
int exprtation = timestamp + cachelife_text;
searchdex.setExpiration(exprtation);
searchdex.setKeywords(srchtxt + "+" + srchuname);
searchdex.setSearchstring(searchstring);
searchdex.setThreads(Short.valueOf(threadcount + ""));
searchdex.setThreadtypeid(Short.valueOf("0"));
searchdex.setTids(tids);
searchdex.setUid(uid);
searchdex.setUseip(ip);
int searchids = searchServer.insertSearchindex(searchdex);
dataParse = null;
try {
response.sendRedirect("search.jsp?action=search&searchid="+searchids+"&orderby="+orderby+"&ascdesc="+ascdesc);
} catch (IOException e) {
}
return null;
}
}
}
@SuppressWarnings("unchecked")
public ActionForward searchbytype(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
Map<String,String> forumStr = (Map<String,String>)request.getAttribute("forums");
DataParse dataParse = (DataParse) BeanFactory.getBean("dataParse");
Map<String,Map<String,String>> forumMap=dataParse.characterParse(forumStr.get("forums"),false);
HttpSession session = request.getSession();
Members member = (Members)session.getAttribute("user");
short groupid = (Short)session.getAttribute("jsprun_groupid");
int uid = (Integer) session.getAttribute("jsprun_uid");
int cachelife_text = 3600;
int timestamp = (Integer)(request.getAttribute("timestamp"));
Map<String, String> settings = (Map<String, String>) request.getAttribute("settings");
String searchctrl = settings.get("searchctrl");
String maxspm = settings.get("maxspm");
String maxsearchresult = settings.get("maxsearchresults");
String srchfid[] = request.getParameterValues("srchfid[]");
StringBuffer forums =new StringBuffer();
if (srchfid == null || srchfid[0].trim().equals("all")) {
Set<String> fids = forumMap.keySet();
String extgroupids = member!=null?member.getExtgroupids():"";
for(String fid:fids){
Map<String,String> forum = forumMap.get(fid);
if ((forum.get("viewperm").equals(""))||Common.forumperm(forum.get("viewperm"), groupid, extgroupids)) {
forums.append(fid + ",");
}
}
} else {
for (int i = 0; i < srchfid.length; i++) {
forums.append(srchfid[i] + ",");
}
}
if (forums.length()>0) {
forums.deleteCharAt(forums.length()-1);
}
if(forums.toString().equals("all")){
forums.delete(0, forums.length());
}
String searchstring = "type|";
String searchindexhql = "from Searchindex as s where s.searchstring = '"+ searchstring + "' and s.expiration >" + timestamp;
Searchindex searchindex = searchServer.findSearchindexByHql(searchindexhql);
if (searchindex != null) {
try {
response.sendRedirect("search.jsp?searchid="+searchindex.getSearchid()+"&orderby=lastpost&ascdesc=desc");
} catch (IOException e) {
}
return null;
} else {
String ip = request.getRemoteAddr();
if (!searchctrl.equals("0")) {
int times = timestamp- convertInt(searchctrl);
String ctrlhql = "select searchid from jrun_searchindex as s where s.useip='"+ ip + "' and uid=" + uid + " and s.dateline >="+ times+" limit 1";
List<Map<String,String>> index = dataBaseService.executeQuery(ctrlhql);
if (index != null && index.size()>0) {
String message = "对不起,您在 " + searchctrl+ " 秒内只能进行一次搜索,请返回。";
request.setAttribute("errorInfo", message);
return mapping.findForward("showMessage");
}
index = null;
}
if (!maxspm.equals("0")) {
int times = timestamp - 60;
String maxhql = "select count(*) from Searchindex as s where s.useip='"
+ ip
+ "' and uid="
+ uid
+ " and s.dateline>="
+ times;
int count = searchServer.findseachindexcountbyHql(maxhql);
if (count >= convertInt(maxspm)) {
String message = "对不起,管理员设置了每分钟系统最多响应搜索请求 " + maxspm
+ " 次,请返回并稍后再试。";
request.setAttribute("errorInfo", message);
return mapping.findForward("showMessage");
}
}
String typeid = request.getParameter("typeid");
if (typeid.equals("0")) {
request.setAttribute("errorInfo", "您没有指定要搜索的类别,请返回重新填写。");
return mapping.findForward("showMessage");
}
String hql = "select tid from jrun_threads as t where t.typeid = " + typeid
+ " and t.fid in ( " + forums + " ) order by lastpost desc limit 0,"+maxsearchresult;
List<Map<String,String>> threadlist = dataBaseService.executeQuery(hql);
String tids = "0";
int threadcount = 0;
if (threadlist != null && threadlist.size() > 0) {
threadcount = threadlist.size();
for (Map<String,String> t : threadlist) {
tids += ","+t.get("tid");
}
}
threadlist = null;
Searchindex searchdex = new Searchindex();
searchdex.setDateline(timestamp);
int exprtation = timestamp + cachelife_text;
searchdex.setExpiration(exprtation);
searchdex.setSearchstring(searchstring);
searchdex.setThreads(Short.valueOf(threadcount + ""));
searchdex.setTids(tids);
searchdex.setUid(uid);
searchdex.setUseip(ip);
searchdex.setKeywords("");
searchdex.setThreadtypeid(Short.valueOf(typeid));
int searchids = searchServer.insertSearchindex(searchdex);
try {
response.sendRedirect("search.jsp?action=search&searchid="+searchids+"&orderby=lastpost&ascdesc=desc");
} catch (IOException e) {
}
return null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -