Esempio n. 1
0
        /// <summary> Just like {@link #Search(Weight, Filter, int, Sort)}, but you choose
        /// whether or not the fields in the returned {@link FieldDoc} instances
        /// should be set by specifying fillFields.<br/>
        ///
        /// <p/>
        /// NOTE: this does not compute scores by default. If you need scores, create
        /// a {@link TopFieldCollector} instance by calling
        /// {@link TopFieldCollector#create} and then pass that to
        /// {@link #Search(Weight, Filter, Collector)}.
        /// <p/>
        /// </summary>
        public virtual TopFieldDocs Search(Weight weight, Filter filter, int nDocs, Sort sort, bool fillFields)
        {
            nDocs = System.Math.Min(nDocs, reader.MaxDoc());

            SortField[] fields = sort.fields;
            bool        legacy = false;

            for (int i = 0; i < fields.Length; i++)
            {
                SortField     field     = fields[i];
                System.String fieldname = field.GetField();
                int           type      = field.GetType();
                // Resolve AUTO into its true type
                if (type == SortField.AUTO)
                {
                    int autotype = SortField.DetectFieldType(reader, fieldname);
                    if (autotype == SortField.STRING)
                    {
                        fields[i] = new SortField(fieldname, field.GetLocale(), field.GetReverse());
                    }
                    else
                    {
                        fields[i] = new SortField(fieldname, autotype, field.GetReverse());
                    }
                }

                if (field.GetUseLegacySearch())
                {
                    legacy = true;
                }
            }

            if (legacy)
            {
                // Search the single top-level reader
                TopDocCollector     collector = new TopFieldDocCollector(reader, sort, nDocs);
                HitCollectorWrapper hcw       = new HitCollectorWrapper(collector);
                hcw.SetNextReader(reader, 0);
                if (filter == null)
                {
                    Scorer scorer = weight.Scorer(reader, true, true);
                    if (scorer != null)
                    {
                        scorer.Score(hcw);
                    }
                }
                else
                {
                    SearchWithFilter(reader, weight, filter, hcw);
                }
                return((TopFieldDocs)collector.TopDocs());
            }

            TopFieldCollector collector2 = TopFieldCollector.create(sort, nDocs, fillFields, fieldSortDoTrackScores, fieldSortDoMaxScore, !weight.ScoresDocsOutOfOrder());

            Search(weight, filter, collector2);
            return((TopFieldDocs)collector2.TopDocs());
        }
Esempio n. 2
0
            public override void  Collect(int doc)
            {
                ++totalHits;
                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 = totalHits - 1;
                    // Copy hit into queue
                    comparator.Copy(slot, doc);
                    Add(slot, doc, score);
                    if (queueFull)
                    {
                        comparator.SetBottom(bottom.slot);
                    }
                }
            }
Esempio n. 3
0
            public override float Score()
            {
                int doc = DocID();

                if (doc >= lastScoredDoc)
                {
                    if (doc > lastScoredDoc)
                    {
                        lastDocScore  = scorer.Score();
                        lastScoredDoc = doc;
                    }
                    Enclosing_Instance.coordinator.nrMatchers++;
                }
                return(lastDocScore);
            }
Esempio n. 4
0
        /// <summary>Returns the score of the current document matching the query.
        /// Initially invalid, until {@link #Next()} 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()
        {
            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);
        }
Esempio n. 5
0
            public override int CompareBottom(int doc)
            {
                float score = scorer.Score();

                return(bottom > score?-1:(bottom < score?1:0));
            }
Esempio n. 6
0
 /// <summary>Returns the score of the current document matching the query.
 /// Initially invalid, until {@link #Next()} is called the first time.
 /// </summary>
 /// <returns> The score of the required scorer.
 /// </returns>
 public override float Score()
 {
     return(reqScorer.Score());            // reqScorer may be null when next() or skipTo() already return false
 }
Esempio n. 7
0
            public override void  Collect(int doc)
            {
                ++totalHits;
                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 = totalHits - 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);
                        }
                    }
                }
            }
Esempio n. 8
0
 public override void  Collect(int doc)
 {
     collector.Collect(doc + base_Renamed, scorer.Score());
 }
 public /*protected internal*/ override bool Score(Collector collector, int max, int firstDocID)
 {
     return(scorer.Score(collector, max, firstDocID));
 }