Lucene_demo04_分页
来源:互联网 发布:网络配音兼职网站推荐 编辑:程序博客网 时间:2024/06/06 04:18
- /**
- * 分页
- */
- 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条数据
- }
- }
0 0
- Lucene_demo04_分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- Host文件初识
- Lucene_demo02_分词
- Logstash处理json格式日志文件的三种方法
- Lucene_demo03_索引库整理
- iOS开发——基于corelocation位置定位——工具类
- Lucene_demo04_分页
- 第七周 项目4-队列数组
- 第七周项目2—建立链队算法库
- jquery EasyUI 心得--------2 datagrid中混用渲染方式引出的bug带给我的反思
- 在Ubuntu下配置pyrouge
- Lucene_demo05_内存索引和文件索引
- 第7周、项目3—负数把正数赶出队列
- 第7周项目1建立顺序环形队列算法库
- 后缀表达式