public TopFieldDocs Call() { Debug.Assert(slice.Leaves.Length == 1); TopFieldDocs docs = searcher.Search(Arrays.AsList(slice.Leaves), weight, after, nDocs, sort, true, doDocScores || sort.NeedsScores, doMaxScore); @lock.Lock(); try { AtomicReaderContext ctx = slice.Leaves[0]; int @base = ctx.DocBase; hq.SetNextReader(ctx); hq.SetScorer(fakeScorer); foreach (ScoreDoc scoreDoc in docs.ScoreDocs) { fakeScorer.doc = scoreDoc.Doc - @base; fakeScorer.score = scoreDoc.Score; hq.Collect(scoreDoc.Doc - @base); } // Carry over maxScore from sub: if (doMaxScore && docs.MaxScore > hq.maxScore) { hq.maxScore = docs.MaxScore; } } finally { @lock.Unlock(); } return(docs); }
public override TopDocs Rescore(IndexSearcher searcher, TopDocs firstPassTopDocs, int topN) { // Copy ScoreDoc[] and sort by ascending docID: ScoreDoc[] hits = (ScoreDoc[])firstPassTopDocs.ScoreDocs.Clone(); Array.Sort(hits, new ComparerAnonymousInnerClassHelper(this)); IList <AtomicReaderContext> leaves = searcher.IndexReader.Leaves; TopFieldCollector collector = TopFieldCollector.Create(sort, topN, true, true, true, false); // Now merge sort docIDs from hits, with reader's leaves: int hitUpto = 0; int readerUpto = -1; int endDoc = 0; int docBase = 0; FakeScorer fakeScorer = new FakeScorer(); while (hitUpto < hits.Length) { ScoreDoc hit = hits[hitUpto]; int docID = hit.Doc; AtomicReaderContext readerContext = null; while (docID >= endDoc) { readerUpto++; readerContext = leaves[readerUpto]; endDoc = readerContext.DocBase + readerContext.Reader.MaxDoc; } if (readerContext != null) { // We advanced to another segment: collector.SetNextReader(readerContext); collector.SetScorer(fakeScorer); docBase = readerContext.DocBase; } fakeScorer.score = hit.Score; fakeScorer.doc = docID - docBase; collector.Collect(fakeScorer.doc); hitUpto++; } return(collector.GetTopDocs()); }