예제 #1
0
        public override TopDocs Search(Weight weight, Filter filter, int nDocs, IState state)
        {
            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, state);
                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));
        }
예제 #2
0
        public override TopDocs Search(Weight weight, Filter filter, int nDocs)
        {
            HitQueue hq        = new HitQueue(nDocs);
            int      totalHits = 0;

            for (int i = 0; i < searchables.Length; i++)
            {
                // search each searcher
                TopDocs docs = searchables[i].Search(weight, filter, nDocs);
                totalHits += docs.totalHits;                 // update totalHits
                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();
            }

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

            return(new TopDocs(totalHits, scoreDocs2, maxScore));
        }
예제 #3
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();

            TopDocs[] results = new TopDocs[searchables.Length];
            //search each searchable
            Parallel.For(0, searchables.Length, (i) => results[i] = MultiSearcherCallableNoSort(ThreadLock.MonitorLock, lockObj, searchables[i], weight, filter,
                                                                                                nDocs, hq, i, starts));
            int   totalHits = 0;
            float maxScore  = float.NegativeInfinity;

            foreach (TopDocs topDocs in results)
            {
                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));
        }
예제 #4
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, IState state)
        {
            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, state));
            }

            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));
        }
예제 #5
0
        // inherit javadoc
        public override TopDocs Search(Weight weight, Filter filter, int nDocs)
        {
            if (nDocs <= 0)
            {
                // null might be returned from hq.top() below.
                throw new System.ArgumentException("nDocs must be > 0");
            }

            Scorer scorer = weight.Scorer(reader);

            if (scorer == null)
            {
                return(new TopDocs(0, new ScoreDoc[0], System.Single.NegativeInfinity));
            }

            System.Collections.BitArray bits = filter != null?filter.Bits(reader) : null;

            HitQueue hq = new HitQueue(nDocs);

            int[] totalHits = new int[1];
            scorer.Score(new AnonymousClassHitCollector(bits, totalHits, hq, nDocs, this));

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

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

            return(new TopDocs(totalHits[0], scoreDocs, maxScore));
        }
예제 #6
0
 public SearcherCallableNoSort(ReentrantLock @lock, IndexSearcher searcher, LeafSlice slice, Weight weight, ScoreDoc after, int nDocs, HitQueue hq)
 {
     this.@lock    = @lock;
     this.Searcher = searcher;
     this.Weight   = weight;
     this.After    = after;
     this.NDocs    = nDocs;
     this.Hq       = hq;
     this.Slice    = slice;
 }
        /// <summary> A search implementation which spans a new thread for each
        /// Searchable, 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);
            int      totalHits = 0;

            MultiSearcherThread[] msta = new MultiSearcherThread[searchables.Length];
            for (int i = 0; i < searchables.Length; i++)
            {
                // search each searchable
                // Assume not too many searchables and cost of creating a thread is by far inferior to a search
                msta[i] = new MultiSearcherThread(searchables[i], weight, filter, nDocs, hq, i, starts, "MultiSearcher thread #" + (i + 1));
                msta[i].Start();
            }

            for (int i = 0; i < searchables.Length; i++)
            {
                try
                {
                    msta[i].Join();
                }
                catch (System.Threading.ThreadInterruptedException ie)
                {
                    // In 3.0 we will change this to throw
                    // InterruptedException instead
                    SupportClass.ThreadClass.Current().Interrupt();
                    throw new System.SystemException(ie.Message, ie);
                }
                System.IO.IOException ioe = msta[i].GetIOException();
                if (ioe == null)
                {
                    totalHits += msta[i].Hits();
                }
                else
                {
                    // if one search produced an IOException, rethrow it
                    throw ioe;
                }
            }

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

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

            return(new TopDocs(totalHits, scoreDocs, maxScore));
        }
예제 #8
0
        /// <summary>
        /// Expert: Low-level search implementation.  Finds the top <code>n</code>
        /// hits for <code>query</code>, applying <code>filter</code> if non-null.
        ///
        /// <p>Applications should usually call <seealso cref="IndexSearcher#search(Query,int)"/> or
        /// <seealso cref="IndexSearcher#search(Query,Filter,int)"/> instead. </summary>
        /// <exception cref="BooleanQuery.TooManyClauses"> If a query would exceed
        ///         <seealso cref="BooleanQuery#getMaxClauseCount()"/> clauses. </exception>
        protected internal virtual TopDocs Search(Weight weight, ScoreDoc after, int nDocs)
        {
            int limit = Reader.MaxDoc;

            if (limit == 0)
            {
                limit = 1;
            }
            if (after != null && after.Doc >= limit)
            {
                throw new System.ArgumentException("after.doc exceeds the number of documents in the reader: after.doc=" + after.Doc + " limit=" + limit);
            }
            nDocs = Math.Min(nDocs, limit);

            if (Executor == null)
            {
                return(Search(LeafContexts, weight, after, nDocs));
            }
            else
            {
                HitQueue                  hq     = new HitQueue(nDocs, false);
                ReentrantLock             @lock  = new ReentrantLock();
                ExecutionHelper <TopDocs> runner = new ExecutionHelper <TopDocs>(Executor);

                for (int i = 0; i < LeafSlices.Length; i++) // search each sub
                {
                    runner.Submit(new SearcherCallableNoSort(@lock, this, LeafSlices[i], weight, after, nDocs, hq));
                }

                int   totalHits = 0;
                float maxScore  = float.NegativeInfinity;
                foreach (TopDocs topDocs in runner)
                {
                    if (topDocs.TotalHits != 0)
                    {
                        totalHits += topDocs.TotalHits;
                        maxScore   = Math.Max(maxScore, topDocs.MaxScore);
                    }
                }

                var 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));
            }
        }
        /// <summary> A search implementation which spans a new thread for each
        /// Searchable, 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);
            int totalHits = 0;
            MultiSearcherThread[] msta = new MultiSearcherThread[searchables.Length];
            for (int i = 0; i < searchables.Length; i++)
            {
                // search each searchable
                // Assume not too many searchables and cost of creating a thread is by far inferior to a search
                msta[i] = new MultiSearcherThread(searchables[i], weight, filter, nDocs, hq, i, starts, "MultiSearcher thread #" + (i + 1));
                msta[i].Start();
            }

            for (int i = 0; i < searchables.Length; i++)
            {
                try
                {
                    msta[i].Join();
                }
                catch (System.Threading.ThreadInterruptedException ie)
                {
                    // In 3.0 we will change this to throw
                    // InterruptedException instead
                    SupportClass.ThreadClass.Current().Interrupt();
                    throw new System.SystemException(ie.Message, ie);
                }
                System.IO.IOException ioe = msta[i].GetIOException();
                if (ioe == null)
                {
                    totalHits += msta[i].Hits();
                }
                else
                {
                    // if one search produced an IOException, rethrow it
                    throw ioe;
                }
            }

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

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

            return new TopDocs(totalHits, scoreDocs, maxScore);
        }
예제 #10
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();

            TopDocs[] results = new TopDocs[searchables.Length];
            //search each searchable
            Parallel.For(0, searchables.Length, (i) => results[i] = MultiSearcherCallableNoSort(ThreadLock.MonitorLock, lockObj, searchables[i], weight, filter,
                                                                            nDocs, hq, i, starts));
            int totalHits = 0;
            float maxScore = float.NegativeInfinity;

            foreach (TopDocs topDocs in results)
            {
                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);
        }
예제 #11
0
파일: MultiSearcher.cs 프로젝트: sinsay/SSE
        public override TopDocs Search(Weight weight, Filter filter, int nDocs)
        {
            HitQueue hq = new HitQueue(nDocs, false);
            int totalHits = 0;

            for (int i = 0; i < searchables.Length; i++)
            {
                // search each searcher
                TopDocs docs = searchables[i].Search(weight, filter, nDocs);
                totalHits += docs.TotalHits; // update totalHits
                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();

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

            return new TopDocs(totalHits, scoreDocs2, maxScore);
        }
 public MultiSearcherThread(Lucene.Net.Search.Searchable searchable, Weight weight, Filter filter, int nDocs, HitQueue hq, int i, int[] starts, System.String name) : base(name)
 {
     this.searchable = searchable;
     this.weight     = weight;
     this.filter     = filter;
     this.nDocs      = nDocs;
     this.hq         = hq;
     this.i          = i;
     this.starts     = starts;
 }
예제 #13
0
		// inherit javadoc
		public override TopDocs Search(Weight weight, Filter filter, int nDocs)
		{
			
			if (nDocs <= 0)
			    // null might be returned from hq.top() below.
				throw new System.ArgumentException("nDocs must be > 0");
			
			Scorer scorer = weight.Scorer(reader);
			if (scorer == null)
				return new TopDocs(0, new ScoreDoc[0], System.Single.NegativeInfinity);
			
			System.Collections.BitArray bits = filter != null?filter.Bits(reader):null;
			HitQueue hq = new HitQueue(nDocs);
			int[] totalHits = new int[1];
			scorer.Score(new AnonymousClassHitCollector(bits, totalHits, hq, nDocs, this));
			
			ScoreDoc[] scoreDocs = new ScoreDoc[hq.Size()];
			for (int i = hq.Size() - 1; i >= 0; i--)
			    // put docs in array
				scoreDocs[i] = (ScoreDoc) hq.Pop();
			
			float maxScore = (totalHits[0] == 0) ? System.Single.NegativeInfinity : scoreDocs[0].score;
			
			return new TopDocs(totalHits[0], scoreDocs, maxScore);
		}
 public MultiSearcherThread(Searchable searchable, Weight weight, Filter filter, int nDocs, HitQueue hq, int i, int[] starts, System.String name)
     : base(name)
 {
     this.searchable = searchable;
     this.weight = weight;
     this.filter = filter;
     this.nDocs = nDocs;
     this.hq = hq;
     this.i = i;
     this.starts = starts;
 }
예제 #15
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);
        }
		/// <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);
		}