<%@ page contentType="text/html; charset=gbk" language="java" import="java.sql.*,java.util.*,java.text.SimpleDateFormat,com.bmtech.utils.tcp.*, com.qianlima.zhaobiao.se.search.*"%> <%@ include file="conn.jsp"%> <%@ include file="checklogin.jsp"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ include file="sub.jsp"%> <%@page import="com.google.gson.Gson"%> <%@ include file="pageUtil.jsp"%> <%@ include file="searchSolrList.jsp"%> <%@ page import="java.sql.*,java.util.*,java.text.SimpleDateFormat"%> <%@ page import="java.net.*,java.io.*"%> <% String area=request.getParameter("areaId"); int areaid=0; if(area!=null){ areaid=Integer.parseInt(area); } int pageNo=intshuzi(request.getParameter("pageNo"), 1); int sid=intshuzi(request.getParameter("sid"), 0); HotBean cbz=getSeohot(conn,sid); String areaUrl=null; if(areaid<10&&areaid>=0){ areaUrl="000"+areaid; }else if(areaid<100&&areaid>=10){ areaUrl="00"+areaid; }else if(areaid<1000&&areaid>=100){ areaUrl="0"+areaid; }else if(areaid<10000&&areaid>=1000){ areaUrl=""+areaid; } if(cbz==null){ response.setStatus(404); out.println("404 not found"); conn.close(); return; } List ids =new ArrayList(); Integer pageSize=10; try{ String keyword=cbz.keyword; String word=cbz.word; String city=""; if(areaid!=0){ city=getAreaByName(conn, areaid); request.setAttribute("parea", city); } /*solr start*/ SearchResult result = zhureload(city+word,pageNo,pageSize); List list = new ArrayList(); int total = 0; if(result!=null) { list = result.getResults(); total = (int)result.getRowCount(); } ids = getIds(list); List> showList=getShowList(conn, ids); if(total<10){ int ssid=0; ssid=10-total; showList.addAll(getSjList(conn,ssid)); } if(total>50){ total=50; } /*solr end*/ String herf="/hot"+sid+area+"/"; pageContext.setAttribute("showList", showList); pageContext.setAttribute("city", city); PageUtil pageUtil=new PageUtil(total, pageNo, pageSize,10); pageContext.setAttribute("page", pageUtil); pageContext.setAttribute("area", area); pageContext.setAttribute("keyword", keyword); pageContext.setAttribute("sid", sid); pageContext.setAttribute("herf", herf); }catch(Exception e){ e.printStackTrace(); } finally{ if(conn!=null){ try{ conn.close(); } catch(Exception e){} } } %> ${city}${keyword} <%@ include file="wap_tongji.jsp"%>
<%@ include file="fenzhan.jsp"%>
全面跟踪 "${city}${keyword}" 招标项目
<%! public List> getShowList(Connection conn,List ids)throws Exception{ List> showList=new ArrayList>(); SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); for(Integer contentid:ids){ PreparedStatement ps=conn.prepareStatement("select title,url,updatetime from phpcms_content where contentid=? and status=99"); ps.setInt(1, contentid); ResultSet rs=ps.executeQuery(); if(rs.next()){ Map map=new HashMap(); map.put("title",jiequ(rs.getString("title"), 90)); map.put("url",rs.getString("url").replace("www.qianlima.com","wap.qianlima.com")); map.put("updatetime", sdf.format(new java.util.Date(rs.getInt("updatetime")*1000L))); showList.add(map); } } return showList; } public String jiequ(String str,int num){ String reString=""; int k=0; char[] a=str.toCharArray(); for(int i=0;ik;i++){ String s1 = String.valueOf(a[i]); //获取字符串数组中的字符并转换成String型 byte[] getBytes = s1.getBytes(); //字符串数组中的字符串以字节数组的形式存储 if(getBytes.length==2){ //为了应付题目,把一个汉字当做2个字节 k += getBytes.length-1; }else{ k += getBytes.length; } if(k<=num){ //处理如:"a我",2的情况,只输出"a",而不是"a我" reString += a[i]; } } if(reString.equals(str)){ return str; }else{ return reString+"..."; } } public SearchResult zhureload(String word,int pageNo,int pageSize) throws Exception{ String sort = "updatetime desc"; int filtermode = 1; // 全文 int isprecise = 0; // 模糊 String datetype = "1"; String types = "0,1,2,3"; SearchResult result = getSolrIds(word.toLowerCase(),pageSize,pageNo,sort,filtermode,datetype,null,null,isprecise,null,types); return result; } public List> getSjList(Connection conn,int sid)throws Exception{ List> sjList=new ArrayList>(); SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); int sjid=buildRandom(3); PreparedStatement ps=conn.prepareStatement("SELECT title,url,updatetime,contentid FROM phpcms_content WHERE STATUS=99 ORDER BY updatetime DESC LIMIT "+sjid+","+sid); ResultSet rs=ps.executeQuery(); while(rs.next()){ Map map=new HashMap(); map.put("title",jiequ(rs.getString("title"), 90)); map.put("url",rs.getString("url").replace("www.qianlima.com","wap.qianlima.com")); map.put("updatetime", sdf.format(new java.util.Date(rs.getInt("updatetime")*1000L))); sjList.add(map); } return sjList; } public static int buildRandom(int length) { int num = 1; double random = Math.random(); if (random < 0.1) { random = random + 0.1; } for (int i = 0; i < length; i++) { num = num * 10; } return (int) ((random * num)); } public String getAreaByName(Connection conn,int area)throws Exception{ String sql="select name from zdy_area_new where areaid=?"; PreparedStatement ps=conn.prepareStatement(sql); ps.setInt(1, area); ResultSet rs=ps.executeQuery(); if(rs.next()){ String starea=rs.getString(1); return starea; } return null; } public class HotBean{ public int id; public String keyword; public String word; public String kwid; public int city; public int getId() { return id; } public String getKeyword() { return keyword; } public String getWord() { return word; } public String getKwid() { return kwid; } public int getCity() { return city; } } public HotBean getSeohot(Connection conn,int sid)throws Exception{ PreparedStatement ps=conn.prepareStatement("select keyword,word,kwid,city from seo_zhaobiao_hot where id=?"); ps.setInt(1, sid); ResultSet rs=ps.executeQuery(); if(rs.next()){ HotBean hot= new HotBean(); hot.keyword=rs.getString(1); hot.word=rs.getString(2); hot.kwid=rs.getString(3); hot.city=rs.getInt(4); return hot; } return null; } %>