国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開(kāi)通VIP
lucene高亮問(wèn)題

關(guān)鍵問(wèn)題是返回到頁(yè)面的是一個(gè)個(gè)對(duì)象。如果把搜索的結(jié)果中的關(guān)鍵字設(shè)置為高亮,謝謝
InfoPushController:
Page page = infoPushManager.searchKeyword(keyword,request.getParameter("pageNo"),best,category);
List list = new ArrayList();
if(page != null)
list = (List)page.getResult();
mav.addObject("infoPushs", list);
//關(guān)鍵問(wèn)題是返回到頁(yè)面的是一個(gè)個(gè)對(duì)象。

InfoPushManager 里的2個(gè)方法:
public Page searchKeyword(String keyword,String pageNoStr,int best,String category)
{
int pageNo = 1;
if (StringUtils.isNotEmpty(pageNoStr))
pageNo = Integer.parseInt(pageNoStr);
try{
IndexSearcher searcher = new IndexSearcher(IndexReader.open(Constants.INDEX_STORE_PATH));
String bestStr = String.valueOf(best);
/***** 一個(gè)關(guān)鍵字,在兩個(gè)字段中查詢 *****/
/*
* 1.BooleanClause.Occur[]的三種類型:
* MUST : + and
* MUST_NOT : - not
* SHOULD : or
* 2.下面查詢的意思是:content中必須包含該關(guān)鍵字,而title有沒(méi)有都無(wú)所謂
* 3.下面的這個(gè)查詢中,Occur[]的長(zhǎng)度必須和Fields[]的長(zhǎng)度一致。每個(gè)限制條件對(duì)應(yīng)一個(gè)字段
*/
org.apache.lucene.search.Query query = null;
if(best == 1)
{
BooleanClause.Occur[] flags = new BooleanClause.Occur[]{BooleanClause.Occur.MUST,BooleanClause.Occur.MUST,BooleanClause.Occur.MUST};
query = MultiFieldQueryParser.parse(new String[]{keyword,category,bestStr},new String[]{"contents","category","best"},flags,new StandardAnalyzer());
}
else
{
BooleanClause.Occur[] flags = new BooleanClause.Occur[]{BooleanClause.Occur.MUST,BooleanClause.Occur.MUST};
query = MultiFieldQueryParser.parse(new String[]{keyword,category},new String[]{"contents","category"},flags,new StandardAnalyzer());
}
// org.apache.lucene.search.Query query = QueryParser.parse(keyword, "contents",new StandardAnalyzer());
Hits hits = searcher.search(query);

//高亮顯示設(shè)置
SimpleHTMLFormatter simpleHTMLFormatter = new SimpleHTMLFormatter("<red>","</red>");
Highlighter highlighter = new Highlighter(simpleHTMLFormatter,new QueryScorer(query));
highlighter.setTextFragmenter(new SimpleFragmenter(10));//這個(gè)100是指定關(guān)鍵字字符串的context的長(zhǎng)度,你可以自己設(shè)定,因?yàn)椴豢赡芊祷卣膬?nèi)容

return pagedQueryLucene(pageNo, PageContants.SEARCH_AJAX_PAGES, hits);
}
catch(Exception e){
e.printStackTrace();
return null;
}
}

public Page pagedQueryLucene(int pageNo, int pageSize,Hits h) {


long totalCount = 0;
int startIndex = 0;
List list = new ArrayList();
if (h.length() == 0) {
System.out.println("have no data !");
}
else
{
totalCount = h.length();
if (totalCount < 1) return new Page();

// 實(shí)際查詢返回分頁(yè)對(duì)象
startIndex = Page.getStartOfPage(pageNo, pageSize);

//long step = totalCount > pageSize ? pageSize : totalCount;
long endIndex = startIndex + Page.stepDataOfPage(pageSize, totalCount, pageNo);

for (int i = startIndex; i < endIndex; i++) {
try {
Document doc = h.doc(i);
String id = doc.get("id");
InfoPush infoPush = dao.get(id);
list.add(infoPush);

} catch (Exception e) {
e.printStackTrace();
}
}
}
return new Page(startIndex, totalCount, pageSize, list);
}

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Lucene 3.6.1:中文分詞、創(chuàng)建索引庫(kù)、排序、多字段分頁(yè)查詢以及高亮顯示
lucene多種搜索方式詳解例子
Spring MVC MongoDB 分頁(yè)例子下載
自己寫的查詢底層方法:查詢
lucene3.0 中BooleanQuery 的使用 | 親親寶寶
Lucene搜索方法總結(jié) - Java綜合 - Java - ITeye論壇
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服