[solr ] solr 高亮的使用

chmod777 2009-02-06
已经解决,详见:http://www.weizhifeng.net/archives/566
jayson22 2009-02-13
List<UUDocument> list = new ArrayList<UUDocument>();
List<Map<String,Object>> $list = new ArrayList<Map<String,Object>>();
SolrQuery query = new SolrQuery().setHighlight(true);
    query.setQuery("content:"+condition +" OR title:"+condition);
    query.setStart(start);
    query.setRows(rows);
    query.setIncludeScore(true);
    query.addHighlightField("content");
    query.addHighlightField("title");
    query.setHighlightSimplePre("<font color=\"#c60a00\">");
    query.setHighlightSimplePost("</font>");
    //query.setSortField("contentTime", SolrQuery.ORDER.desc);
   // query.addSortField("dataTime", SolrQuery.ORDER.desc );
   
    QueryResponse response = null;
    try {
    response = solrServer.query(query);
} catch (SolrServerException e1) {
e1.printStackTrace();
}
list = response.getBeans(UUDocument.class);

Map<String,Map<String,List<String>>> hl = response.getHighlighting();
Map<String,Object> _map ;
for (UUDocument u : list) {

_map = new HashMap<String,Object>();
_map.put("contenrURL", u.getContenrURL());
_map.put("title", u.getTitle());
_map.put("contentTime", u.getContentTime());
_map.put("size", u.getSize());
//如果有高亮信息,我们取高亮 否则我们就取原来内容 取前100个字符
if (null != hl.get(u.getTitle()).get("content")) {
_map.put("displayContent", hl.get(u.getTitle()).get("content").get(0));
}else {
String content = u.getContent();
if (content.length() >= 100) {
content = content.substring(0, 100);
}
_map.put("displayContent", content);
}

if (null != hl.get(u.getTitle()).get("title")) {

_map.put("displayTitle", hl.get(u.getTitle()).get("title").get(0));
}else {
_map.put("displayTitle", u.getTitle());
}

_map.put("storeTime", u.getDataTime());

$list.add(_map);
}
chmod777 2009-02-15
谢了.
zjkgzl 2010-01-25
query.setQuery("content:"+condition +" OR title:"+condition);
zjkgzl 2010-01-25
如果早点找到你这句话,我就早点解脱了
samjay 2011-10-10
Map<String,Map<String,List<String>>> hl = response.getHighlighting();
我用这个取的时候如果有十条数据也内的话 就取到多少条
如果是十条也上的话 就取十条 为什么 急 求解
Global site tag (gtag.js) - Google Analytics