Currently I do like this:
IndexSearcher searcher = new IndexSearcher(lucenePath);
Hits hits = searcher.Search(query);
Document doc;
List<string> companyNames = new List<string>();
for (int i = 0; i < hits.Length(); i++)
{
doc = hits.Doc(i);
companyNames.Add(doc.Get("companyName"));
}
searcher.Close();
companyNames = companyNames.Distinct<string>().Skip(offSet ?? 0).ToList();
return companyNames.Take(count??companyNames.Count()).ToList();
As you can see, I first collect ALL the fields (several thousands) and then distinct them, possibly skip some and take some out.
I feel like there should be a better way to do this.