Package org.hibernate.search.reader

Examples of org.hibernate.search.reader.ReaderProvider


  }

  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;
  }
View Full Code Here

TOP

Related Classes of org.hibernate.search.reader.ReaderProvider

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.