分页查询只需要传入每页显示多少条记录,当前是第几页就可以了。
当然是对搜索返回的结果进行分页,并不是对搜索结果的总数量进行分页,因为我们搜索的时候都是返回前n条记录。
例如indexSearcher.search(query, 100);//只返回前100条记录
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
/** * 对搜索返回的前n条结果进行分页显示
* @param keyWord 查询关键词
* @param pageSize 每页显示记录数
* @param currentPage 当前页
* @throws ParseException
* @throws CorruptIndexException
* @throws IOException
*/
public void paginationQuery(String keyWord, int pageSize, int currentPage) throws ParseException, CorruptIndexException, IOException {
String[] fields = { "title" , "content" };
QueryParser queryParser = new MultiFieldQueryParser(Version.LUCENE_36,fields,analyzer);
Query query = queryParser.parse(keyWord);
IndexReader indexReader = IndexReader.open(directory);
IndexSearcher indexSearcher = new IndexSearcher(indexReader);
//TopDocs 搜索返回的结果
TopDocs topDocs = indexSearcher.search(query, 100 ); //只返回前100条记录
int totalCount = topDocs.totalHits; // 搜索结果总数量
ScoreDoc[] scoreDocs = topDocs.scoreDocs; // 搜索返回的结果集合
//查询起始记录位置
int begin = pageSize * (currentPage - 1 ) ;
//查询终止记录位置
int end = Math.min(begin + pageSize, scoreDocs.length);
//进行分页查询
for ( int i=begin;i<end;i++) {
int docID = scoreDocs[i].doc;
Document doc = indexSearcher.doc(docID);
int id = NumericUtils.prefixCodedToInt(doc.get( "id" ));
String title = doc.get( "title" );
System.out.println( "id is : " +id);
System.out.println( "title is : " +title);
}
}
@Test
public void testPaginationQuery() throws CorruptIndexException, ParseException, IOException{
//每页显示5条记录,显示第三页的记录
paginationQuery( "思想" , 5 , 3 );
}
|
相关推荐
NULL 博文链接:https://iamyida.iteye.com/blog/2193345
在lucene搜索分页过程中,可以有两种方式 一种是将搜索结果集直接放到session中,但是假如结果集非常大,同时又存在大并发访问的时候,很可能造成服务器的内存不足,而使服务器宕机 还有一种是每次都重新进行搜索,这样...
这个是自己写的lucene分页高亮程序虽然有些不足但是毕竟是自己研究半天总结出来的麻烦各位帮忙给点分哈哈祝大家新年快乐!
一步一步跟我学习lucene是对近期做lucene索引的总结,大家有问题的话联系本人如蒙加入,不胜感激,大家共同探讨,本人争取每日一博,希望大家持续关注,会带给大家惊喜的
SSH + Lucene + 分页 + 排序 + 高亮 模拟简单新闻网站搜索引擎--NewsWithSearch.part3 SSH + Lucene + 分页 + 排序 + 高亮 模拟简单新闻网站搜索引擎--NewsWithSearch.part2 SSH + Lucene + 分页 + 排序 + 高亮 ...
利用Lucene.net做的建立索引,检索分页
SSH + Lucene + 分页 + 排序 + 高亮 模拟简单新闻网站搜索引擎--NewsWithSearch.part3 SSH + Lucene + 分页 + 排序 + 高亮 模拟简单新闻网站搜索引擎--NewsWithSearch.part2 SSH + Lucene + 分页 + 排序 + 高亮 ...
SSH + Lucene + 分页 + 排序 + 高亮 模拟简单新闻网站搜索引擎--NewsWithSearch.part3 SSH + Lucene + 分页 + 排序 + 高亮 模拟简单新闻网站搜索引擎--NewsWithSearch.part2 SSH + Lucene + 分页 + 排序 + 高亮 ...
SSH + Lucene + 分页 + 排序 + 高亮 模拟简单新闻网站搜索引擎--NewsWithSearch.part3 SSH + Lucene + 分页 + 排序 + 高亮 模拟简单新闻网站搜索引擎--NewsWithSearch.part2 SSH + Lucene + 分页 + 排序 + 高亮 ...
SSH + Lucene + 分页 + 排序 + 高亮 模拟简单新闻网站搜索引擎--NewsWithSearch.part3 SSH + Lucene + 分页 + 排序 + 高亮 模拟简单新闻网站搜索引擎--NewsWithSearch.part2 SSH + Lucene + 分页 + 排序 + 高亮 ...
SSH + Lucene + 分页 + 排序 + 高亮 模拟简单新闻网站搜索引擎--NewsWithSearch.part3 SSH + Lucene + 分页 + 排序 + 高亮 模拟简单新闻网站搜索引擎--NewsWithSearch.part2 SSH + Lucene + 分页 + 排序 + 高亮 ...
SSH + Lucene + 分页 + 排序 + 高亮 模拟简单新闻网站搜索引擎
lucene的排序过滤和分页,lucene开发技术,lucene下载
为了快速查询,加快查询速度,减少与数据库交互,经常需要用到lucene实现创建索引和查询
赠送jar包:lucene-spatial3d-6.6.0.jar; 赠送原API文档:lucene-spatial3d-6.6.0-javadoc.jar; 赠送源代码:lucene-spatial3d-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-spatial3d-6.6.0.pom; 包含...
lucene实例是一个比较详细的例子,包括lucene的入门到高级实例,代码里有比较详细的实例,所有的实例都是通过junit来测试...实例包括各种搜索:如通配符查询、模糊查询、查询结果的分页、中文分词器、自定义分词器等...
NULL 博文链接:https://llying.iteye.com/blog/581411
NULL 博文链接:https://techpool.iteye.com/blog/531101
springmvc+mybatis+lucene4文档搜索系统(支持分页)