private static long applyQueryDeletes(Iterable<QueryAndLimit> queriesIter, SegmentState segState) throws IOException {
    long delCount = 0;
    final LeafReaderContext readerContext = segState.reader.getContext();
    for (QueryAndLimit ent : queriesIter) {
      Query query = ent.query;
      int limit = ent.limit;
      final IndexSearcher searcher = new IndexSearcher(readerContext.reader());
      searcher.setQueryCache(null);
      final Weight weight = searcher.createNormalizedWeight(query, false);
      final Scorer scorer = weight.scorer(readerContext);
      if (scorer != null) {
        final DocIdSetIterator it = scorer.iterator();
        final Bits liveDocs = readerContext.reader().getLiveDocs();
        while (true)  {
          int doc = it.nextDoc();
          if (doc >= limit) {
            break;
          }
          if (liveDocs != null && liveDocs.get(doc) == false) {
            continue;
          }

          if (!segState.any) {
            segState.rld.initWritableLiveDocs();
            segState.any = true;
          }
          if (segState.rld.delete(doc)) {
            delCount++;
          }
        }
      }
    }

    return delCount;
  }