public virtual void TestSpanScorerZeroSloppyFreq() { bool ordered = true; int slop = 1; IndexReaderContext topReaderContext = searcher.TopReaderContext; IList <AtomicReaderContext> leaves = topReaderContext.Leaves; int subIndex = ReaderUtil.SubIndex(11, leaves); for (int i = 0, c = leaves.Count; i < c; i++) { AtomicReaderContext ctx = leaves[i]; Similarity sim = new DefaultSimilarityAnonymousInnerClassHelper(this); Similarity oldSim = searcher.Similarity; Scorer spanScorer; try { searcher.Similarity = sim; SpanNearQuery snq = new SpanNearQuery(new SpanQuery[] { MakeSpanTermQuery("t1"), MakeSpanTermQuery("t2") }, slop, ordered); spanScorer = searcher.CreateNormalizedWeight(snq).GetScorer(ctx, ((AtomicReader)ctx.Reader).LiveDocs); } finally { searcher.Similarity = oldSim; } if (i == subIndex) { Assert.IsTrue(spanScorer.NextDoc() != DocIdSetIterator.NO_MORE_DOCS, "first doc"); Assert.AreEqual(spanScorer.DocID + ctx.DocBase, 11, "first doc number"); float score = spanScorer.GetScore(); Assert.IsTrue(score == 0.0f, "first doc score should be zero, " + score); } else { Assert.IsTrue(spanScorer.NextDoc() == DocIdSetIterator.NO_MORE_DOCS, "no second doc"); } } }
public virtual void TestSpanScorerZeroSloppyFreq() { bool ordered = true; int slop = 1; IndexReaderContext topReaderContext = Searcher.TopReaderContext; IList<AtomicReaderContext> leaves = topReaderContext.Leaves; int subIndex = ReaderUtil.SubIndex(11, leaves); for (int i = 0, c = leaves.Count; i < c; i++) { AtomicReaderContext ctx = leaves[i]; Similarity sim = new DefaultSimilarityAnonymousInnerClassHelper(this); Similarity oldSim = Searcher.Similarity; Scorer spanScorer; try { Searcher.Similarity = sim; SpanNearQuery snq = new SpanNearQuery(new SpanQuery[] { MakeSpanTermQuery("t1"), MakeSpanTermQuery("t2") }, slop, ordered); spanScorer = Searcher.CreateNormalizedWeight(snq).Scorer(ctx, ((AtomicReader)ctx.Reader).LiveDocs); } finally { Searcher.Similarity = oldSim; } if (i == subIndex) { Assert.IsTrue(spanScorer.NextDoc() != DocIdSetIterator.NO_MORE_DOCS, "first doc"); Assert.AreEqual(spanScorer.DocID() + ctx.DocBase, 11, "first doc number"); float score = spanScorer.Score(); Assert.IsTrue(score == 0.0f, "first doc score should be zero, " + score); } else { Assert.IsTrue(spanScorer.NextDoc() == DocIdSetIterator.NO_MORE_DOCS, "no second doc"); } } }