private List<FacetResult> search() throws IOException {
  DirectoryReader indexReader=DirectoryReader.open(indexDir);
  IndexSearcher searcher=new IndexSearcher(indexReader);
  SortedSetDocValuesReaderState state=new DefaultSortedSetDocValuesReaderState(indexReader);
  FacetsCollector fc=new FacetsCollector();
  FacetsCollector.search(searcher,new MatchAllDocsQuery(),10,fc);
  Facets facets=new SortedSetDocValuesFacetCounts(state,fc);
  List<FacetResult> results=new ArrayList<>();
  results.add(facets.getTopChildren(10,"Author"));
  results.add(facets.getTopChildren(10,"Publish Year"));
  indexReader.close();
  return results;
}

private List < FacetResult > search ( ) throws IOException { DirectoryReader indexReader = DirectoryReader . open ( indexDir ) ; IndexSearcher searcher = new IndexSearcher ( indexReader ) ; SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState ( indexReader ) ; FacetsCollector fc = new FacetsCollector ( ) ; FacetsCollector . search ( searcher , new MatchAllDocsQuery ( ) , 10 , fc ) ; Facets facets = new SortedSetDocValuesFacetCounts ( state , fc ) ; List < FacetResult > results = new ArrayList < > ( ) ; results . add ( facets . getTopChildren ( 10 , "Author" ) ) ; results . add ( facets . getTopChildren ( 10 , "Publish Year" ) ) ; indexReader . close ( ) ; return results ; }
user runs a query and counts facets .
