参与权重的查询字段最好是可以进行分词配置过的,
例子程序:
//权重
query.set("defType","dismax");
query.set("qf","username^10000 zgxltext^10000 usernameSpell^10000 id^10000 email^10000 jgtext^10000 xueweitext^10000 zhiweitext^10000 sextext^10000 zhijitext^10000 companytext^10000 zuzhitext^10000 companysubtext^10000 sbfamily^1 sbharvest^1 sbproject^1 sbteach^1 sbwaiyu^1 sbwork^1 sbzhiCheng^1 ");
//高亮
query.setHighlight(true);
query.setParam("hl", "true"); //highlighting
query.setParam("hl.fl", "username id email jgtext xueweitext zhiweitext sextext zhijitext companytext zuzhitext companysubtext zgxltext");
query.setHighlightSimplePre("<font color=\'red\'>");
query.setHighlightSimplePost("</font>");
query.setHighlightFragsize(200);
query.setHighlightSnippets(3);
List<SPEntity> lpojo = response.getBeans(SPEntity.class);
Map<String, Map<String, List<String>>> highlighting = response.getHighlighting();
List<String> list2 =null;
//
if (lpojo != null && lpojo.size()>0 && highlighting != null){
for(SPEntity sp : lpojo){
Map<String, List<String>> map = highlighting.get(sp.getId());
list2 = map.get("username");
if (list2 != null && list2.size()>0){
sp.setUsername(list2.get(0));
}
list2 = map.get("id");
if (list2 != null && list2.size()>0){
sp.setId(list2.get(0));
}
list2 = map.get("email");
if (list2 != null && list2.size()>0){
sp.setEmail(list2.get(0));
}
list2 = map.get("jgtext");
if (list2 != null && list2.size()>0){
sp.setJgtext(list2.get(0));
}
list2 = map.get("xueweitext");
if (list2 != null && list2.size()>0){
sp.setXueweitext(list2.get(0));
}
list2 = map.get("zhiweitext");
if (list2 != null && list2.size()>0){
sp.setZhiweitext(list2.get(0));
}
list2 = map.get("sextext");
if (list2 != null && list2.size()>0){
sp.setSextext(list2.get(0));
}
list2 = map.get("zhijitext");
if (list2 != null && list2.size()>0){
sp.setZhijitext(list2.get(0));
}
list2 = map.get("companytext");
if (list2 != null && list2.size()>0){
sp.setCompanytext(list2.get(0));
}
list2 = map.get("zuzhitext");
if (list2 != null && list2.size()>0){
sp.setZuzhitext(list2.get(0));
}
list2 = map.get("companysubtext");
if (list2 != null && list2.size()>0){
sp.setCompanysubtext(list2.get(0));
}
list2 = map.get("zgxltext");//
if (list2 != null && list2.size()>0){
sp.setZgxltext(list2.get(0));
}
}
}