/**
  * By default, uses the {@link PayloadFunction} to score the payloads, but can be overridden to
  * do other things.
  *
  * @param payLoads The payloads
  * @param start The start position of the span being scored
  * @param end The end position of the span being scored
  * @see Spans
  */
 protected void processPayloads(Collection<byte[]> payLoads, int start, int end) {
   for (final byte[] thePayload : payLoads) {
     payloadScore =
         function.currentScore(
             doc,
             fieldName,
             start,
             end,
             payloadsSeen,
             payloadScore,
             similarity.scorePayload(
                 doc, spans.start(), spans.end(), thePayload, 0, thePayload.length));
     ++payloadsSeen;
   }
 }
  private void dumpSpans(SpanQuery query) throws IOException {
    Spans spans = query.getSpans(reader);
    System.out.println(query + ":");
    int numSpans = 0;

    TopDocs hits = searcher.search(query, 10);
    float[] scores = new float[2];
    for (ScoreDoc sd : hits.scoreDocs) {
      scores[sd.doc] = sd.score;
    }

    while (spans.next()) { // A
      numSpans++;

      int id = spans.doc();
      Document doc = reader.document(id); // B

      TokenStream stream =
          analyzer.tokenStream(
              "contents", // C
              new StringReader(doc.get("f"))); // C
      TermAttribute term = stream.addAttribute(TermAttribute.class);

      StringBuilder buffer = new StringBuilder();
      buffer.append("   ");
      int i = 0;
      while (stream.incrementToken()) { // D
        if (i == spans.start()) { // E
          buffer.append("<"); // E
        } // E
        buffer.append(term.term()); // E
        if (i + 1 == spans.end()) { // E
          buffer.append(">"); // E
        } // E
        buffer.append(" ");
        i++;
      }
      buffer.append("(").append(scores[id]).append(") ");
      System.out.println(buffer);
    }

    if (numSpans == 0) {
      System.out.println("   No spans");
    }
    System.out.println();
  }
 @Override
 protected boolean setFreqCurrentDoc() throws IOException {
   if (!more) {
     return false;
   }
   doc = spans.doc();
   freq = 0.0f;
   payloadScore = 0;
   payloadsSeen = 0;
   do {
     int matchLength = spans.end() - spans.start();
     freq += similarity.sloppyFreq(matchLength);
     Spans[] spansArr = new Spans[1];
     spansArr[0] = spans;
     getPayloads(spansArr);
     more = spans.next();
   } while (more && (doc == spans.doc()));
   return true;
 }