예제 #1
0
        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));
        }
예제 #2
0
        /// <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));
        }
예제 #3
0
		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);
		}
예제 #4
0
 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;
 }
예제 #5
0
		/// <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);
		}
예제 #6
0
		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;
		}