开发者

Best way to retrieve certain field of all documents returned by a Lucene search

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 selec开发者_Go百科tor 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜