public void finish() throws IOException { if (contexts.length == 0) { return; } int currentContext = 0; int currentDocBase = 0; int nextDocBase = currentContext + 1 < contexts.length ? contexts[currentContext + 1].docBase : maxDoc; leafDelegate = delegate.getLeafCollector(contexts[currentContext]); DummyScorer dummy = new DummyScorer(); leafDelegate.setScorer(dummy); DocIdSetIterator it = new BitSetIterator(fieldValueCollapse.getCollapsedSet(), 0); // cost is not useful here int docId = -1; int nullScoreIndex = 0; float[] scores = fieldValueCollapse.getScores(); FloatArrayList nullScores = fieldValueCollapse.getNullScores(); float nullScore = fieldValueCollapse.getNullScore(); while ((docId = it.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { if (this.needsScores) { int ord = values.getOrd(docId); if (ord > -1) { dummy.score = scores[ord]; } else if (boostDocs != null && boostDocs.containsKey(docId)) { // It's an elevated doc so no score is needed dummy.score = 0F; } else if (nullPolicy == CollapsingPostFilter.NULL_POLICY_COLLAPSE) { dummy.score = nullScore; } else if (nullPolicy == CollapsingPostFilter.NULL_POLICY_EXPAND) { dummy.score = nullScores.get(nullScoreIndex++); } } while (docId >= nextDocBase) { currentContext++; currentDocBase = contexts[currentContext].docBase; nextDocBase = currentContext + 1 < contexts.length ? contexts[currentContext + 1].docBase : maxDoc; leafDelegate = delegate.getLeafCollector(contexts[currentContext]); leafDelegate.setScorer(dummy); } int contextDoc = docId - currentDocBase; dummy.docId = contextDoc; leafDelegate.collect(contextDoc); } if (delegate instanceof DelegatingCollector) { ((DelegatingCollector) delegate).finish(); } }
@Override public void finish() throws IOException { if (contexts.length == 0) { return; } if (nullScore > 0) { this.collapsedSet.set(nullDoc); } if (this.boostOrds != null) { for (int i = 0; i < this.boostOrds.length; i++) { ords[boostOrds[i]] = -1; } } for (int i = 0; i < ords.length; i++) { int doc = ords[i]; if (doc > -1) { collapsedSet.set(doc); } } int currentContext = 0; int currentDocBase = 0; int nextDocBase = currentContext + 1 < contexts.length ? contexts[currentContext + 1].docBase : maxDoc; leafDelegate = delegate.getLeafCollector(contexts[currentContext]); DummyScorer dummy = new DummyScorer(); leafDelegate.setScorer(dummy); DocIdSetIterator it = new BitSetIterator(collapsedSet, 0L); // cost is not useful here int docId = -1; int nullScoreIndex = 0; while ((docId = it.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { int ord = values.getOrd(docId); if (ord > -1) { dummy.score = scores[ord]; } else if (this.boostDocs != null && boostDocs.containsKey(docId)) { // Elevated docs don't need a score. dummy.score = 0F; } else if (nullPolicy == CollapsingPostFilter.NULL_POLICY_COLLAPSE) { dummy.score = nullScore; } else if (nullPolicy == CollapsingPostFilter.NULL_POLICY_EXPAND) { dummy.score = nullScores.get(nullScoreIndex++); } while (docId >= nextDocBase) { currentContext++; currentDocBase = contexts[currentContext].docBase; nextDocBase = currentContext + 1 < contexts.length ? contexts[currentContext + 1].docBase : maxDoc; leafDelegate = delegate.getLeafCollector(contexts[currentContext]); leafDelegate.setScorer(dummy); } int contextDoc = docId - currentDocBase; dummy.docId = contextDoc; leafDelegate.collect(contextDoc); } if (delegate instanceof DelegatingCollector) { ((DelegatingCollector) delegate).finish(); } }