📄 searchjsp.java
字号:
/*
* Created on 2007-5-30
* Last modified on 2007-9-26
* Powered by GamVan.com
*/
package com.yeqiangwei.club.view.jsp;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.yeqiangwei.club.service.model.TopicModel;
import com.yeqiangwei.club.service.model.UserModel;
import com.yeqiangwei.club.service.search.SearchFactory;
import com.yeqiangwei.club.service.search.SearchParameter;
import com.yeqiangwei.club.service.search.SearchProvider;
import com.yeqiangwei.club.util.BeanUtils;
import com.yeqiangwei.club.view.model.TopicView;
import com.yeqiangwei.club.view.model.UserView;
import com.yeqiangwei.html.OutPrint;
import com.yeqiangwei.net.URL;
import com.yeqiangwei.util.ParamUtils;
import com.yeqiangwei.util.StringHelper;
import com.yeqiangwei.util.Validator;
public class SearchJsp extends BaseJsp{
private String pagination;
private int page = 1;
private int searchType = 1;
private String keys = "";
private int totalRows = 0;
private long runtimed = 0;
public SearchJsp(HttpServletRequest request, HttpServletResponse response) {
super(request, response);
searchType = ParamUtils.getIntParameter(request,"t",1);
page = ParamUtils.getIntParameter(request,"page",1);
keys = ParamUtils.getStringParameter(request, "q", "").trim();
if(!Validator.isEmpty(keys)){
keys = this.keyFilter(keys);
keys = URL.urlDecoder(keys,"UTF-8");
keys = StringHelper.toUTF8(keys);
}
}
public String keyFilter(String keys){
keys = keys.replace("%","");
keys = keys.replace(">","");
keys = keys.replace("<","");
keys = keys.replace("&","");
return keys;
}
public List<UserView> userResults(int rows){
SearchProvider<UserModel> searcher = SearchFactory.getInstance(SearchProvider.SEARCH_USER);
if(Validator.isEmpty(keys)){
return null;
}
SearchParameter param = new SearchParameter();
param.setPage(new Integer(page));
param.setRows(new Integer(rows));
param.setHighlight(true);
param.setKeys(keys);
param.setSex(ParamUtils.getStringParameter(request,"sex","0"));
List<UserModel> mlist = searcher.results(param);
List<UserView> list = new ArrayList<UserView>();
if(!Validator.isEmpty(mlist)){
for(int i=0; i<mlist.size(); i++){
UserModel model = (UserModel) mlist.get(i);
UserView view = new UserView();
BeanUtils.copyProperties(view, model);
list.add(view);
}
this.totalRows = searcher.getTotalrows();
this.runtimed = searcher.getRuntimed();
StringBuffer url = new StringBuffer();
url.append("search.jsp?q=");
url.append(URL.urlEncoder(keys,"UTF-8"));
url.append("&t=");
url.append(searchType);
url.append("&sex=");
url.append(param.getSex());
url.append("&page=");
this.setPagination(OutPrint.pagination(page, rows, this.totalRows, url.toString(),5));
return list;
}
else{
return null;
}
}
public List<TopicView> topicResults(int rows){
if(Validator.isEmpty(keys)){
return null;
}
SearchProvider<TopicModel> searcher = SearchFactory.getInstance(SearchProvider.SEARCH_TOPIC);
int forumId = ParamUtils.getIntParameter(request,"forumId");
SearchParameter param = new SearchParameter();
param.setKeys(keys);
param.setForumId(forumId);
param.setPage(new Integer(page));
param.setRows(new Integer(rows));
param.setHighlight(true);
List<TopicModel> mlist = searcher.results(param);
List<TopicView> list = new ArrayList<TopicView>();
if(!Validator.isEmpty(mlist)){
for(int i=0; i<mlist.size(); i++){
TopicModel model = (TopicModel) mlist.get(i);
TopicView view = new TopicView();
BeanUtils.copyProperties(view, model);
view.setContent(model.getContentModel().getContent());
list.add(view);
}
this.totalRows = searcher.getTotalrows();
this.runtimed = searcher.getRuntimed();
StringBuffer url = new StringBuffer();
url.append("search.jsp?q=");
url.append(URL.urlEncoder(keys,"UTF-8"));
if(forumId>0){
url.append("&forumId=");
url.append(forumId);
}
url.append("&page=");
this.setPagination(OutPrint.pagination(page, rows, this.totalRows, url.toString(),5));
return list;
}
else{
return null;
}
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public String getPagination() {
return pagination;
}
public void setPagination(String pagination) {
this.pagination = pagination;
}
public String getKeys() {
return keys;
}
public void setKeys(String keys) {
this.keys = keys;
}
public long getRuntimed() {
return runtimed;
}
public void setRuntimed(long runtimed) {
this.runtimed = runtimed;
}
public int getTotalRows() {
return totalRows;
}
public void setTotalRows(int totalRows) {
this.totalRows = totalRows;
}
public int getSearchType() {
return searchType;
}
public void setSearchType(int searchType) {
this.searchType = searchType;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -