Ejemplo n.º 1
0
        public override TopFieldDocs Search(Weight weight, Filter filter, int n, Sort sort)
        {
            FieldDocSortedHitQueue hq = null;
            int totalHits             = 0;

            float maxScore = System.Single.NegativeInfinity;

            for (int i = 0; i < searchables.Length; i++)
            {
                // search each searcher
                TopFieldDocs docs = searchables[i].Search(weight, filter, n, sort);
                // If one of the Sort fields is FIELD_DOC, need to fix its values, so that
                // it will break ties by doc Id properly. Otherwise, it will compare to
                // 'relative' doc Ids, that belong to two different searchers.
                for (int j = 0; j < docs.fields.Length; j++)
                {
                    if (docs.fields[j].GetType() == SortField.DOC)
                    {
                        // iterate over the score docs and change their fields value
                        for (int j2 = 0; j2 < docs.scoreDocs.Length; j2++)
                        {
                            FieldDoc fd = (FieldDoc)docs.scoreDocs[j2];
                            fd.fields[j] = (System.Int32)(((System.Int32)fd.fields[j]) + starts[i]);
                        }
                        break;
                    }
                }
                if (hq == null)
                {
                    hq = new FieldDocSortedHitQueue(docs.fields, n);
                }
                totalHits += docs.totalHits;                 // update totalHits
                maxScore   = System.Math.Max(maxScore, docs.GetMaxScore());
                ScoreDoc[] scoreDocs = docs.scoreDocs;
                for (int j = 0; j < scoreDocs.Length; j++)
                {
                    // merge scoreDocs into hq
                    ScoreDoc scoreDoc = scoreDocs[j];
                    scoreDoc.doc += starts[i];                     // convert doc
                    if (!hq.Insert(scoreDoc))
                    {
                        break;                         // no more scores > minScore
                    }
                }
            }

            ScoreDoc[] scoreDocs2 = new ScoreDoc[hq.Size()];
            for (int i = hq.Size() - 1; i >= 0; i--)
            {
                // put docs in array
                scoreDocs2[i] = (ScoreDoc)hq.Pop();
            }

            return(new TopFieldDocs(totalHits, scoreDocs2, hq.GetFields(), maxScore));
        }
Ejemplo n.º 2
0
        public override TopFieldDocs Search(Weight weight, Filter filter, int n, Sort sort)
        {
            FieldDocSortedHitQueue hq = null;
            int totalHits             = 0;

            float maxScore = System.Single.NegativeInfinity;

            for (int i = 0; i < searchables.Length; i++)
            {
                // search each searcher
                TopFieldDocs docs = searchables[i].Search(weight, filter, n, sort);

                if (hq == null)
                {
                    hq = new FieldDocSortedHitQueue(docs.fields, n);
                }
                totalHits += docs.totalHits;                 // update totalHits
                maxScore   = System.Math.Max(maxScore, docs.GetMaxScore());
                ScoreDoc[] scoreDocs = docs.scoreDocs;
                for (int j = 0; j < scoreDocs.Length; j++)
                {
                    // merge scoreDocs into hq
                    ScoreDoc scoreDoc = scoreDocs[j];
                    scoreDoc.doc += starts[i];                     // convert doc
                    if (!hq.Insert(scoreDoc))
                    {
                        break;                         // no more scores > minScore
                    }
                }
            }

            ScoreDoc[] scoreDocs2 = new ScoreDoc[hq.Size()];
            for (int i = hq.Size() - 1; i >= 0; i--)
            {
                // put docs in array
                scoreDocs2[i] = (ScoreDoc)hq.Pop();
            }

            return(new TopFieldDocs(totalHits, scoreDocs2, hq.GetFields(), maxScore));
        }