public override void Collect(int doc)
            {
                ++internalTotalHits;
                if (queueFull)
                {
                    if ((reverseMul * comparator.CompareBottom(doc)) <= 0)
                    {
                        // since docs are visited in doc Id order, if compare is 0, it means
                        // this document is largest than anything else in the queue, and
                        // therefore not competitive.
                        return;
                    }

                    // Compute the score only if the hit is competitive.
                    float score = scorer.Score();

                    // This hit is competitive - replace bottom element in queue & adjustTop
                    comparator.Copy(bottom.slot, doc);
                    UpdateBottom(doc, score);
                    comparator.SetBottom(bottom.slot);
                }
                else
                {
                    // Compute the score only if the hit is competitive.
                    float score = scorer.Score();

                    // Startup transient: queue hasn't gathered numHits yet
                    int slot = internalTotalHits - 1;
                    // Copy hit into queue
                    comparator.Copy(slot, doc);
                    Add(slot, doc, score);
                    if (queueFull)
                    {
                        comparator.SetBottom(bottom.slot);
                    }
                }
            }
Example #2
0
            public override int CompareBottom(int doc)
            {
                float score = scorer.Score();

                return(bottom > score?-1:(bottom < score?1:0));
            }
            public override void  Collect(int doc)
            {
                ++internalTotalHits;
                if (queueFull)
                {
                    // Fastmatch: return if this hit is not competitive
                    for (int i = 0; ; i++)
                    {
                        int c = reverseMul[i] * comparators[i].CompareBottom(doc);
                        if (c < 0)
                        {
                            // Definitely not competitive.
                            return;
                        }
                        else if (c > 0)
                        {
                            // Definitely competitive.
                            break;
                        }
                        else if (i == comparators.Length - 1)
                        {
                            // Here c=0. If we're at the last comparator, this doc is not
                            // competitive, since docs are visited in doc Id order, which means
                            // this doc cannot compete with any other document in the queue.
                            return;
                        }
                    }

                    // This hit is competitive - replace bottom element in queue & adjustTop
                    for (int i = 0; i < comparators.Length; i++)
                    {
                        comparators[i].Copy(bottom.slot, doc);
                    }

                    // Compute score only if it is competitive.
                    float score = scorer.Score();
                    UpdateBottom(doc, score);

                    for (int i = 0; i < comparators.Length; i++)
                    {
                        comparators[i].SetBottom(bottom.slot);
                    }
                }
                else
                {
                    // Startup transient: queue hasn't gathered numHits yet
                    int slot = internalTotalHits - 1;
                    // Copy hit into queue
                    for (int i = 0; i < comparators.Length; i++)
                    {
                        comparators[i].Copy(slot, doc);
                    }

                    // Compute score only if it is competitive.
                    float score = scorer.Score();
                    Add(slot, doc, score);
                    if (queueFull)
                    {
                        for (int i = 0; i < comparators.Length; i++)
                        {
                            comparators[i].SetBottom(bottom.slot);
                        }
                    }
                }
            }