}
public int getNumberOfIndexedEntities(String entity) {
Class<?> clazz = getEntityClass( entity );
DirectoryProvider[] directoryProviders = searchFactoryImplementor.getDirectoryProviders( clazz );
ReaderProvider readerProvider = searchFactoryImplementor.getReaderProvider();
int count = 0;
for ( DirectoryProvider directoryProvider : directoryProviders ) {
IndexReader reader = readerProvider.openReader( directoryProvider );
IndexSearcher searcher = new IndexSearcher( reader );
BooleanQuery boolQuery = new BooleanQuery();
boolQuery.add( new MatchAllDocsQuery(), BooleanClause.Occur.MUST );
boolQuery.add(
new TermQuery( new Term( ProjectionConstants.OBJECT_CLASS, entity ) ), BooleanClause.Occur.MUST
);
try {
TopDocs topdocs = searcher.search( boolQuery, 1 );
count += topdocs.totalHits;
}
catch ( IOException e ) {
throw new RuntimeException( "Unable to execute count query for entity " + entity, e );
}
finally {
readerProvider.closeReader( reader );
}
}
return count;
}