solr SitesIndexServlet

package com.paic.wcm.search.admin.web.servlet;


import java.io.IOException;
import java.text.ParseException;
import java.util.Date;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;


import com.paic.wcm.search.admin.service.SitesIndexService;
import com.paic.wcm.search.utils.SecurityUtil;


public class SitesIndexServlet extends HttpServlet {


private static final long serialVersionUID = 1L;


/**
* @see HttpServlet#HttpServlet()
*/
public SitesIndexServlet() {
super();
}


protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doPost(req, resp);
}


protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String actionType = request.getParameter("actionType");
String user = (String) request.getSession().getAttribute("user");


/* if(!request.getSession().getAttribute("redom").equals(request.getParameter("redom"))){
request.getRequestDispatcher("/admin/sitesIndex.jsp").forward(
request, response);
return;
}*/

if ("insert".equals(actionType)) {
/*
* insert
*/
String link = StringUtils.trimToEmpty(request.getParameter("link"));
String title = StringUtils.trimToEmpty(request
.getParameter("title"));
String keywords = StringUtils.trimToEmpty(request
.getParameter("keywords"));
String desc = StringUtils.trimToEmpty(request.getParameter("desc"));
String content = StringUtils.trimToEmpty(request
.getParameter("content"));
String tags = StringUtils.trimToEmpty(request.getParameter("tags"));
String type = "";
String site = StringUtils.trimToEmpty(request.getParameter("site"));


// 拆分site和type
if (site.contains("|")) {
String[] strArray = site.split("\\|");
site = strArray[0];
type = strArray[1];
}
String dateStr = request.getParameter("date");
String hourStr = request.getParameter("hour");
String minuteStr = request.getParameter("minute");
// 解析时间
Date date = toDate(dateStr, hourStr, minuteStr);


SitesIndexService.insert(user ,link, title, desc, content, tags,
keywords, site, type , date , "site");

}else if("update".equals(actionType)){

String link = StringUtils.trimToEmpty(request.getParameter("link"));
String title = StringUtils.trimToEmpty(request
.getParameter("title"));
String keywords = StringUtils.trimToEmpty(request
.getParameter("keywords"));
String desc = StringUtils.trimToEmpty(request.getParameter("desc"));
String content = StringUtils.trimToEmpty(request
.getParameter("content"));
String tags = StringUtils.trimToEmpty(request.getParameter("tags"));
String type = "";
String site = StringUtils.trimToEmpty(request.getParameter("site"));


// 拆分site和type
if (site.contains("|")) {
String[] strArray = site.split("\\|");
site = strArray[0];
type = strArray[1];
}
String dateStr = request.getParameter("date");
String hourStr = request.getParameter("hour");
String minuteStr = request.getParameter("minute");
// 解析时间
Date date = toDate(dateStr, hourStr, minuteStr);

SitesIndexService.updateByLink(user ,link, title, keywords, desc, tags, content,
site, type, date , "site");

}else if ("delete".equals(actionType)) {
/*
* delete
*/
String link = StringUtils.trimToEmpty(request.getParameter("link"));
if(link!=null && !"".equals(link)){
SitesIndexService.deleteByLink(user ,link , "site");
}
}else if("deleteAll".equals(actionType)){
/*
* deleteAll
*/
String link = StringUtils.trimToEmpty(request.getParameter("link"));
if(link!=null && !"".equals(link)){
SitesIndexService.deleteAll(user ,link , "site");
}
}

String queryUrl = StringUtils.trimToEmpty(request
.getParameter("queryUrl"));
String pageIndexStr = request.getParameter("pageIndex");
String pageSizeStr = request.getParameter("pageSize");
if (StringUtils.isEmpty(pageIndexStr)
|| StringUtils.isEmpty(pageSizeStr)) {
request.getRequestDispatcher("/admin/sitesIndex.jsp").forward(
request, response);
return;
}
int pageIndex = Integer.valueOf(StringUtils.trimToEmpty(pageIndexStr));
int pageSize = Integer.valueOf(StringUtils.trimToEmpty(pageSizeStr));
if("".equals(queryUrl)){
          request.getRequestDispatcher("/admin/sitesIndex.jsp").forward(
                 request, response);
          return ;
      }


SolrDocumentList resultList = SitesIndexService.query(
queryUrl, pageIndex, pageSize,"site");
SolrDocumentList resultLists = new SolrDocumentList();
SolrDocument solr;
for(SolrDocument s : resultList){
solr = s;
solr.setField("title", SecurityUtil.outputfilter((String)s.getFieldValue("title")));
solr.setField("keywords", SecurityUtil.outputfilter((String)s.getFieldValue("keywords")));
solr.setField("desc", SecurityUtil.outputfilter((String)s.getFieldValue("desc")));
solr.setField("tags", SecurityUtil.outputfilter((String)s.getFieldValue("tags")));
solr.setField("content", SecurityUtil.outputfilter((String)s.getFieldValue("content")));
resultLists.add(solr);
}
long count = resultList.getNumFound();
request.setAttribute("resultList", resultLists);
request.setAttribute("queryUrl", queryUrl);
request.setAttribute("pageCount", Math.ceil(count * 1.0 / pageSize));
request.setAttribute("pageIndex", pageIndex);


request.getRequestDispatcher("/admin/sitesIndex.jsp").forward(
request, response);
}


private Date toDate(String date, String hour, String minute) {
date = date + " " + hour + ":" + minute;
try {
return DateUtils.parseDate(date,
new String[] { "yyyy-MM-dd HH:mm" });
} catch (ParseException e) {
e.printStackTrace();
return new Date();
}
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值