Lucene_demo04_分页
/**
* 分页
*/
public class DispageTest {
// 分页类
private void testSearchIndex(int firstResult, int maxResult) throws Exception {
IndexSearcher indexSearcher = new IndexSearcher(LuceneUtils.directory);
QueryParser queryParser = new MultiFieldQueryParser(Version.LUCENE_30, new String[] { "title", "content" }, LuceneUtils.analyzer);
Query query = queryParser.parse("2013");
TopDocs topDocs = indexSearcher.search(query, 50);// 查询50条结果
int count = topDocs.totalHits;// 总的记录数
int scoreCount = Math.min(count, firstResult + maxResult);// 截止条数
ScoreDoc[] scoreDocs = topDocs.scoreDocs;
// 将搜索出的doc转换为model保存在List中
List<Article> articleList = new ArrayList<Article>();
for (int i = firstResult; i < scoreCount; i++) {
int index = scoreDocs[i].doc;
Document document = indexSearcher.doc(index);
Article article = DocumentUtils.document2Article(document);
articleList.add(article);
}
// 输出查询结果
for (Article article : articleList) {
System.out.println(article.getId());
System.out.println(article.getTitle());
System.out.println(article.getContent());
}
}
@Test
public void dispage() throws Exception {
this.testSearchIndex(20, 10);// 从查询出来的索引值中,从第20条开始取后面的10条数据
}
}
分享到:
相关推荐
可用lucene demo 已经有入门级pdf学习
lucene_in_action中文版lucene_in_action中文版lucene_in_action中文版lucene_in_action中文版lucene_in_action中文版lucene_in_action中文版
Lucene资料大全,包括:Lucene_in_Action书,尚学堂科技_张志宇_lucene.ppt等
lucene_jar包
大型网站站内搜索(Lucene_In_Action).pdf 大型网站站内搜索(Lucene_In_Action).pdf
Lucene_3.0_原理与代码分析
Lucene_in_Action 中文版
一个vb.net2.0做的Lucene索引测试 vb.net的东西比较少吧,我上一个
JAVA_Lucene_in_Action教程完整版
这个压缩包包含lucene_3.6.1_API,后缀格式为chm. .;...
实现的的索引建立 以及全文检索等功能……
对clucene0.9.21版本在vc6下调试demo希望对你的开发有帮助
Lucene_in_Action english版
compass_lucene_source
Lucene_in_Action(中文版).pdf Lucene in Action(中文版) ----------------------------------------- Lucene in Action 中文版 第一部分 Lucene 核心 1. 接触 Lucene 2. 索引 3. 为程序添加搜索 4. ...
Lucene_in_Action(中文版).pdf
c#中文分词类库+可用来做搜索引擎分词+准确率90 +支持Lucene.net.rar
Lucene_in_ Action java search engine.PDF 搜索引擎教程