Example #1
0
 public static long count(IndexSearcher searcher, Query query) throws IOException {
   TotalHitCountCollector countCollector = new TotalHitCountCollector();
   // we don't need scores, so wrap it in a constant score query
   if (!(query instanceof ConstantScoreQuery)) {
     query = new ConstantScoreQuery(query);
   }
   searcher.search(query, countCollector);
   return countCollector.getTotalHits();
 }