Expert: Collectors are primarily meant to be used to gather raw results from a search, and implement sorting or custom result filtering, collation, etc.

Lucene's core collectors are derived from Collector. Likely your application can use one of these classes, or subclass TopDocsCollector, instead of implementing Collector directly: TopDocsCollector is an abstract base class that assumes you will retrieve the top N docs, according to some criteria, after collection is done. TopScoreDocCollector is a concrete subclass TopDocsCollector and sorts according to score + docID. This is used internally by the IndexSearcher search methods that do not take an explicit Sort. It is likely the most frequently used collector. TopFieldCollector subclasses TopDocsCollector and sorts according to a specified Sort object (sort by field). This is used internally by the IndexSearcher search methods that take an explicit Sort. TimeLimitingCollector, which wraps any other Collector and aborts the search if it's taken too much time. PositiveScoresOnlyCollector wraps any other Collector and prevents collection of hits whose score is <= 0.0

Collector decouples the score from the collected doc: the score computation is skipped entirely if it's not needed. Collectors that do need the score should implement the SetScorer method, to hold onto the passed Scorer instance, and call Scorer.Score() within the collect method to compute the current hit's score. If your collector may request the score for a single hit multiple times, you should use ScoreCachingWrappingScorer.

NOTE: The doc that is passed to the collect method is relative to the current reader. If your collector needs to resolve this to the docID space of the Multi*Reader, you must re-base it by recording the docBase from the most recent setNextReader call. Here's a simple example showing how to collect docIDs into a BitSet:

Searcher searcher = new IndexSearcher(indexReader); final BitSet bits = new BitSet(indexReader.MaxDoc); searcher.search(query, new Collector() { private int docBase; // ignore scorer public void setScorer(Scorer scorer) { } // accept docs out of order (for a BitSet it doesn't matter) public boolean acceptsDocsOutOfOrder() { return true; } public void collect(int doc) { bits.set(doc + docBase); } public void setNextReader(IndexReader reader, int docBase) { this.docBase = docBase; } });

Not all collectors will need to rebase the docID. For example, a collector that simply counts the total number of hits would skip it.

NOTE: Prior to 2.9, Lucene silently filtered out hits with score <= 0. As of 2.9, the core Collectors no longer do that. It's very unusual to have such hits (a negative query boost, or function query returning negative custom scores, could cause it to happen). If you need that behavior, use PositiveScoresOnlyCollector .

NOTE: This API is experimental and might change in incompatible ways in the next release.

		// firstDocID is ignored since nextDoc() sets 'doc'
		public /*protected internal*/ override bool Score(Collector c, int end, int firstDocID)
		{
			c.SetScorer(this);
			while (doc < end)
			{
				// for docs in window
				c.Collect(doc); // collect score
				
				if (++pointer >= pointerMax)
				{
					pointerMax = termDocs.Read(docs, freqs); // refill buffers
					if (pointerMax != 0)
					{
						pointer = 0;
					}
					else
					{
						termDocs.Close(); // close stream
						doc = System.Int32.MaxValue; // set to sentinel value
						return false;
					}
				}
				doc = docs[pointer];
			}
			return true;
		}
        private void SearchWithFilter(IndexReader reader, Weight weight, Filter filter, Collector collector)
        {
            DocIdSet docIdSet = filter.GetDocIdSet(reader);
            if (docIdSet == null)
                return;
            Scorer scorer = weight.Scorer(reader, true, false);
            if (scorer == null)
                return;
            scorer.DocID();

            DocIdSetIterator docIdSetIterator = docIdSet.Iterator();
            if (docIdSetIterator == null)
                return;
            int target = docIdSetIterator.NextDoc();
            int num = scorer.Advance(target);
            collector.SetScorer(scorer);
            while (true)
            {
                while (num != target)
                {
                    if (num > target)
                        target = docIdSetIterator.Advance(num);
                    else
                        num = scorer.Advance(target);
                }
                if (num != DocIdSetIterator.NO_MORE_DOCS && !((GroupCollector)collector).GroupLimitReached)
                {
                    collector.Collect(num);
                    target = docIdSetIterator.NextDoc();
                    num = scorer.Advance(target);
                }
                else
                    break;
            }
        }
Esempio n. 3
0
 internal AssertingCollector(Random random, Collector @in, bool inOrder)
 {
     this.Random = random;
     this.@in = @in;
     this.InOrder = inOrder;
     LastCollected = -1;
 }
Esempio n. 4
0
 /// <summary> Create a TimeLimitedCollector wrapper over another <see cref="Collector" /> with a specified timeout.</summary>
 /// <param name="collector">the wrapped <see cref="Collector" />
 /// </param>
 /// <param name="timeAllowed">max time allowed for collecting hits after which <see cref="TimeExceededException" /> is thrown
 /// </param>
 public TimeLimitingCollector(Collector collector, long timeAllowed)
 {
     InitBlock();
     this.collector = collector;
     t0 = TIMER_THREAD.GetMilliseconds();
     this.timeout = t0 + timeAllowed;
 }
 public override bool Score(Collector collector, int max)
 {
     RandomOrderCollector randomCollector = new RandomOrderCollector(Random, collector);
     bool remaining = @in.Score(randomCollector, max);
     randomCollector.Flush();
     return remaining;
 }
Esempio n. 6
0
		/// <summary>Scores and collects all matching documents.</summary>
		/// <param name="collector">The collector to which all matching documents are passed.
		/// <br/>When this method is used the {@link #Explain(int)} method should not be used.
		/// </param>
		public virtual void  Score(Collector collector)
		{
			collector.SetScorer(this);
			int doc;
			while ((doc = NextDoc()) != NO_MORE_DOCS)
			{
				collector.Collect(doc);
			}
		}
 internal RandomOrderCollector(Random random, Collector @in)
 {
     if ([email protected]())
     {
         throw new System.ArgumentException();
     }
     this.@in = @in;
     this.Random = random;
     BufferSize = 1 + random.Next(100);
     DocIDs = new int[BufferSize];
     Scores = new float[BufferSize];
     Freqs = new int[BufferSize];
     Buffered = 0;
 }
Esempio n. 8
0
        // Prevent extension from non-internal classes
        private CachingCollector(Collector other, double maxRAMMB, bool cacheScores)
        {
            this.Other = other;

            CachedDocs = new List<int[]>();
            CurDocs = new int[INITIAL_ARRAY_SIZE];
            CachedDocs.Add(CurDocs);

            int bytesPerDoc = RamUsageEstimator.NUM_BYTES_INT;
            if (cacheScores)
            {
                bytesPerDoc += RamUsageEstimator.NUM_BYTES_FLOAT;
            }
            MaxDocsToCache = (int)((maxRAMMB * 1024 * 1024) / bytesPerDoc);
        }
 public override void Score(Collector collector)
 {
     if (Random.NextBoolean())
     {
         try
         {
             bool remaining = @in.Score(collector, DocsEnum.NO_MORE_DOCS);
             Debug.Assert(!remaining);
         }
         catch (System.NotSupportedException e)
         {
             @in.Score(collector);
         }
     }
     else
     {
         @in.Score(collector);
     }
 }
 public override void Search(Weight weight, Filter filter, Collector collector)
 {
     if (filter == null)
     {
         for (int index = 0; index < this.subReaders.Length; ++index)
         {
             collector.SetNextReader(this.subReaders[index], this.docStarts[index]);
             Scorer scorer = weight.Scorer(this.subReaders[index], !collector.AcceptsDocsOutOfOrder, true);
             if (scorer != null)
                 this.SearchWithScorer(this.subReaders[index], weight, scorer, collector);
         }
     }
     else
     {
         for (int index = 0; index < this.subReaders.Length; ++index)
         {
             collector.SetNextReader(this.subReaders[index], this.docStarts[index]);
             this.SearchWithFilter(this.subReaders[index], weight, filter, collector);
         }
     }
 }
Esempio n. 11
0
			public SubScorer(Scorer scorer, bool required, bool prohibited, Collector collector, SubScorer next)
			{
				this.scorer = scorer;
				this.required = required;
				this.prohibited = prohibited;
				this.collector = collector;
				this.next = next;
			}
 /// <summary>
 /// Searches for documents mapped from the given type using the specified query and Collector.
 /// </summary>
 /// <param name="searcher">
 /// The Searcher to search on.
 /// </param>
 /// <param name="type">
 /// The type of the object to search documents for.
 /// </param>
 /// <param name="query">
 /// The Query which selects the documents.
 /// </param>
 /// <param name="results">
 /// The Collector to use to gather results.
 /// </param>
 public static void Search(this Searcher searcher, Type type, Query query, Collector results)
 {
     searcher.Search(query, ObjectMapping.GetTypeFilter(type), results);
 }
Esempio n. 13
0
        private void  SearchWithFilter(IndexReader reader, Weight weight, Filter filter, Collector collector, IState state)
        {
            System.Diagnostics.Debug.Assert(filter != null);

            Scorer scorer = weight.Scorer(reader, true, false, state);

            if (scorer == null)
            {
                return;
            }

            int docID = scorer.DocID();

            System.Diagnostics.Debug.Assert(docID == -1 || docID == DocIdSetIterator.NO_MORE_DOCS);

            // CHECKME: use ConjunctionScorer here?
            DocIdSet filterDocIdSet = filter.GetDocIdSet(reader, state);

            if (filterDocIdSet == null)
            {
                // this means the filter does not accept any documents.
                return;
            }

            DocIdSetIterator filterIter = filterDocIdSet.Iterator(state);

            if (filterIter == null)
            {
                // this means the filter does not accept any documents.
                return;
            }
            int filterDoc = filterIter.NextDoc(state);
            int scorerDoc = scorer.Advance(filterDoc, state);

            collector.SetScorer(scorer);
            while (true)
            {
                if (scorerDoc == filterDoc)
                {
                    // Check if scorer has exhausted, only before collecting.
                    if (scorerDoc == DocIdSetIterator.NO_MORE_DOCS)
                    {
                        break;
                    }
                    collector.Collect(scorerDoc, state);
                    filterDoc = filterIter.NextDoc(state);
                    scorerDoc = scorer.Advance(filterDoc, state);
                }
                else if (scorerDoc > filterDoc)
                {
                    filterDoc = filterIter.Advance(scorerDoc, state);
                }
                else
                {
                    scorerDoc = scorer.Advance(filterDoc, state);
                }
            }
        }
Esempio n. 14
0
 /// <summary>Lower-level search API.
 ///
 /// <p/><see cref="Collector.Collect(int)" /> is called for every matching
 /// document.
 /// <br/>Collector-based access to remote indexes is discouraged.
 ///
 /// <p/>Applications should only use this if they need <i>all</i> of the
 /// matching documents.  The high-level search API (<see cref="Searcher.Search(Query, Filter, int)" />)
 /// is usually more efficient, as it skips
 /// non-high-scoring hits.
 ///
 /// </summary>
 /// <param name="query">to match documents
 /// </param>
 /// <param name="filter">if non-null, used to permit documents to be collected.
 /// </param>
 /// <param name="results">to receive hits
 /// </param>
 /// <throws>  BooleanQuery.TooManyClauses </throws>
 public virtual void  Search(Query query, Filter filter, Collector results)
 {
     Search(CreateWeight(query), filter, results);
 }
Esempio n. 15
0
		/// <summary>Lower-level search API.
		/// 
		/// <p/><see cref="Collector.Collect(int)" /> is called for every matching
		/// document.
		/// <br/>Collector-based access to remote indexes is discouraged.
		/// 
		/// <p/>Applications should only use this if they need <i>all</i> of the
		/// matching documents.  The high-level search API (<see cref="Searcher.Search(Query, Filter, int)" />)
		/// is usually more efficient, as it skips
		/// non-high-scoring hits.
		/// 
		/// </summary>
		/// <param name="query">to match documents
		/// </param>
		/// <param name="filter">if non-null, used to permit documents to be collected.
		/// </param>
		/// <param name="results">to receive hits
		/// </param>
		/// <throws>  BooleanQuery.TooManyClauses </throws>
		public virtual void  Search(Query query, Filter filter, Collector results)
		{
			Search(CreateWeight(query), filter, results);
		}
Esempio n. 16
0
        // inherit javadoc
        public override void Search(Weight weight, Filter filter, Collector collector)
        {
            for (int i = 0; i < searchables.Length; i++)
            {

                int start = starts[i];

                Collector hc = new AnonymousClassCollector(collector, start, this);

                searchables[i].Search(weight, filter, hc);
            }
        }
Esempio n. 17
0
		/// <summary> Expert: Collects matching documents in a range. Hook for optimization.
		/// Note, <code>firstDocID</code> is added to ensure that {@link #NextDoc()}
		/// was called before this method.
		/// 
		/// </summary>
		/// <param name="collector">The collector to which all matching documents are passed.
		/// </param>
		/// <param name="max">Do not score documents past this.
		/// </param>
		/// <param name="firstDocID">
		/// The first document ID (ensures {@link #NextDoc()} is called before
		/// this method.
		/// </param>
		/// <returns> true if more matching documents may remain.
		/// </returns>
		public /*protected internal*/ virtual bool Score(Collector collector, int max, int firstDocID)
		{
			collector.SetScorer(this);
			int doc = firstDocID;
			while (doc < max)
			{
				collector.Collect(doc);
				doc = NextDoc();
			}
			return doc != NO_MORE_DOCS;
		}
Esempio n. 18
0
 public CountingCollector(Collector other)
     : this(other, new HashSet <string> {
     "MUST", "SHOULD", "MUST_NOT"
 })
 {
 }
Esempio n. 19
0
 protected internal override void Search(IList <AtomicReaderContext> leaves, Weight weight, Collector collector)
 {
     Assert.AreEqual(-1, collector.GetType().Name.IndexOf("OutOfOrder"));
     base.Search(leaves, weight, collector);
 }
Esempio n. 20
0
 public override void  Search(Query query, Collector results, IState state)
 {
     CheckExplanations(query);
     base.Search(query, results, null);
 }
Esempio n. 21
0
 public override void  Score(Collector c)
 {
     Score(c, System.Int32.MaxValue, NextDoc());
 }
Esempio n. 22
0
 /// <summary>
 /// Create a TimeLimitedCollector wrapper over another <seealso cref="Collector"/> with a specified timeout. </summary>
 /// <param name="collector"> the wrapped <seealso cref="Collector"/> </param>
 /// <param name="clock"> the timer clock </param>
 /// <param name="ticksAllowed"> max time allowed for collecting
 /// hits after which <seealso cref="TimeExceededException"/> is thrown </param>
 public TimeLimitingCollector(Collector collector, Counter clock, long ticksAllowed)
 {
     this.collector    = collector;
     this.Clock        = clock;
     this.TicksAllowed = ticksAllowed;
 }
Esempio n. 23
0
 public virtual void Search(Weight weight, Collector collector)
 {
     Search(Ctx, weight, collector);
 }
Esempio n. 24
0
		public override void  Score(Collector collector)
		{
			Score(collector, System.Int32.MaxValue, NextDoc());
		}
 public CountingCollector(Collector other, ISet<string> relationships)
 {
     this.Other = other;
     this.Relationships = relationships;
 }
Esempio n. 26
0
 public CountingCollector(Collector other, ISet <string> relationships)
 {
     this.Other         = other;
     this.Relationships = relationships;
 }
		/// <summary>Scores and collects all matching documents.</summary>
		/// <param name="collector">The collector to which all matching documents are passed through.
		/// <br/>When this method is used the <see cref="Explain(int)" /> method should not be used.
		/// </param>
		public override void  Score(Collector collector)
		{
			collector.SetScorer(this);
			while (NextDoc() != NO_MORE_DOCS)
			{
				collector.Collect(currentDoc);
			}
		}
Esempio n. 28
0
 protected override void Search(IList <AtomicReaderContext> leaves, Weight weight, Collector collector)
 {
     // TODO: shouldn't we AssertingCollector.wrap(collector) here?
     base.Search(leaves, AssertingWeight.Wrap(Random, weight), collector);
 }
Esempio n. 29
0
		public abstract void  Search(Weight weight, Filter filter, Collector results);
Esempio n. 30
0
 /// <summary>Lower-level search API.
 ///
 /// <p/><see cref="Collector.Collect(int)" /> is called for every matching document.
 ///
 /// <p/>Applications should only use this if they need <i>all</i> of the matching
 /// documents. The high-level search API (<see cref="Searcher.Search(Query, int)" />
 /// ) is usually more efficient, as it skips non-high-scoring hits.
 /// <p/>Note: The <c>score</c> passed to this method is a raw score.
 /// In other words, the score will not necessarily be a float whose value is
 /// between 0 and 1.
 /// </summary>
 /// <throws>  BooleanQuery.TooManyClauses </throws>
 public virtual void  Search(Query query, Collector results, IState state)
 {
     Search(CreateWeight(query, state), null, results, state);
 }
 public override void  Score(Collector collector)
 {
     scorer.Score(collector);
 }
Esempio n. 32
0
 /// <summary>Lower-level search API.
 ///
 /// <p/><see cref="Collector.Collect(int)" /> is called for every matching
 /// document.
 /// <br/>Collector-based access to remote indexes is discouraged.
 ///
 /// <p/>Applications should only use this if they need <i>all</i> of the
 /// matching documents.  The high-level search API (<see cref="Searcher.Search(Query, Filter, int)" />)
 /// is usually more efficient, as it skips
 /// non-high-scoring hits.
 ///
 /// </summary>
 /// <param name="query">to match documents
 /// </param>
 /// <param name="filter">if non-null, used to permit documents to be collected.
 /// </param>
 /// <param name="results">to receive hits
 /// </param>
 /// <throws>  BooleanQuery.TooManyClauses </throws>
 public virtual void  Search(Query query, Filter filter, Collector results, IState state)
 {
     Search(CreateWeight(query, state), filter, results, state);
 }
Esempio n. 33
0
 public override void  Search(Weight weight, Filter filter, Collector results)
 {
     throw new System.NotSupportedException();
 }
Esempio n. 34
0
 internal NoScoreCachingCollector(Collector other, double maxRAMMB)
     : base(other, maxRAMMB, false)
 {
 }
 private void  Search(Collector collector)
 {
     searcher.Search(query, collector);
 }
Esempio n. 36
0
 internal NoScoreCachingCollector(Collector other, int maxDocsToCache)
     : base(other, maxDocsToCache)
 {
 }
Esempio n. 37
0
 /// <summary>
 /// Create a new <seealso cref="CachingCollector"/> that wraps the given collector and
 /// caches documents and scores up to the specified RAM threshold.
 /// </summary>
 /// <param name="other">
 ///          the Collector to wrap and delegate calls to. </param>
 /// <param name="cacheScores">
 ///          whether to cache scores in addition to document IDs. Note that
 ///          this increases the RAM consumed per doc </param>
 /// <param name="maxRAMMB">
 ///          the maximum RAM in MB to consume for caching the documents and
 ///          scores. If the collector exceeds the threshold, no documents and
 ///          scores are cached. </param>
 public static CachingCollector Create(Collector other, bool cacheScores, double maxRAMMB)
 {
     return(cacheScores ? (CachingCollector) new ScoreCachingCollector(other, maxRAMMB) : new NoScoreCachingCollector(other, maxRAMMB));
 }
Esempio n. 38
0
 /// <summary>
 /// Create a new <seealso cref="CachingCollector"/> that wraps the given collector and
 /// caches documents and scores up to the specified max docs threshold.
 /// </summary>
 /// <param name="other">
 ///          the Collector to wrap and delegate calls to. </param>
 /// <param name="cacheScores">
 ///          whether to cache scores in addition to document IDs. Note that
 ///          this increases the RAM consumed per doc </param>
 /// <param name="maxDocsToCache">
 ///          the maximum number of documents for caching the documents and
 ///          possible the scores. If the collector exceeds the threshold,
 ///          no documents and scores are cached. </param>
 public static CachingCollector Create(Collector other, bool cacheScores, int maxDocsToCache)
 {
     return(cacheScores ? (CachingCollector) new ScoreCachingCollector(other, maxDocsToCache) : new NoScoreCachingCollector(other, maxDocsToCache));
 }
Esempio n. 39
0
		// firstDocID is ignored since nextDoc() initializes 'current'
		public /*protected internal*/ override bool Score(Collector collector, int max, int firstDocID)
		{
			bool more;
			Bucket tmp;
			BucketScorer bs = new BucketScorer();
			// The internal loop will set the score and doc before calling collect.
			collector.SetScorer(bs);
			do 
			{
				bucketTable.first = null;
				
				while (current != null)
				{
					// more queued 
					
					// check prohibited & required
					if ((current.bits & prohibitedMask) == 0 && (current.bits & requiredMask) == requiredMask)
					{
						
						if (current.doc >= max)
						{
							tmp = current;
							current = current.next;
							tmp.next = bucketTable.first;
							bucketTable.first = tmp;
							continue;
						}
						
						if (current.coord >= minNrShouldMatch)
						{
							bs.score = current.score * coordFactors[current.coord];
							bs.doc = current.doc;
							collector.Collect(current.doc);
						}
					}
					
					current = current.next; // pop the queue
				}
				
				if (bucketTable.first != null)
				{
					current = bucketTable.first;
					bucketTable.first = current.next;
					return true;
				}
				
				// refill the queue
				more = false;
				end += BucketTable.SIZE;
				for (SubScorer sub = scorers; sub != null; sub = sub.next)
				{
					int subScorerDocID = sub.scorer.DocID();
					if (subScorerDocID != NO_MORE_DOCS)
					{
						more |= sub.scorer.Score(sub.collector, end, subScorerDocID);
					}
				}
				current = bucketTable.first;
			}
			while (current != null || more);
			
			return false;
		}
Esempio n. 40
0
 /// <summary>
 /// Replays the cached doc IDs (and scores) to the given Collector. If this
 /// instance does not cache scores, then Scorer is not set on
 /// {@code other.setScorer} as well as scores are not replayed.
 /// </summary>
 /// <exception cref="InvalidOperationException">
 ///           if this collector is not cached (i.e., if the RAM limits were too
 ///           low for the number of documents + scores to cache). </exception>
 /// <exception cref="IllegalArgumentException">
 ///           if the given Collect's does not support out-of-order collection,
 ///           while the collector passed to the ctor does. </exception>
 public abstract void Replay(Collector other);
 public CountingCollector(Collector other)
     : this(other, new HashSet<string> { "MUST", "SHOULD", "MUST_NOT" })
 {
 }
Esempio n. 42
0
 public override void  Search(Query query, Filter filter, Collector results)
 {
     CheckExplanations(query);
     base.Search(query, filter, results);
 }
 public PositiveScoresOnlyCollector(Collector c)
 {
     this.c = c;
 }
Esempio n. 44
0
 public override bool Score(Collector collector, int max)
 {
     collector.Scorer = new FakeScorer();
     collector.Collect(0);
     return(false);
 }
Esempio n. 45
0
 public override void  Search(Query query, Filter filter, Collector results)
 {
     throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
 }
 public override void Score(Collector collector)
 {
     RandomOrderCollector randomCollector = new RandomOrderCollector(Random, collector);
     @in.Score(randomCollector);
     randomCollector.Flush();
 }
	    /// <summary>Expert: Collects matching documents in a range.  Hook for optimization.
	    /// Note that <see cref="Next()" /> must be called once before this method is called
	    /// for the first time.
	    /// </summary>
	    /// <param name="collector">The collector to which all matching documents are passed through.
	    /// </param>
	    /// <param name="max">Do not score documents past this.
	    /// </param>
	    /// <param name="firstDocID"></param>
	    /// <returns> true if more matching documents may remain.
	    /// </returns>
	    public /*protected internal*/ override bool Score(Collector collector, int max, int firstDocID)
		{
			// firstDocID is ignored since nextDoc() sets 'currentDoc'
			collector.SetScorer(this);
			while (currentDoc < max)
			{
				collector.Collect(currentDoc);
				if (NextDoc() == NO_MORE_DOCS)
				{
					return false;
				}
			}
			return true;
		}
Esempio n. 48
0
        private void SearchWithFilter(IndexReader reader, Weight weight, Filter filter, Collector collector)
        {
            System.Diagnostics.Debug.Assert(filter != null);

            Scorer scorer = weight.Scorer(reader, true, false);
            if (scorer == null)
            {
                return ;
            }

            int docID = scorer.DocID();
            System.Diagnostics.Debug.Assert(docID == - 1 || docID == DocIdSetIterator.NO_MORE_DOCS);

            // CHECKME: use ConjunctionScorer here?
            DocIdSet filterDocIdSet = filter.GetDocIdSet(reader);
            if (filterDocIdSet == null)
            {
                // this means the filter does not accept any documents.
                return ;
            }

            DocIdSetIterator filterIter = filterDocIdSet.Iterator();
            if (filterIter == null)
            {
                // this means the filter does not accept any documents.
                return ;
            }
            int filterDoc = filterIter.NextDoc();
            int scorerDoc = scorer.Advance(filterDoc);

            collector.SetScorer(scorer);
            while (true)
            {
                if (scorerDoc == filterDoc)
                {
                    // Check if scorer has exhausted, only before collecting.
                    if (scorerDoc == DocIdSetIterator.NO_MORE_DOCS)
                    {
                        break;
                    }
                    collector.Collect(scorerDoc);
                    filterDoc = filterIter.NextDoc();
                    scorerDoc = scorer.Advance(filterDoc);
                }
                else if (scorerDoc > filterDoc)
                {
                    filterDoc = filterIter.Advance(scorerDoc);
                }
                else
                {
                    scorerDoc = scorer.Advance(filterDoc);
                }
            }
        }
Esempio n. 49
0
 public override void Search(Weight weight, Filter filter, Collector results)
 {
     throw new System.NotSupportedException();
 }
Esempio n. 50
0
			public override void  Search(Query query, Filter filter, Collector results)
			{
				throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
			}
Esempio n. 51
0
		/// <summary>Lower-level search API.
		/// 
		/// <p/><see cref="Collector.Collect(int)" /> is called for every matching document.
		/// 
		/// <p/>Applications should only use this if they need <i>all</i> of the matching
		/// documents. The high-level search API (<see cref="Searcher.Search(Query, int)" />
		/// ) is usually more efficient, as it skips non-high-scoring hits.
		/// <p/>Note: The <c>score</c> passed to this method is a raw score.
		/// In other words, the score will not necessarily be a float whose value is
		/// between 0 and 1.
		/// </summary>
		/// <throws>  BooleanQuery.TooManyClauses </throws>
		public virtual void  Search(Query query, Collector results)
		{
			Search(CreateWeight(query), null, results);
		}
 /// <summary>
 /// Searches for documents mapped from the given type using the specified query and Collector.
 /// </summary>
 /// <typeparam name="TObject">
 /// The type of the object to search documents for.
 /// </typeparam>
 /// <param name="searcher">
 /// The Searcher to search on.
 /// </param>
 /// <param name="query">
 /// The Query which selects the documents.
 /// </param>
 /// <param name="results">
 /// The Collector to use to gather results.
 /// </param>
 public static void Search <TObject>(this Searcher searcher, Query query, Collector results)
 {
     searcher.Search(query, ObjectMapping.GetTypeFilter <TObject>(), results);
 }
Esempio n. 53
0
			public /*protected internal*/ override bool Score(Collector collector, int max, int firstDocID)
			{
				throw new System.NotSupportedException(Lucene.Net.Search.JustCompileSearch.UNSUPPORTED_MSG);
			}
 public /*protected internal*/ override bool Score(Collector collector, int max, int firstDocID)
 {
     return(scorer.Score(collector, max, firstDocID));
 }
Esempio n. 55
0
 /// <summary>Lower-level search API.
 ///
 /// <p/><see cref="Collector.Collect(int)" /> is called for every matching document.
 ///
 /// <p/>Applications should only use this if they need <i>all</i> of the matching
 /// documents. The high-level search API (<see cref="Searcher.Search(Query, int)" />
 /// ) is usually more efficient, as it skips non-high-scoring hits.
 /// <p/>Note: The <c>score</c> passed to this method is a raw score.
 /// In other words, the score will not necessarily be a float whose value is
 /// between 0 and 1.
 /// </summary>
 /// <throws>  BooleanQuery.TooManyClauses </throws>
 public virtual void  Search(Query query, Collector results)
 {
     Search(CreateWeight(query), null, results);
 }
 /// <summary>
 /// Searches for documents mapped from the given type using the specified query and Collector.
 /// </summary>
 /// <typeparam name="TObject">
 /// The type of the object to search documents for.
 /// </typeparam>
 /// <param name="searcher">
 /// The Searcher to search on.
 /// </param>
 /// <param name="kind">
 /// The kind of type to restrict the search to.
 /// </param>
 /// <param name="query">
 /// The Query which selects the documents.
 /// </param>
 /// <param name="results">
 /// The Collector to use to gather results.
 /// </param>
 public static void Search <TObject>(this Searcher searcher, DocumentObjectTypeKind kind, Query query, Collector results)
 {
     searcher.Search(query, ObjectMapping.GetTypeFilter <TObject>(kind), results);
 }
Esempio n. 57
0
 public override void Search(Weight weight, Filter filter, Collector collector)
 {
     if (filter == null)
     {
         for (int i = 0; i < subReaders.Length; i++)
         {
             // search each subreader
             collector.SetNextReader(subReaders[i], docStarts[i]);
             Scorer scorer = weight.Scorer(subReaders[i], !collector.AcceptsDocsOutOfOrder(), true);
             if (scorer != null)
             {
                 scorer.Score(collector);
             }
         }
     }
     else
     {
         for (int i = 0; i < subReaders.Length; i++)
         {
             // search each subreader
             collector.SetNextReader(subReaders[i], docStarts[i]);
             SearchWithFilter(subReaders[i], weight, filter, collector);
         }
     }
 }
Esempio n. 58
0
 public PositiveScoresOnlyCollector(Collector c)
 {
     this.c = c;
 }
 public EarlyTerminatingSortingCollectorHelper(Collector @in, Sort sort, int numDocsToCollect)
     : base(@in, sort, numDocsToCollect)
 {
 }
Esempio n. 60
0
 public abstract void  Search(Weight weight, Filter filter, Collector results);