public override float Score() { int doc = scorer.DocID(); if (doc != curDoc) { curScore = scorer.Score(); curDoc = doc; } return(curScore); }
/// <summary>Advance to non excluded doc. /// <br/>On entry: /// <ul> /// <li>reqScorer != null, </li> /// <li>exclScorer != null, </li> /// <li>reqScorer was advanced once via next() or skipTo() /// and reqScorer.doc() may still be excluded.</li> /// </ul> /// Advances reqScorer a non excluded required doc, if any. /// </summary> /// <returns> true iff there is a non excluded required doc. /// </returns> private int ToNonExcluded() { int exclDoc = exclDisi.DocID(); int reqDoc = reqScorer.DocID(); // may be excluded do { if (reqDoc < exclDoc) { return(reqDoc); // reqScorer advanced to before exclScorer, ie. not excluded } else if (reqDoc > exclDoc) { exclDoc = exclDisi.Advance(reqDoc); if (exclDoc == NO_MORE_DOCS) { exclDisi = null; // exhausted, no more exclusions return(reqDoc); } if (exclDoc > reqDoc) { return(reqDoc); // not excluded } } }while ((reqDoc = reqScorer.NextDoc()) != NO_MORE_DOCS); reqScorer = null; // exhausted, nothing left return(NO_MORE_DOCS); }
private void SearchWithFilter(IndexReader reader, Weight weight, Filter filter, Collector collector) { System.Diagnostics.Debug.Assert(filter != null); Scorer scorer = weight.Scorer(reader, true, false); if (scorer == null) { return; } int docID = scorer.DocID(); System.Diagnostics.Debug.Assert(docID == -1 || docID == DocIdSetIterator.NO_MORE_DOCS); // CHECKME: use ConjunctionScorer here? DocIdSet filterDocIdSet = filter.GetDocIdSet(reader); if (filterDocIdSet == null) { // this means the filter does not accept any documents. return; } DocIdSetIterator filterIter = filterDocIdSet.Iterator(); if (filterIter == null) { // this means the filter does not accept any documents. return; } int filterDoc = filterIter.NextDoc(); int scorerDoc = scorer.Advance(filterDoc); collector.SetScorer(scorer); while (true) { if (scorerDoc == filterDoc) { // Check if scorer has exhausted, only before collecting. if (scorerDoc == DocIdSetIterator.NO_MORE_DOCS) { break; } collector.Collect(scorerDoc); filterDoc = filterIter.NextDoc(); scorerDoc = scorer.Advance(filterDoc); } else if (scorerDoc > filterDoc) { filterDoc = filterIter.Advance(scorerDoc); } else { scorerDoc = scorer.Advance(filterDoc); } } }
/* The subtree of subScorers at root is a min heap except possibly for its root element. * Bubble the root down as required to make the subtree a heap. */ private void HeapAdjust(int root) { Scorer scorer = subScorers[root]; int doc = scorer.DocID(); int i = root; while (i <= (numScorers >> 1) - 1) { int lchild = (i << 1) + 1; Scorer lscorer = subScorers[lchild]; int ldoc = lscorer.DocID(); int rdoc = System.Int32.MaxValue, rchild = (i << 1) + 2; Scorer rscorer = null; if (rchild < numScorers) { rscorer = subScorers[rchild]; rdoc = rscorer.DocID(); } if (ldoc < doc) { if (rdoc < ldoc) { subScorers[i] = rscorer; subScorers[rchild] = scorer; i = rchild; } else { subScorers[i] = lscorer; subScorers[lchild] = scorer; i = lchild; } } else if (rdoc < doc) { subScorers[i] = rscorer; subScorers[rchild] = scorer; i = rchild; } else { return; } } }
/// <summary>Returns the score of the current document matching the query. /// Initially invalid, until {@link #Next()} is called the first time. /// </summary> /// <returns> The score of the required scorer, eventually increased by the score /// of the optional scorer when it also matches the current document. /// </returns> public override float Score() { int curDoc = reqScorer.DocID(); float reqScore = reqScorer.Score(); if (optScorer == null) { return(reqScore); } int optScorerDoc = optScorer.DocID(); if (optScorerDoc < curDoc && (optScorerDoc = optScorer.Advance(curDoc)) == NO_MORE_DOCS) { optScorer = null; return(reqScore); } return(optScorerDoc == curDoc?reqScore + optScorer.Score():reqScore); }
public override int NextDoc() { bool more; do { while (bucketTable.first != null) { // more queued current = bucketTable.first; bucketTable.first = current.next; // pop the queue // check prohibited & required, and minNrShouldMatch if ((current.bits & prohibitedMask) == 0 && (current.bits & requiredMask) == requiredMask && current.coord >= minNrShouldMatch) { return(doc = current.doc); } } // refill the queue more = false; end += BucketTable.SIZE; for (SubScorer sub = scorers; sub != null; sub = sub.next) { Scorer scorer = sub.scorer; sub.collector.SetScorer(scorer); int doc = scorer.DocID(); while (doc < end) { sub.collector.Collect(doc); doc = scorer.NextDoc(); } more |= (doc != NO_MORE_DOCS); } }while (bucketTable.first != null || more); return(this.doc = NO_MORE_DOCS); }
public override int DocID() { return(reqScorer.DocID()); }