Пример #1
0
		public virtual int Compare(ScoreDoc i, ScoreDoc j)
		{
			if (i.doc < j.doc)
				return - 1;
			if (i.doc > j.doc)
				return 1;
			return 0;
		}
Пример #2
0
		public virtual int Compare(ScoreDoc i, ScoreDoc j)
		{
			if (i.score > j.score)
				return - 1;
			if (i.score < j.score)
				return 1;
			return 0;
		}
			public int Compare(ScoreDoc i, ScoreDoc j)
			{
				float fi = fieldOrder[i.doc];
				float fj = fieldOrder[j.doc];
				if (fi < fj)
					return - 1;
				if (fi > fj)
					return 1;
				return 0;
			}
Пример #4
0
        /// <summary> A search implementation allowing sorting which spans a new thread for each
        /// Searchable, waits for each search to complete and merges
        /// the results back together.
        /// </summary>
        public override TopFieldDocs Search(Query query, Filter filter, int nDocs, Sort sort)
        {
            // don't specify the fields - we'll wait to do this until we get results
            FieldDocSortedHitQueue hq = new FieldDocSortedHitQueue(null, nDocs);
            int totalHits             = 0;

            MultiSearcherThread[] msta = new MultiSearcherThread[searchables.Length];
            for (int i = 0; i < searchables.Length; i++)
            {
                // search each searcher
                // Assume not too many searchables and cost of creating a thread is by far inferior to a search
                msta[i] = new MultiSearcherThread(searchables[i], query, filter, nDocs, hq, sort, 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)
                {
                    ;                     // TODO: what should we do with this???
                }
                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();
            }

            return(new TopFieldDocs(totalHits, scoreDocs, hq.GetFields()));
        }
 override public void  Run()
 {
     try
     {
         docs = (sort == null)?searchable.Search(query, filter, nDocs):searchable.Search(query, filter, nDocs, sort);
     }
     // Store the IOException for later use by the caller of this thread
     catch (System.IO.IOException ioe)
     {
         this.ioe = ioe;
     }
     if (this.ioe == null)
     {
         // if we are sorting by fields, we need to tell the Field sorted hit queue
         // the actual type of fields, in case the original list contained AUTO.
         // if the searchable returns null for fields, we'll have problems.
         if (sort != null)
         {
             ((FieldDocSortedHitQueue)hq).SetFields(((TopFieldDocs)docs).fields);
         }
         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
             //it would be so nice if we had a thread-safe insert
             lock (hq)
             {
                 if (!hq.Insert(scoreDoc))
                 {
                     break;
                 }
             } // no more scores > minScore
         }
     }
 }
Пример #6
0
        public override TopFieldDocs Search(Query query, Filter filter, int n, Sort sort)
        {
            FieldDocSortedHitQueue hq = null;
            int totalHits             = 0;

            for (int i = 0; i < searchables.Length; i++)
            {
                // search each searcher
                TopFieldDocs docs = searchables[i].Search(query, filter, n, sort);
                if (hq == null)
                {
                    hq = new FieldDocSortedHitQueue(docs.fields, n);
                }
                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();
            }

            return(new TopFieldDocs(totalHits, scoreDocs2, hq.GetFields()));
        }
Пример #7
0
		/// <summary>Expert: Constructs a TopDocs.</summary>
		internal TopDocs(int totalHits, ScoreDoc[] scoreDocs)
		{
			this.totalHits = totalHits;
			this.scoreDocs = scoreDocs;
		}
			public virtual int Compare(ScoreDoc i, ScoreDoc j)
			{
				return cachedValues[i.doc].CompareTo(cachedValues[j.doc]);
			}
Пример #9
0
 public virtual System.IComparable SortValue(ScoreDoc i)
 {
     return(index[i.doc]);
 }
Пример #10
0
 public virtual System.IComparable SortValue(ScoreDoc i)
 {
     return(index.lookup[index.order[i.doc]]);
 }
Пример #11
0
 public virtual System.IComparable SortValue(ScoreDoc i)
 {
     return((float)i.score);
 }
Пример #12
0
 public virtual int Compare(ScoreDoc i, ScoreDoc j)
 {
     return(cachedValues[i.doc].CompareTo(cachedValues[j.doc]));
 }
Пример #13
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(Query query, Filter filter, int nDocs)
		{
			HitQueue hq = new HitQueue(nDocs);
			int totalHits = 0;
			MultiSearcherThread[] msta = new MultiSearcherThread[searchables.Length];
			for (int i = 0; i < searchables.Length; i++)
			{
				// search each searcher
				// Assume not too many searchables and cost of creating a thread is by far inferior to a search
				msta[i] = new MultiSearcherThread(searchables[i], query, 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)
				{
					; // TODO: what should we do with this???
				}
				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();
			
			return new TopDocs(totalHits, scoreDocs);
		}
Пример #14
0
		public virtual System.IComparable SortValue(ScoreDoc i)
		{
			return (System.Int32) i.doc;
		}
Пример #15
0
		public virtual System.IComparable SortValue(ScoreDoc i)
		{
			return (float) i.score;
		}
			public virtual System.IComparable SortValue(ScoreDoc i)
			{
				return (float) fieldOrder[i.doc];
			}
		// inherit javadoc
		public override TopFieldDocs Search(Query query, Filter filter, int nDocs, Sort sort)
		{
			Scorer scorer = query.Weight(this).Scorer(reader);
			if (scorer == null)
				return new TopFieldDocs(0, new ScoreDoc[0], sort.fields);
			
			System.Collections.BitArray bits = filter != null ? filter.Bits(reader) : null;
			FieldSortedHitQueue hq = new FieldSortedHitQueue(reader, sort.fields, nDocs);
			int[] totalHits = new int[1];
			scorer.Score(new AnonymousClassHitCollector1(bits, totalHits, hq, this));
			
			ScoreDoc[] scoreDocs = new ScoreDoc[hq.Size()];
			for (int i = hq.Size() - 1; i >= 0; i--)
			// put docs in array
				scoreDocs[i] = hq.FillFields((FieldDoc) hq.Pop());
			
			return new TopFieldDocs(totalHits[0], scoreDocs, hq.GetFields());
		}
Пример #18
0
 public virtual System.IComparable SortValue(ScoreDoc i)
 {
     return(cachedValues[i.doc]);
 }
Пример #19
0
 public virtual System.IComparable SortValue(ScoreDoc i)
 {
     return((System.Int32)i.doc);
 }
Пример #20
0
		public override TopFieldDocs Search(Query query, Filter filter, int n, Sort sort)
		{
			FieldDocSortedHitQueue hq = null;
			int totalHits = 0;
			
			for (int i = 0; i < searchables.Length; i++)
			{
				// search each searcher
				TopFieldDocs docs = searchables[i].Search(query, filter, n, sort);
				if (hq == null)
					hq = new FieldDocSortedHitQueue(docs.fields, n);
				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();
			
			return new TopFieldDocs(totalHits, scoreDocs2, hq.GetFields());
		}
Пример #21
0
		/// <summary>Creates one of these objects.</summary>
		/// <param name="totalHits"> Total number of hits for the query.
		/// </param>
		/// <param name="scoreDocs"> The top hits for the query.
		/// </param>
		/// <param name="fields">    The sort criteria used to find the top hits.
		/// </param>
		internal TopFieldDocs(int totalHits, ScoreDoc[] scoreDocs, SortField[] fields):base(totalHits, scoreDocs)
		{
			this.fields = fields;
		}
			public int Compare(ScoreDoc i, ScoreDoc j)
			{
				int fi = index.order[i.doc];
				int fj = index.order[j.doc];
				if (fi < fj)
					return - 1;
				if (fi > fj)
					return 1;
				return 0;
			}
Пример #23
0
 public int Compare(ScoreDoc i, ScoreDoc j)
 {
     return(collator.Compare(index[i.doc].ToString(), index[j.doc].ToString()));
 }
			public virtual System.IComparable SortValue(ScoreDoc i)
			{
				return index.lookup[index.order[i.doc]];
			}
Пример #25
0
 public virtual System.IComparable SortValue(ScoreDoc i)
 {
     return((System.Int32)fieldOrder[i.doc]);
 }
			public int Compare(ScoreDoc i, ScoreDoc j)
			{
				return collator.Compare(index[i.doc].ToString(), index[j.doc].ToString());
			}
			public virtual System.IComparable SortValue(ScoreDoc i)
			{
				return cachedValues[i.doc];
			}
			public virtual System.IComparable SortValue(ScoreDoc i)
			{
				return index[i.doc];
			}