/** Returns true iff <code>o</code> is equal to this. */
 @Override
 public boolean equals(Object o) {
   if (!super.equals(o)) {
     return false;
   }
   SpanPositionCheckQuery spcq = (SpanPositionCheckQuery) o;
   return match.equals(spcq.match);
 }
 @Override
 public Scorer scorer(
     AtomicReaderContext context, boolean scoreDocsInOrder, boolean topScorer, Bits acceptDocs)
     throws IOException {
   if (stats == null) {
     return null;
   } else {
     return new SpanScorer(
         query.getSpans(context, acceptDocs, termContexts),
         this,
         similarity.sloppySimScorer(stats, context));
   }
 }
  public SpanWeight(SpanQuery query, IndexSearcher searcher) throws IOException {
    this.similarity = searcher.getSimilarity();
    this.query = query;

    termContexts = new HashMap<Term, TermContext>();
    TreeSet<Term> terms = new TreeSet<Term>();
    query.extractTerms(terms);
    final IndexReaderContext context = searcher.getTopReaderContext();
    final TermStatistics termStats[] = new TermStatistics[terms.size()];
    int i = 0;
    for (Term term : terms) {
      TermContext state = TermContext.build(context, term, true);
      termStats[i] = searcher.termStatistics(term, state);
      termContexts.put(term, state);
      i++;
    }
    final String field = query.getField();
    if (field != null) {
      stats =
          similarity.computeWeight(
              query.getBoost(), searcher.collectionStatistics(query.getField()), termStats);
    }
  }
  @Override
  public Query rewrite(IndexReader reader) throws IOException {
    SpanPositionCheckQuery clone = null;

    SpanQuery rewritten = (SpanQuery) match.rewrite(reader);
    if (rewritten != match) {
      clone = (SpanPositionCheckQuery) this.clone();
      clone.match = rewritten;
    }

    if (clone != null) {
      return clone; // some clauses rewrote
    } else {
      return this; // no clauses rewrote
    }
  }
 @Override
 public SpanWeight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
   SpanWeight matchWeight = match.createWeight(searcher, false);
   return new SpanPositionCheckWeight(
       matchWeight, searcher, needsScores ? getTermContexts(matchWeight) : null);
 }
 @Override
 public String getField() {
   return match.getField();
 }
 @Override
 public int hashCode() {
   return match.hashCode() ^ super.hashCode();
 }
 @Override
 public void extractTerms(Set<Term> terms) {
   match.extractTerms(terms);
 }