views:

72

answers:

1

Hi,

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.

Thx in advance Philipp

+4  A: 

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.

Shashikant Kore