Kalyan
Kalyan

Reputation: 498

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?

Upvotes: 6

Views: 5517

Answers (2)

rmuller
rmuller

Reputation: 12859

Late at the party, but in the meanwhile you can just call FieldInfos# GetEnumerator()

See https://github.com/Shazwazza/lucenenet/blob/docs-update-jan2020/src/Lucene.Net/Index/FieldInfos.cs/#L168

Upvotes: 0

fatih
fatih

Reputation: 1395

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();.

Upvotes: 6

Related Questions