分页Lucene的搜索结果 [英] Paging Lucene's search results

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

问题描述

我正在使用Lucene在Web应用程序中显示搜索结果. 搜索结果的范围从5000到10000甚至更多. 有人可以告诉我关于分页和缓存搜索结果的最佳策略吗?

I am using Lucene to show search results in a web application.I am also custom paging for showing the same. Search results could vary from 5000 to 10000 or more. Can someone please tell me the best strategy for paging and caching the search results?

推荐答案

我建议您不要缓存结果,至少不要在应用程序级别缓存.不过,在具有大量内存的操作系统上运行Lucene很有用,操作系统可以将其用于文件缓存.

I would recommend you don't cache the results, at least not at the application level. Running Lucene on a box with lots of memory that the operating system can use for its file cache will help though.

只需对每个页面使用不同的偏移量重复搜索即可.缓存会引入有状态性,最终会破坏性能.我们有成百上千的并发用户搜索超过4000万份文档的索引.在不使用显式缓存的情况下,搜索可以在不到一秒钟的时间内完成.

Just repeat the search with a different offset for each page. Caching introduces statefulness that, in the end, undermines performance. We have hundreds of concurrent users searching an index of over 40 million documents. Searches complete in much less than one second without using explicit caching.

使用搜索返回的Hits对象,您可以访问如下页面的文档:

Using the Hits object returned from search, you can access the documents for a page like this:

Hits hits = searcher.search(query);
int offset = page * recordsPerPage;
int count = Math.min(hits.length() - offset, recordsPerPage);
for (int i = 0; i < count; ++i) {
  Document doc = hits.doc(offset + i);
  ...
}

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

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