@Override
  public void setScorer(Scorer scorer) {
    // System.out.println("C.setScorer scorer=" + scorer);
    // Since we invoke .score(), and the comparators likely
    // do as well, cache it so it's only "really" computed
    // once:
    this.scorer = new ScoreCachingWrappingScorer(scorer);
    for (int compIDX = 0; compIDX < comparators.length; compIDX++) {
      comparators[compIDX].setScorer(this.scorer);
    }
    Arrays.fill(joinScorers, null);

    Queue<Scorer> queue = new LinkedList<>();
    // System.out.println("\nqueue: add top scorer=" + scorer);
    queue.add(scorer);
    while ((scorer = queue.poll()) != null) {
      // System.out.println("  poll: " + scorer + "; " + scorer.getWeight().getQuery());
      if (scorer instanceof ToParentBlockJoinQuery.BlockJoinScorer) {
        enroll(
            (ToParentBlockJoinQuery) scorer.getWeight().getQuery(),
            (ToParentBlockJoinQuery.BlockJoinScorer) scorer);
      }

      for (ChildScorer sub : scorer.getChildren()) {
        // System.out.println("  add sub: " + sub.child + "; " + sub.child.getWeight().getQuery());
        queue.add(sub.child);
      }
    }
  }
Esempio n. 2
0
  /**
   * Get a list of all Spans made available from the passed-in Scorer
   *
   * @param scorer the scorer to extract spans from
   * @param errorOnNoSpans if true, throw an error if no Spans can be extracted from the Scorer or
   *     any of its children
   * @return a List of Spans
   */
  public static List<Spans> getSpans(Scorer scorer, boolean errorOnNoSpans) {

    List<Spans> spans = new ArrayList<>();
    if (scorer instanceof Spans) {
      spans.add((Spans) scorer);
      return spans;
    }

    Collection<Scorer.ChildScorer> children = scorer.getChildren();
    if (errorOnNoSpans && children.size() == 0)
      throw new RuntimeException(
          "Couldn't extract SpanScorer from " + scorer.getClass().getCanonicalName());

    for (Scorer.ChildScorer child : children) {
      spans.addAll(getSpans(child.child, errorOnNoSpans));
    }

    return spans;
  }