예제 #1
0
 @Override
 public void collect(int doc) throws IOException {
   if (values != null) {
     int ord = (int) ordinals.getOrd(doc);
     long parentIdx = parentIdsIndex.get(ord);
     if (parentIdx < 0) {
       final BytesRef bytes = values.getValueByOrd(ord);
       final int hash = values.currentValueHash();
       parentIdx = parentIds.add(bytes, hash);
       if (parentIdx < 0) {
         parentIdx = -parentIdx - 1;
         scores.increment(parentIdx, scorer.score());
         occurrences.increment(parentIdx, 1);
       } else {
         scores = bigArrays.grow(scores, parentIdx + 1);
         scores.set(parentIdx, scorer.score());
         occurrences = bigArrays.grow(occurrences, parentIdx + 1);
         occurrences.set(parentIdx, 1);
       }
       parentIdsIndex.set(ord, parentIdx);
     } else {
       scores.increment(parentIdx, scorer.score());
       occurrences.increment(parentIdx, 1);
     }
   }
 }
예제 #2
0
      @Override
      public int advance(int target) throws IOException {
        if (remaining == 0) {
          return currentDocId = NO_MORE_DOCS;
        }

        currentDocId = parentsIterator.advance(target);
        if (currentDocId == DocIdSetIterator.NO_MORE_DOCS) {
          return currentDocId;
        }

        bytesValues.setDocument(currentDocId);
        long index = parentIds.find(bytesValues.nextValue(), bytesValues.currentValueHash());
        if (index != -1) {
          currentScore = scores.get(index);
          currentScore /= occurrences.get(index);
          remaining--;
          return currentDocId;
        } else {
          return nextDoc();
        }
      }