Beispiel #1
0
        public override TopDocs Search(Weight weight, Filter filter, int nDocs)
        {
            HitQueue hq        = new HitQueue(nDocs, false);
            int      totalHits = 0;

            var lockObj = new object();

            for (int i = 0; i < searchables.Length; i++)
            {
                // search each searcher
                // use NullLock, we don't care about synchronization for these
                TopDocs docs = MultiSearcherCallableNoSort(ThreadLock.NullLock, lockObj, searchables[i], weight, filter, nDocs, hq, i, starts);
                totalHits += docs.TotalHits;                 // update totalHits
            }

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

            float maxScore = (totalHits == 0)?System.Single.NegativeInfinity:scoreDocs2[0].Score;

            return(new TopDocs(totalHits, scoreDocs2, maxScore));
        }
Beispiel #2
0
        /// <summary> A search implementation which executes each
        /// <see cref="Searchable"/> in its own thread and waits for each search to complete
        /// and merge the results back together.
        /// </summary>
        public override TopDocs Search(Weight weight, Filter filter, int nDocs)
        {
            HitQueue hq      = new HitQueue(nDocs, false);
            object   lockObj = new object();

            Task <TopDocs>[] tasks = new Task <TopDocs> [searchables.Length];
            //search each searchable
            for (int i = 0; i < searchables.Length; i++)
            {
                int cur = i;
                tasks[i] =
                    Task.Factory.StartNew(() => MultiSearcherCallableNoSort(ThreadLock.MonitorLock, lockObj, searchables[cur], weight, filter,
                                                                            nDocs, hq, cur, starts));
            }

            int   totalHits = 0;
            float maxScore  = float.NegativeInfinity;


            Task.WaitAll(tasks);
            foreach (TopDocs topDocs in tasks.Select(x => x.Result))
            {
                totalHits += topDocs.TotalHits;
                maxScore   = Math.Max(maxScore, topDocs.MaxScore);
            }

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

            return(new TopDocs(totalHits, scoreDocs, maxScore));
        }