Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lucene - Reading all field names that are stored

I need to populate a dropdown with all field names in a lucene index and need to show those values. I was able to do it successfully using

var luceneIndexReader IndexReader.Open("D:\path_to\index_directory", true);
var allAvailableFieldNames = luceneIndexReader.GetFieldNames(IndexReader.FieldOption.ALL);

Only problem is I need to include only 'Stored' fields in the drop down. This list includes all 'Indexed' and/or 'Stored' fields in it. Is there a way to query/search the indexes if a field has any 'stored' values and thereby filter out this list?

like image 683
Kalyan Avatar asked Jan 07 '14 19:01

Kalyan


1 Answers

The problem is that every document in the index can have different fields containing stored fields. Since those are not storef as inverted index (they are stored per document) you can't retrieve them from the IndexReader. You need to retrieve one specific document, e.g. Document doc = indexReader.document(1); and call Fieldable fields[] = doc.getFields();. Then iterate over them and checking: field.isStored();.

like image 136
fatih Avatar answered Oct 15 '22 14:10

fatih