使用分页Lucene.net [英] Paging using Lucene.net

查看:274
本文介绍了使用分页Lucene.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的.Net应用程序,它使用Asp.net 3.5和Lucene.Net我显示由Lucene.Net在一个asp.net的DataGrid给定的搜索结果。我需要实现分页(10条记录每一页上)这个aspx页面。

I'm working on a .Net application which uses Asp.net 3.5 and Lucene.Net I am showing search results given by Lucene.Net in an asp.net datagrid. I need to implement Paging (10 records on each page) for this aspx page.

我要如何使用这做Lucene.Net?

How do I get this done using Lucene.Net?

推荐答案

下面是一个的方式来构建一个简单的列表的匹配与Lucene.Net特定页面。这不是ASP.Net特定

Here is a way to build a simple list matching a specific page with Lucene.Net. This is not ASP.Net specific.

int first = 0, last = 9; // TODO: Set first and last to correct values according to page number and size
Searcher searcher = new IndexSearcher(YourIndexFolder);
Query query = BuildQuery(); // TODO: Implement BuildQuery
Hits hits = searcher.Search(query);
List<Document> results = new List<Document>();
for (int i = first; i <= last && i < hits.Length(); i++)
    results.Add(hits.Doc(i));

// results now contains a page of documents matching the query

基本上,点击收藏非常轻巧。获取此列表的成本是最小的。你只要通过调用hits.Doc(一)建立页面实例化所需要的文档。

Basically the Hits collection is very lightweight. The cost of getting this list is minimal. You just instantiate the needed Documents by calling hits.Doc(i) to build your page.

这篇关于使用分页Lucene.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆