예제 #1
0
            public virtual void Collect(int doc)
            {
                float score = scorer.GetScore();

                try
                {
                    long startMS = J2N.Time.NanoTime() / J2N.Time.MillisecondsPerNanosecond; // LUCENENET: Use NanoTime() rather than CurrentTimeMilliseconds() for more accurate/reliable results
                    for (int i = lastDoc[0] + 1; i <= doc; i++)
                    {
                        Weight w       = s.CreateNormalizedWeight(q);
                        Scorer scorer_ = w.GetScorer(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_.GetScore();
                        Assert.AreEqual(skipToScore, scorer_.GetScore(), 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 && (J2N.Time.NanoTime() / J2N.Time.MillisecondsPerNanosecond) - startMS > 5) // LUCENENET: Use NanoTime() rather than CurrentTimeMilliseconds() for more accurate/reliable results
                        {
                            i = doc - 1;
                        }
                    }
                    lastDoc[0] = doc;
                }
                catch (Exception e) when(e.IsIOException())
                {
                    throw RuntimeException.Create(e);
                }
            }
예제 #2
0
            public virtual void Collect(int doc)
            {
                float score = scorer.GetScore();

                try
                {
                    long startMS = Environment.TickCount;
                    for (int i = lastDoc[0] + 1; i <= doc; i++)
                    {
                        Weight w       = s.CreateNormalizedWeight(q);
                        Scorer scorer_ = w.GetScorer(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_.GetScore();
                        Assert.AreEqual(skipToScore, scorer_.GetScore(), 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.ToString(), e);
                }
            }
예제 #3
0
            public override void Collect(int doc)
            {
                if (m_curDocs == null)
                {
                    // Cache was too large
                    cachedScorer.score = scorer.GetScore();
                    cachedScorer.doc   = doc;
                    m_other.Collect(doc);
                    return;
                }

                // Allocate a bigger array or abort caching
                if (m_upto == m_curDocs.Length)
                {
                    m_base += m_upto;

                    // Compute next array length - don't allocate too big arrays
                    int nextLength = 8 * m_curDocs.Length;
                    if (nextLength > MAX_ARRAY_SIZE)
                    {
                        nextLength = MAX_ARRAY_SIZE;
                    }

                    if (m_base + nextLength > m_maxDocsToCache)
                    {
                        // try to allocate a smaller array
                        nextLength = m_maxDocsToCache - m_base;
                        if (nextLength <= 0)
                        {
                            // Too many docs to collect -- clear cache
                            m_curDocs = null;
                            curScores = null;
                            m_cachedSegs.Clear();
                            m_cachedDocs.Clear();
                            cachedScores.Clear();
                            cachedScorer.score = scorer.GetScore();
                            cachedScorer.doc   = doc;
                            m_other.Collect(doc);
                            return;
                        }
                    }

                    m_curDocs = new int[nextLength];
                    m_cachedDocs.Add(m_curDocs);
                    curScores = new float[nextLength];
                    cachedScores.Add(curScores);
                    m_upto = 0;
                }

                m_curDocs[m_upto]  = doc;
                cachedScorer.score = curScores[m_upto] = scorer.GetScore();
                m_upto++;
                cachedScorer.doc = doc;
                m_other.Collect(doc);
            }
예제 #4
0
            public void Collect(int doc)
            {
                // just a sanity check to avoid IOOB.
                if (idx == mscores.Length)
                {
                    return;
                }

                // just call score() a couple of times and record the score.
                mscores[idx] = scorer.GetScore();
                mscores[idx] = scorer.GetScore();
                mscores[idx] = scorer.GetScore();
                ++idx;
            }
예제 #5
0
            public void Collect(int doc)
            {
                // just a sanity check to avoid IOOB.
                if (Idx == Mscores.Length)
                {
                    return;
                }

                // just call score() a couple of times and record the score.
                Mscores[Idx] = Scorer_Renamed.GetScore();
                Mscores[Idx] = Scorer_Renamed.GetScore();
                Mscores[Idx] = Scorer_Renamed.GetScore();
                ++Idx;
            }
예제 #6
0
 public virtual void Collect(int doc)
 {
     if (scorer.GetScore() > 0)
     {
         c.Collect(doc);
     }
 }
예제 #7
0
        public override float GetScore()
        {
            coordinator.nrMatchers = 0;
            float sum = countingSumScorer.GetScore();

            return(sum * coordinator.coordFactors[coordinator.nrMatchers]);
        }
예제 #8
0
        public virtual void TestNext()
        {
            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.GetScorer(context, (context.AtomicReader).LiveDocs);

            Assert.IsTrue(ts.NextDoc() != DocIdSetIterator.NO_MORE_DOCS, "next did not return a doc");
            Assert.IsTrue(ts.GetScore() == 1.6931472f, "score is not correct");
            Assert.IsTrue(ts.NextDoc() != DocIdSetIterator.NO_MORE_DOCS, "next did not return a doc");
            Assert.IsTrue(ts.GetScore() == 1.6931472f, "score is not correct");
            Assert.IsTrue(ts.NextDoc() == DocIdSetIterator.NO_MORE_DOCS, "next returned a doc and it should not have");
        }
예제 #9
0
            public virtual void Collect(int doc)
            {
                float score = scorer.GetScore();

                doc = doc + @base;
                Docs.Add(new TestHit(OuterInstance, doc, score));
                Assert.IsTrue(score > 0, "score " + score + " is not greater than 0");
                Assert.IsTrue(doc == 0 || doc == 5, "Doc: " + doc + " does not equal 0 or doc does not equal 5");
            }
예제 #10
0
        public override float GetScore()
        {
            Debug.Assert(Iterating());
            float score = @in.GetScore();

            Debug.Assert(!float.IsNaN(score));
            Debug.Assert(!float.IsNaN(score));
            return(score);
        }
예제 #11
0
        public override float GetScore()
        {
            int doc = scorer.DocID;

            if (doc != curDoc)
            {
                curScore = scorer.GetScore();
                curDoc   = doc;
            }

            return(curScore);
        }
예제 #12
0
        protected override void AfterNext()
        {
            Scorer sub = m_subScorers[0];

            m_doc = sub.DocID;
            if (m_doc != NO_MORE_DOCS)
            {
                m_score      = sub.GetScore();
                m_nrMatchers = 1;
                CountMatches(1);
                CountMatches(2);
            }
        }
예제 #13
0
            public virtual void Collect(int doc)
            {
                float score = sc.GetScore();

                lastDoc[0] = doc;
                try
                {
                    if (scorer == null)
                    {
                        Weight w = s.CreateNormalizedWeight(q);
                        AtomicReaderContext context = readerContextArray[leafPtr];
                        scorer = w.GetScorer(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.GetScore();
                    float scorerScore2 = scorer.GetScore();
                    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.ToString(), e);
                }
            }
예제 #14
0
            public void Collect(int doc)
            {
                BucketTable table  = bucketTable;
                int         i      = doc & BucketTable.MASK;
                Bucket      bucket = table.buckets[i];

                if (bucket.Doc != doc)                // invalid bucket
                {
                    bucket.Doc   = doc;               // set doc
                    bucket.Score = scorer.GetScore(); // initialize score
                    bucket.Bits  = mask;              // initialize mask
                    bucket.Coord = 1;                 // initialize coord

                    bucket.Next = table.first;        // push onto valid list
                    table.first = bucket;
                } // valid bucket
                else
                {
                    bucket.Score += scorer.GetScore(); // increment score
                    bucket.Bits  |= mask;              // add bits in mask
                    bucket.Coord++;                    // increment coord
                }
            }
예제 #15
0
            public override float GetScore()
            {
                int doc = DocID;

                if (doc >= lastScoredDoc)
                {
                    if (doc > lastScoredDoc)
                    {
                        lastDocScore  = scorer.GetScore();
                        lastScoredDoc = doc;
                    }
                    outerInstance.coordinator.nrMatchers++;
                }
                return(lastDocScore);
            }
예제 #16
0
 public void Collect(int doc)
 {
     DocIDs[Buffered] = doc;
     Scores[Buffered] = Scorer_Renamed.GetScore();
     try
     {
         Freqs[Buffered] = Scorer_Renamed.Freq;
     }
     catch (System.NotSupportedException)
     {
         Freqs[Buffered] = -1;
     }
     if (++Buffered == BufferSize)
     {
         Flush();
     }
 }
예제 #17
0
 public void Collect(int doc)
 {
     docIDs[buffered] = doc;
     scores[buffered] = scorer.GetScore();
     try
     {
         freqs[buffered] = scorer.Freq;
     }
     catch (NotSupportedException)
     {
         freqs[buffered] = -1;
     }
     if (++buffered == bufferSize)
     {
         Flush();
     }
 }
예제 #18
0
 public void Collect(int doc)
 {
     docIDs[buffered] = doc;
     scores[buffered] = scorer.GetScore();
     try
     {
         freqs[buffered] = scorer.Freq;
     }
     catch (Exception e) when(e.IsUnsupportedOperationException())
     {
         freqs[buffered] = -1;
     }
     if (++buffered == bufferSize)
     {
         Flush();
     }
 }
예제 #19
0
 private void AssertNext(Scorer expected, Scorer actual)
 {
     if (actual == null)
     {
         Assert.AreEqual(DocIdSetIterator.NO_MORE_DOCS, expected.NextDoc());
         return;
     }
     int doc;
     while ((doc = expected.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS)
     {
         Assert.AreEqual(doc, actual.NextDoc());
         Assert.AreEqual(expected.Freq, actual.Freq);
         float expectedScore = expected.GetScore();
         float actualScore = actual.GetScore();
         Assert.AreEqual(expectedScore, actualScore, CheckHits.ExplainToleranceDelta(expectedScore, actualScore));
     }
     Assert.AreEqual(DocIdSetIterator.NO_MORE_DOCS, actual.NextDoc());
 }
예제 #20
0
        public virtual void Collect(int doc)
        {
            Explanation exp = null;

            doc = doc + @base;
            try
            {
                exp = s.Explain(q, doc);
            }
            catch (IOException e)
            {
                throw new Exception("exception in hitcollector of [[" + d + "]] for #" + doc, e);
            }

            Assert.IsNotNull(exp, "Explanation of [[" + d + "]] for #" + doc + " is null");
            CheckHits.VerifyExplanation(d, doc, scorer.GetScore(), deep, exp);
            Assert.IsTrue(exp.IsMatch, "Explanation of [[" + d + "]] for #" + doc + " does not indicate match: " + exp.ToString());
        }
예제 #21
0
        public virtual void Collect(int doc)
        {
            Explanation exp; // LUCENENET: IDE0059: Remove unnecessary value assignment

            doc = doc + @base;
            try
            {
                exp = s.Explain(q, doc);
            }
            catch (Exception e) when(e.IsIOException())
            {
                throw RuntimeException.Create("exception in hitcollector of [[" + d + "]] for #" + doc, e);
            }

            Assert.IsNotNull(exp, "Explanation of [[" + d + "]] for #" + doc + " is null");
            CheckHits.VerifyExplanation(d, doc, scorer.GetScore(), deep, exp);
            Assert.IsTrue(exp.IsMatch, "Explanation of [[" + d + "]] for #" + doc + " does not indicate match: " + exp.ToString());
        }
예제 #22
0
        private void AssertAdvance(Scorer expected, Scorer actual, int amount)
        {
            if (actual is null)
            {
                Assert.AreEqual(DocIdSetIterator.NO_MORE_DOCS, expected.NextDoc());
                return;
            }
            int prevDoc = 0;
            int doc;

            while ((doc = expected.Advance(prevDoc + amount)) != DocIdSetIterator.NO_MORE_DOCS)
            {
                Assert.AreEqual(doc, actual.Advance(prevDoc + amount));
                Assert.AreEqual(expected.Freq, actual.Freq);
                float expectedScore = expected.GetScore();
                float actualScore   = actual.GetScore();
                Assert.AreEqual(expectedScore, actualScore, CheckHits.ExplainToleranceDelta(expectedScore, actualScore));
                prevDoc = doc;
            }
            Assert.AreEqual(DocIdSetIterator.NO_MORE_DOCS, actual.Advance(prevDoc + amount));
        }
예제 #23
0
        /// <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 GetScore()
        {
            // TODO: sum into a double and cast to float if we ever send required clauses to BS1
            int   curDoc   = reqScorer.DocID;
            float reqScore = reqScorer.GetScore();

            if (optScorer is 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.GetScore() : reqScore);
        }
예제 #24
0
 public override sealed float GetScore()
 {
     return(scorer.GetScore());
 }
예제 #25
0
 public virtual void Collect(int doc)
 {
     Assert.IsFalse(float.IsInfinity(scorer.Freq));
     Assert.IsFalse(float.IsInfinity(scorer.GetScore()));
 }
예제 #26
0
 public virtual void Collect(int doc)
 {
     //System.out.println("Doc=" + doc + " score=" + score);
     Assert.AreEqual(2.0f, scorer.GetScore(), 0);
 }
예제 #27
0
 public virtual void Collect(int doc)
 {
     Assert.AreEqual(1.0f, scorer.GetScore(), 0);
 }
예제 #28
0
 public virtual void Collect(int doc)
 {
     scores[doc + @base] = scorer.GetScore();
 }
예제 #29
0
        [AwaitsFix(BugUrl = "https://github.com/apache/lucenenet/issues/269")] // LUCENENET TODO: this test fails on x86 on .NET Framework in Release mode only
#endif
        public virtual void TestBS2DisjunctionNextVsAdvance()
        {
            Directory         d = NewDirectory();
            RandomIndexWriter w = new RandomIndexWriter(
#if FEATURE_INSTANCE_TESTDATA_INITIALIZATION
                this,
#endif
                Random, d);
            int numDocs = AtLeast(300);

            for (int docUpto = 0; docUpto < numDocs; docUpto++)
            {
                string contents = "a";
                if (Random.Next(20) <= 16)
                {
                    contents += " b";
                }
                if (Random.Next(20) <= 8)
                {
                    contents += " c";
                }
                if (Random.Next(20) <= 4)
                {
                    contents += " d";
                }
                if (Random.Next(20) <= 2)
                {
                    contents += " e";
                }
                if (Random.Next(20) <= 1)
                {
                    contents += " f";
                }
                Document doc = new Document();
                doc.Add(new TextField("field", contents, Field.Store.NO));
                w.AddDocument(doc);
            }
            w.ForceMerge(1);
            IndexReader   r = w.GetReader();
            IndexSearcher s = NewSearcher(r);

            w.Dispose();

            for (int iter = 0; iter < 10 * RandomMultiplier; iter++)
            {
                if (Verbose)
                {
                    Console.WriteLine("iter=" + iter);
                }
                IList <string> terms = new List <string> {
                    "a", "b", "c", "d", "e", "f"
                };
                int numTerms = TestUtil.NextInt32(Random, 1, terms.Count);
                while (terms.Count > numTerms)
                {
                    terms.RemoveAt(Random.Next(terms.Count));
                }

                if (Verbose)
                {
                    Console.WriteLine("  terms=" + terms);
                }

                BooleanQuery q = new BooleanQuery();
                foreach (string term in terms)
                {
                    q.Add(new BooleanClause(new TermQuery(new Term("field", term)), Occur.SHOULD));
                }

                Weight weight = s.CreateNormalizedWeight(q);

                Scorer scorer = weight.GetScorer(s.m_leafContexts[0], null);

                // First pass: just use .NextDoc() to gather all hits
                IList <ScoreDoc> hits = new List <ScoreDoc>();
                while (scorer.NextDoc() != DocIdSetIterator.NO_MORE_DOCS)
                {
                    hits.Add(new ScoreDoc(scorer.DocID, scorer.GetScore()));
                }

                if (Verbose)
                {
                    Console.WriteLine("  " + hits.Count + " hits");
                }

                // Now, randomly next/advance through the list and
                // verify exact match:
                for (int iter2 = 0; iter2 < 10; iter2++)
                {
                    weight = s.CreateNormalizedWeight(q);
                    scorer = weight.GetScorer(s.m_leafContexts[0], null);

                    if (Verbose)
                    {
                        Console.WriteLine("  iter2=" + iter2);
                    }

                    int upto = -1;
                    while (upto < hits.Count)
                    {
                        int nextUpto;
                        int nextDoc;
                        int left = hits.Count - upto;
                        if (left == 1 || Random.nextBoolean())
                        {
                            // next
                            nextUpto = 1 + upto;
                            nextDoc  = scorer.NextDoc();
                        }
                        else
                        {
                            // advance
                            int inc = TestUtil.NextInt32(Random, 1, left - 1);
                            nextUpto = inc + upto;
                            nextDoc  = scorer.Advance(hits[nextUpto].Doc);
                        }

                        if (nextUpto == hits.Count)
                        {
                            Assert.AreEqual(DocIdSetIterator.NO_MORE_DOCS, nextDoc);
                        }
                        else
                        {
                            ScoreDoc hit = hits[nextUpto];
                            Assert.AreEqual(hit.Doc, nextDoc);
                            // Test for precise float equality:
                            Assert.IsTrue(hit.Score == scorer.GetScore(), "doc " + hit.Doc + " has wrong score: expected=" + hit.Score + " actual=" + scorer.GetScore());
                        }
                        upto = nextUpto;
                    }
                }
            }

            r.Dispose();
            d.Dispose();
        }
예제 #30
0
 public virtual void Collect(int doc)
 {
     Assert.AreEqual(1.0f, scorer.GetScore(), SCORE_COMP_THRESH, "score for doc " + (doc + @base) + " was not correct");
 }