public override bool Score(Collector collector, int maxDoc) { // the normalization trick already applies the boost of this query, // so we can use the wrapped scorer directly: collector.Scorer = Scorer; if (Scorer.DocID() == -1) { Scorer.NextDoc(); } while (true) { int scorerDoc = Scorer.DocID(); if (scorerDoc < maxDoc) { if (FilterBits.Get(scorerDoc)) { collector.Collect(scorerDoc); } Scorer.NextDoc(); } else { break; } } return(Scorer.DocID() != Scorer.NO_MORE_DOCS); }
public override float Score() { int doc = Scorer.DocID(); if (doc != CurDoc) { CurScore = Scorer.Score(); CurDoc = doc; } return(CurScore); }
public override float Score(IState state) { int doc = scorer.DocID(); if (doc != curDoc) { curScore = scorer.Score(state); 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); }
public override void Collect(int doc) { float score = scorer.Score(); try { long startMS = Environment.TickCount; for (int i = LastDoc[0] + 1; i <= doc; i++) { Weight w = s.CreateNormalizedWeight(q); Scorer scorer_ = w.Scorer(Context[leafPtr], liveDocs); Assert.IsTrue(scorer_.Advance(i) != DocIdSetIterator.NO_MORE_DOCS, "query collected " + doc + " but skipTo(" + i + ") says no more docs!"); Assert.AreEqual(doc, scorer_.DocID(), "query collected " + doc + " but skipTo(" + i + ") got to " + scorer_.DocID()); float skipToScore = scorer_.Score(); Assert.AreEqual(skipToScore, scorer_.Score(), MaxDiff, "unstable skipTo(" + i + ") score!"); Assert.AreEqual(score, skipToScore, MaxDiff, "query assigned doc " + doc + " a score of <" + score + "> but skipTo(" + i + ") has <" + skipToScore + ">!"); // Hurry things along if they are going slow (eg // if you got SimpleText codec this will kick in): if (i < doc && Environment.TickCount - startMS > 5) { i = doc - 1; } } LastDoc[0] = doc; } catch (IOException e) { throw new Exception(e.Message, e); } }
public override void Collect(int doc, IState state) { float score = sc.Score(null); lastDoc[0] = doc; try { if (scorer == null) { Weight w = q.Weight(s, null); scorer = w.Scorer(reader, true, false, null); } int op = order[(opidx[0]++) % order.Length]; // System.out.println(op==skip_op ? // "skip("+(sdoc[0]+1)+")":"next()"); bool more = op == skip_op ? scorer.Advance(scorer.DocID() + 1, null) != DocIdSetIterator.NO_MORE_DOCS : scorer.NextDoc(null) != DocIdSetIterator.NO_MORE_DOCS; int scorerDoc = scorer.DocID(); float scorerScore = scorer.Score(null); float scorerScore2 = scorer.Score(null); float scoreDiff = System.Math.Abs(score - scorerScore); float scorerDiff = System.Math.Abs(scorerScore2 - scorerScore); if (!more || doc != scorerDoc || scoreDiff > maxDiff || scorerDiff > maxDiff) { System.Text.StringBuilder sbord = new System.Text.StringBuilder(); for (int i = 0; i < order.Length; i++) { sbord.Append(order[i] == skip_op?" skip()":" next()"); } throw new System.SystemException("ERROR matching docs:" + "\n\t" + (doc != scorerDoc ? "--> " : "") + "scorerDoc=" + scorerDoc + "\n\t" + (!more ? "--> " : "") + "tscorer.more=" + more + "\n\t" + (scoreDiff > maxDiff ? "--> " : "") + "scorerScore=" + scorerScore + " scoreDiff=" + scoreDiff + " maxDiff=" + maxDiff + "\n\t" + (scorerDiff > maxDiff ? "--> " : "") + "scorerScore2=" + scorerScore2 + " scorerDiff=" + scorerDiff + "\n\thitCollector.doc=" + doc + " score=" + score + "\n\t Scorer=" + scorer + "\n\t Query=" + q + " " + q.GetType().FullName + "\n\t Searcher=" + s + "\n\t Order=" + sbord + "\n\t Op=" + (op == skip_op ? " skip()" : " next()")); } } catch (System.IO.IOException e) { throw new System.SystemException("", e); } }
private void SearchWithFilter(IndexReader reader, Weight weight, Filter filter, Collector collector, IState state) { System.Diagnostics.Debug.Assert(filter != null); Scorer scorer = weight.Scorer(reader, true, false, state); 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, state); if (filterDocIdSet == null) { // this means the filter does not accept any documents. return; } DocIdSetIterator filterIter = filterDocIdSet.Iterator(state); if (filterIter == null) { // this means the filter does not accept any documents. return; } int filterDoc = filterIter.NextDoc(state); int scorerDoc = scorer.Advance(filterDoc, state); 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, state); filterDoc = filterIter.NextDoc(state); scorerDoc = scorer.Advance(filterDoc, state); } else if (scorerDoc > filterDoc) { filterDoc = filterIter.Advance(scorerDoc, state); } else { scorerDoc = scorer.Advance(filterDoc, state); } } }
/// <summary> /// Returns the score of the current document matching the query. /// Initially invalid, until <seealso cref="#nextDoc()"/> 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() { // TODO: sum into a double and cast to float if we ever send required clauses to BS1 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 void Collect(int doc) { IDictionary <Query, float?> freqs = new Dictionary <Query, float?>(); foreach (KeyValuePair <Query, Scorer> ent in SubScorers) { Scorer value = ent.Value; int matchId = value.DocID(); freqs[ent.Key] = matchId == doc?value.Freq() : 0.0f; } DocCounts[doc + DocBase] = freqs; Other.Collect(doc); }
public override void Collect(int doc) { float score = sc.Score(); LastDoc[0] = doc; try { if (scorer == null) { Weight w = s.CreateNormalizedWeight(q); AtomicReaderContext context = ReaderContextArray[leafPtr]; scorer = w.Scorer(context, (context.AtomicReader).LiveDocs); } int op = Order[(Opidx[0]++) % Order.Length]; // System.out.println(op==skip_op ? // "skip("+(sdoc[0]+1)+")":"next()"); bool more = op == Skip_op?scorer.Advance(scorer.DocID() + 1) != DocIdSetIterator.NO_MORE_DOCS : scorer.NextDoc() != DocIdSetIterator.NO_MORE_DOCS; int scorerDoc = scorer.DocID(); float scorerScore = scorer.Score(); float scorerScore2 = scorer.Score(); float scoreDiff = Math.Abs(score - scorerScore); float scorerDiff = Math.Abs(scorerScore2 - scorerScore); if (!more || doc != scorerDoc || scoreDiff > MaxDiff || scorerDiff > MaxDiff) { StringBuilder sbord = new StringBuilder(); for (int i = 0; i < Order.Length; i++) { sbord.Append(Order[i] == Skip_op ? " skip()" : " next()"); } throw new Exception("ERROR matching docs:" + "\n\t" + (doc != scorerDoc ? "--> " : "") + "doc=" + doc + ", scorerDoc=" + scorerDoc + "\n\t" + (!more ? "--> " : "") + "tscorer.more=" + more + "\n\t" + (scoreDiff > MaxDiff ? "--> " : "") + "scorerScore=" + scorerScore + " scoreDiff=" + scoreDiff + " maxDiff=" + MaxDiff + "\n\t" + (scorerDiff > MaxDiff ? "--> " : "") + "scorerScore2=" + scorerScore2 + " scorerDiff=" + scorerDiff + "\n\thitCollector.Doc=" + doc + " score=" + score + "\n\t Scorer=" + scorer + "\n\t Query=" + q + " " + q.GetType().Name + "\n\t Searcher=" + s + "\n\t Order=" + sbord + "\n\t Op=" + (op == Skip_op ? " skip()" : " next()")); } } catch (IOException e) { throw new Exception(e.Message, e); } }
public virtual void TestSkipToFirsttimeHit() { DisjunctionMaxQuery dq = new DisjunctionMaxQuery(0.0f); dq.Add(Tq("dek", "albino")); dq.Add(Tq("dek", "DOES_NOT_EXIST")); QueryUtils.Check(dq, s); Weight dw = dq.Weight(s); Scorer ds = dw.Scorer(r, true, false); Assert.IsTrue(ds.Advance(3) != DocIdSetIterator.NO_MORE_DOCS, "firsttime skipTo found no match"); Assert.AreEqual("d4", r.Document(ds.DocID()).Get("id"), "found wrong docid"); }
public virtual void TestAdvance() { Term allTerm = new Term(FIELD, "all"); TermQuery termQuery = new TermQuery(allTerm); Weight weight = IndexSearcher.CreateNormalizedWeight(termQuery); Assert.IsTrue(IndexSearcher.TopReaderContext is AtomicReaderContext); AtomicReaderContext context = (AtomicReaderContext)IndexSearcher.TopReaderContext; Scorer ts = weight.Scorer(context, (context.AtomicReader).LiveDocs); Assert.IsTrue(ts.Advance(3) != DocIdSetIterator.NO_MORE_DOCS, "Didn't skip"); // The next doc should be doc 5 Assert.IsTrue(ts.DocID() == 5, "doc should be number 5"); }
public virtual void TestSkipToFirsttimeHit() { DisjunctionMaxQuery dq = new DisjunctionMaxQuery(0.0f); dq.Add(Tq("dek", "albino")); dq.Add(Tq("dek", "DOES_NOT_EXIST")); Assert.IsTrue(s.TopReaderContext is AtomicReaderContext); QueryUtils.Check(Random(), dq, s); Weight dw = s.CreateNormalizedWeight(dq); AtomicReaderContext context = (AtomicReaderContext)s.TopReaderContext; Scorer ds = dw.Scorer(context, (context.AtomicReader).LiveDocs); Assert.IsTrue(ds.Advance(3) != DocIdSetIterator.NO_MORE_DOCS, "firsttime skipTo found no match"); Assert.AreEqual("d4", r.Document(ds.DocID()).Get("id"), "found wrong docid"); }
/// <summary> /// 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. /// </summary> protected internal void MinheapSiftDown(int root) { // TODO could this implementation also move rather than swapping neighbours? Scorer scorer = SubScorers[root]; int doc = scorer.DocID(); int i = root; while (i <= (NrInHeap >> 1) - 1) { int lchild = (i << 1) + 1; Scorer lscorer = SubScorers[lchild]; int ldoc = lscorer.DocID(); int rdoc = int.MaxValue, rchild = (i << 1) + 2; Scorer rscorer = null; if (rchild < NrInHeap) { 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; } } }
/* 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> /// 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. /// </summary> protected internal 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 = int.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; } } }
public virtual void TestSkipToFirsttimeMiss() { DisjunctionMaxQuery dq = new DisjunctionMaxQuery(0.0f); dq.Add(Tq("id", "d1")); dq.Add(Tq("dek", "DOES_NOT_EXIST")); QueryUtils.Check(dq, s); Weight dw = dq.Weight(s); Scorer ds = dw.Scorer(r, true, false); bool skipOk = ds.Advance(3) != DocIdSetIterator.NO_MORE_DOCS; if (skipOk) { Assert.Fail("firsttime skipTo found a match? ... " + r.Document(ds.DocID()).Get("id")); } }
public virtual void TestSkipToFirsttimeMiss() { DisjunctionMaxQuery dq = new DisjunctionMaxQuery(0.0f); dq.Add(Tq("id", "d1")); dq.Add(Tq("dek", "DOES_NOT_EXIST")); QueryUtils.Check(Random(), dq, s); Assert.IsTrue(s.TopReaderContext is AtomicReaderContext); Weight dw = s.CreateNormalizedWeight(dq); AtomicReaderContext context = (AtomicReaderContext)s.TopReaderContext; Scorer ds = dw.Scorer(context, (context.AtomicReader).LiveDocs); bool skipOk = ds.Advance(3) != DocIdSetIterator.NO_MORE_DOCS; if (skipOk) { Assert.Fail("firsttime skipTo found a match? ... " + r.Document(ds.DocID()).Get("id")); } }
/// <summary>Returns the score of the current document matching the query. /// Initially invalid, until <see cref="NextDoc()" /> 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(IState state) { int curDoc = reqScorer.DocID(); float reqScore = reqScorer.Score(state); if (optScorer == null) { return(reqScore); } int optScorerDoc = optScorer.DocID(); if (optScorerDoc < curDoc && (optScorerDoc = optScorer.Advance(curDoc, state)) == NO_MORE_DOCS) { optScorer = null; return(reqScore); } return(optScorerDoc == curDoc?reqScore + optScorer.Score(state):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); }
protected internal void MinheapSiftUp(int i) { Scorer scorer = SubScorers[i]; int doc = scorer.DocID(); // find right place for scorer while (i > 0) { int parent = (i - 1) >> 1; Scorer pscorer = SubScorers[parent]; int pdoc = pscorer.DocID(); if (pdoc > doc) // move root down, make space { SubScorers[i] = SubScorers[parent]; i = parent; } // done, found right place else { break; } } SubScorers[i] = scorer; }
public override bool Score(Collector collector, int max) { // TODO: this may be sort of weird, when we are // embedded in a BooleanScorer, because we are // called for every chunk of 2048 documents. But, // then, scorer is a FakeScorer in that case, so any // Collector doing something "interesting" in // setScorer will be forced to use BS2 anyways: collector.Scorer = Scorer; if (max == DocIdSetIterator.NO_MORE_DOCS) { ScoreAll(collector, Scorer); return(false); } else { int doc = Scorer.DocID(); if (doc < 0) { doc = Scorer.NextDoc(); } return(ScoreRange(collector, Scorer, doc, max)); } }
public override void Collect(int doc, IState state) { //System.out.println("doc="+doc); float score = this.scorer.Score(null); try { for (int i = lastDoc[0] + 1; i <= doc; i++) { Weight w = q.Weight(s, null); Scorer scorer = w.Scorer(reader, true, false, null); Assert.IsTrue(scorer.Advance(i, null) != DocIdSetIterator.NO_MORE_DOCS, "query collected " + doc + " but skipTo(" + i + ") says no more docs!"); Assert.AreEqual(doc, scorer.DocID(), "query collected " + doc + " but skipTo(" + i + ") got to " + scorer.DocID()); float skipToScore = scorer.Score(null); Assert.AreEqual(skipToScore, scorer.Score(null), maxDiff, "unstable skipTo(" + i + ") score!"); Assert.AreEqual(score, skipToScore, maxDiff, "query assigned doc " + doc + " a score of <" + score + "> but skipTo(" + i + ") has <" + skipToScore + ">!"); } lastDoc[0] = doc; } catch (System.IO.IOException e) { throw new System.SystemException("", e); } }
private void SearchWithFilter(IndexReader reader, Weight weight, Scorer scorer, Collector collector) { if (scorer == null) return; scorer.DocID(); DocIdSetIterator docIdSetIterator = scorer; if (docIdSetIterator == null) return; int target = docIdSetIterator.NextDoc(); int num = target; // int num = scorer.Advance(target); collector.SetScorer(scorer); while (true) { //while (num != target) //{ // if (num > target) // target = docIdSetIterator.Advance(num); // else // num = scorer.Advance(target); //} if (num != DocIdSetIterator.NO_MORE_DOCS && !((BloclGroupingCollector) collector).GroupLimitReached) { collector.Collect(num); num = docIdSetIterator.NextDoc(); //target = docIdSetIterator.NextDoc(); //num = scorer.Advance(target); } else break; } }
private void SearchWithScorer(IndexReader reader, Weight weight, Scorer scorer, Collector collector) { if (scorer == null) return; scorer.DocID(); int num = scorer.NextDoc(); ; collector.SetScorer(scorer); while (true) { if (num != DocIdSetIterator.NO_MORE_DOCS && !((GroupCollector)collector).GroupLimitReached) { collector.Collect(num); num = scorer.NextDoc(); } else break; } }
public override TopDocs Rescore(IndexSearcher searcher, TopDocs firstPassTopDocs, int topN) { ScoreDoc[] hits = (ScoreDoc[])firstPassTopDocs.ScoreDocs.Clone(); Array.Sort(hits, new ComparatorAnonymousInnerClassHelper(this)); IList <AtomicReaderContext> leaves = searcher.IndexReader.Leaves; Weight weight = searcher.CreateNormalizedWeight(Query); // Now merge sort docIDs from hits, with reader's leaves: int hitUpto = 0; int readerUpto = -1; int endDoc = 0; int docBase = 0; Scorer scorer = null; 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: docBase = readerContext.DocBase; scorer = weight.Scorer(readerContext, null); } int targetDoc = docID - docBase; int actualDoc = scorer.DocID(); if (actualDoc < targetDoc) { actualDoc = scorer.Advance(targetDoc); } if (actualDoc == targetDoc) { // Query did match this doc: hit.Score = Combine(hit.Score, true, scorer.Score()); } else { // Query did not match this doc: Debug.Assert(actualDoc > targetDoc); hit.Score = Combine(hit.Score, false, 0.0f); } hitUpto++; } // TODO: we should do a partial sort (of only topN) // instead, but typically the number of hits is // smallish: Array.Sort(hits, new ComparatorAnonymousInnerClassHelper2(this)); if (topN < hits.Length) { ScoreDoc[] subset = new ScoreDoc[topN]; Array.Copy(hits, 0, subset, 0, topN); hits = subset; } return(new TopDocs(firstPassTopDocs.TotalHits, hits, hits[0].Score)); }
public override int DocID() { return(reqScorer.DocID()); }
// check that first skip on just created scorers always goes to the right doc private static void CheckFirstSkipTo(Query q, IndexSearcher s) { //System.out.println("checkFirstSkipTo: "+q); float maxDiff = 1e-4f; //{{Lucene.Net-2.9.1}}Intentional diversion from Java Lucene int[] lastDoc = new int[] { -1 }; IndexReader[] lastReader = { null }; s.Search(q, new AnonymousClassCollector1(lastDoc, q, s, maxDiff, lastReader), null); if (lastReader[0] != null) { // confirm that skipping beyond the last doc, on the // previous reader, hits NO_MORE_DOCS IndexReader previousReader = lastReader[0]; Weight w = q.Weight(new IndexSearcher(previousReader), null); Scorer scorer = w.Scorer(previousReader, true, false, null); if (scorer != null) { bool more = scorer.Advance(lastDoc[0] + 1, null) != DocIdSetIterator.NO_MORE_DOCS; Assert.IsFalse(more, "query's last doc was " + lastDoc[0] + " but skipTo(" + (lastDoc[0] + 1) + ") got to " + scorer.DocID()); } } }
/// <summary>alternate scorer skipTo(),skipTo(),next(),next(),skipTo(),skipTo(), etc /// and ensure a hitcollector receives same docs and scores /// </summary> public static void CheckSkipTo(Query q, IndexSearcher s) { //System.out.println("Checking "+q); if (q.Weight(s, null).GetScoresDocsOutOfOrder()) { return; // in this case order of skipTo() might differ from that of next(). } int skip_op = 0; int next_op = 1; int[][] orders = new int[][] { new int[] { next_op }, new int[] { skip_op }, new int[] { skip_op, next_op }, new int[] { next_op, skip_op }, new int[] { skip_op, skip_op, next_op, next_op }, new int[] { next_op, next_op, skip_op, skip_op }, new int[] { skip_op, skip_op, skip_op, next_op, next_op } }; for (int k = 0; k < orders.Length; k++) { int[] order = orders[k]; // System.out.print("Order:");for (int i = 0; i < order.length; i++) // System.out.print(order[i]==skip_op ? " skip()":" next()"); // System.out.println(); int[] opidx = new int[] { 0 }; int[] lastDoc = new[] { -1 }; // FUTURE: ensure scorer.doc()==-1 float maxDiff = 1e-5f; IndexReader[] lastReader = new IndexReader[] { null }; s.Search(q, new AnonymousClassCollector(order, opidx, skip_op, lastReader, maxDiff, q, s, lastDoc), null); if (lastReader[0] != null) { // Confirm that skipping beyond the last doc, on the // previous reader, hits NO_MORE_DOCS IndexReader previousReader = lastReader[0]; Weight w = q.Weight(new IndexSearcher(previousReader), null); Scorer scorer = w.Scorer(previousReader, true, false, null); if (scorer != null) { bool more = scorer.Advance(lastDoc[0] + 1, null) != DocIdSetIterator.NO_MORE_DOCS; Assert.IsFalse(more, "query's last doc was " + lastDoc[0] + " but skipTo(" + (lastDoc[0] + 1) + ") got to " + scorer.DocID()); } } } }
public override void SetNextReader(IndexReader reader, int docBase, IState state) { // confirm that skipping beyond the last doc, on the // previous reader, hits NO_MORE_DOCS if (lastReader[0] != null) { IndexReader previousReader = lastReader[0]; Weight w = q.Weight(new IndexSearcher(previousReader), null); Scorer scorer = w.Scorer(previousReader, true, false, null); if (scorer != null) { bool more = scorer.Advance(lastDoc[0] + 1, null) != DocIdSetIterator.NO_MORE_DOCS; Assert.IsFalse(more, "query's last doc was " + lastDoc[0] + " but skipTo(" + (lastDoc[0] + 1) + ") got to " + scorer.DocID()); } } this.reader = lastReader[0] = reader; lastDoc[0] = -1; }
/// <summary> /// alternate scorer skipTo(),skipTo(),next(),next(),skipTo(),skipTo(), etc /// and ensure a hitcollector receives same docs and scores /// </summary> /// <param name = "similarity" > /// LUCENENET specific /// Removes dependency on <see cref="LuceneTestCase.ClassEnv.Similarity"/> /// </param> public static void CheckSkipTo(Query q, IndexSearcher s, Similarity similarity) { //System.out.println("Checking "+q); IList <AtomicReaderContext> readerContextArray = s.TopReaderContext.Leaves; if (s.CreateNormalizedWeight(q).ScoresDocsOutOfOrder()) // in this case order of skipTo() might differ from that of next(). { return; } const int skip_op = 0; const int next_op = 1; int[][] orders = new int[][] { new int[] { next_op }, new int[] { skip_op }, new int[] { skip_op, next_op }, new int[] { next_op, skip_op }, new int[] { skip_op, skip_op, next_op, next_op }, new int[] { next_op, next_op, skip_op, skip_op }, new int[] { skip_op, skip_op, skip_op, next_op, next_op } }; for (int k = 0; k < orders.Length; k++) { int[] order = orders[k]; // System.out.print("Order:");for (int i = 0; i < order.Length; i++) // System.out.print(order[i]==skip_op ? " skip()":" next()"); // System.out.println(); int[] opidx = new int[] { 0 }; int[] lastDoc = new int[] { -1 }; // FUTURE: ensure scorer.Doc()==-1 const float maxDiff = 1e-5f; AtomicReader[] lastReader = new AtomicReader[] { null }; s.Search(q, new CollectorAnonymousInnerClassHelper(q, s, readerContextArray, skip_op, order, opidx, lastDoc, maxDiff, lastReader, similarity)); if (lastReader[0] != null) { // confirm that skipping beyond the last doc, on the // previous reader, hits NO_MORE_DOCS AtomicReader previousReader = lastReader[0]; IndexSearcher indexSearcher = LuceneTestCase.NewSearcher(previousReader, false, similarity); indexSearcher.Similarity = s.Similarity; Weight w = indexSearcher.CreateNormalizedWeight(q); AtomicReaderContext ctx = (AtomicReaderContext)previousReader.Context; Scorer scorer = w.Scorer(ctx, ((AtomicReader)ctx.Reader).LiveDocs); if (scorer != null) { bool more = scorer.Advance(lastDoc[0] + 1) != DocIdSetIterator.NO_MORE_DOCS; Assert.IsFalse(more, "query's last doc was " + lastDoc[0] + " but skipTo(" + (lastDoc[0] + 1) + ") got to " + scorer.DocID()); } } } }
/// <summary> /// check that first skip on just created scorers always goes to the right doc</summary> /// <param name = "similarity" > /// LUCENENET specific /// Removes dependency on <see cref="LuceneTestCase.ClassEnv.Similarity"/> /// </param> public static void CheckFirstSkipTo(Query q, IndexSearcher s, Similarity similarity) { //System.out.println("checkFirstSkipTo: "+q); const float maxDiff = 1e-3f; int[] lastDoc = new int[] { -1 }; AtomicReader[] lastReader = new AtomicReader[] { null }; IList <AtomicReaderContext> context = s.TopReaderContext.Leaves; s.Search(q, new CollectorAnonymousInnerClassHelper2(q, s, maxDiff, lastDoc, lastReader, context, similarity)); if (lastReader[0] != null) { // confirm that skipping beyond the last doc, on the // previous reader, hits NO_MORE_DOCS AtomicReader previousReader = lastReader[0]; IndexSearcher indexSearcher = LuceneTestCase.NewSearcher(previousReader, similarity); indexSearcher.Similarity = s.Similarity; Weight w = indexSearcher.CreateNormalizedWeight(q); Scorer scorer = w.Scorer((AtomicReaderContext)indexSearcher.TopReaderContext, previousReader.LiveDocs); if (scorer != null) { bool more = scorer.Advance(lastDoc[0] + 1) != DocIdSetIterator.NO_MORE_DOCS; Assert.IsFalse(more, "query's last doc was " + lastDoc[0] + " but skipTo(" + (lastDoc[0] + 1) + ") got to " + scorer.DocID()); } } }