检索 Lucene 搜索返回的所有文档的某些字段的最佳方法

发布于 2024-08-27 00:26:51 字数 299 浏览 5 评论 0原文

我想知道最好的方法是检索 Lucene 搜索器返回的所有文档的某个字段。

背景:每个文档都有一个日期字段(写在上面),我想显示所有找到的文档的时间线,因此我需要提取通过搜索找到的所有文档的日期(日)字段。

我目前使用 Searcher.doc(int, FieldSelector) 检索每个文档,其中选择器仅检索特定字段。

我已经索引了 250k 文档,搜索本身不需要时间并返回大约 10k 文档 ID。

然而,检索这些内容需要 20 多秒的时间。

我可以做什么来加快速度,同时仍然获得我需要的所有值?

I was wondering what the best way is to retrieve a certain field of all documents returned by a Searcher of Lucene.

Background: each document has a date field (written on) and I would like to show a timeline of all found documents, so I need to extract the date (day) field of all the documents I find with the search.

I currently retrieve every document using Searcher.doc(int, FieldSelector) having the selector only retrieve the certain field.

I have indexed 250k documents, the search itself takes no time and returns about 10k document ids.

Retrieving those however, takes 20+ seconds.

What can I do to speed things up, but still get all the values I need?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荆棘i 2024-09-03 00:26:51

检索字段值的更好方法是使用 FieldCache。例如,如果字段值为字符串,则可以按如下方式检索值。

String[] fieldValues = FieldCache.DEFAULT.getStrings(indexReader, "FieldName")

顾名思义,这些值会被缓存。也就是说后续调用不需要时间。现在,您可以使用 lucene 文档 id 查找该数组,以检索给定文档的该字段的值。

A better way to retrieve field values is with FieldCache.For example, if the field value is string, you can retrieve values as follows.

String[] fieldValues = FieldCache.DEFAULT.getStrings(indexReader, "FieldName")

As the name suggests, these values are cached. That is subsequent calls take no time. You can now look up this array with lucene document id to retrieve value of that field for the given document.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文