67,513
社区成员
发帖
与我相关
我的任务
分享
方法名:
findCommonMultiSearchDAO(IndexSearcher[] searcher, Query query , String ... cond )
MultiSearcher multiSear = new MultiSearcher(searcher);
multiSear.setSimilarity(new IKSimilarity());
TopScoreDocCollector topdoc = TopScoreDocCollector.create(Integer.valueOf(bundle.getString("query.size")), true);
//返回指定的前几条,query.size,在配置文件中配置
multiSear.search(query,topdoc);
ScoreDoc[] hits = topdoc.topDocs().scoreDocs;
//得到总数
int sta = 0 ;
int end = Integer.valueOf(bundle.getString("query.size")) ;
if("1".equalsIgnoreCase(cond[0]))
{
//表示需要分页
sta = Integer.valueOf(cond[1].trim());
end = Integer.valueOf(cond[2].trim());
if(end > topdoc.getTotalHits() )
{
end = topdoc.getTotalHits() ;
}
//设置分页
topdoc = TopScoreDocCollector.create(topdoc.getTotalHits(), true);
//拿到指定的条数,指定开始记录-->结束记录
multiSear.search(query,topdoc);
hits = topdoc.topDocs(sta, end).scoreDocs;
}
resultMap.put("totalRec", topdoc.getTotalHits() );
//拼装对象放在List里面
List<CommonObj> objList = new ArrayList<CommonObj>();
//POI对象
for (int i = 0 ; i < hits.length ; i++)
{
Document doc = multiSear.doc(hits[i].doc);
CommonObj obj = new CommonObj();
obj.setId(Long.valueOf(doc.get("id")));
obj.setName(doc.get("name"));
obj.setPinyin(doc.get("pinyin"));
obj.setEnglishname(doc.get("englishname"));
obj.setTiroscode(Integer.valueOf(doc.get("tiroscode")));
obj.setAreacode(Integer.valueOf(doc.get("areacode")));
obj.setGoem(doc.get("goem"));
obj.setPathname(doc.get("pathname"));
obj.setPoigid(Long.valueOf(doc.get("poigid")));
obj.setBoost(doc.get("boost"));
obj.setSource(doc.get("source"));
obj.setScore(hits[i].score);
objList.add(obj);
}