Exemple #1
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);
                }
            }
        }
Exemple #2
0
        public override int NextDoc()
        {
            bool more;

            do
            {
                while (bucketTable.first != null)
                {
                    // more queued
                    current           = bucketTable.first;
                    bucketTable.first = current.next;                     // pop the queue

                    // check prohibited & required, and minNrShouldMatch
                    if ((current.bits & prohibitedMask) == 0 && (current.bits & requiredMask) == requiredMask && current.coord >= minNrShouldMatch)
                    {
                        return(doc = current.doc);
                    }
                }

                // refill the queue
                more = false;
                end += BucketTable.SIZE;
                for (SubScorer sub = scorers; sub != null; sub = sub.next)
                {
                    Scorer scorer = sub.scorer;
                    sub.collector.SetScorer(scorer);
                    int doc = scorer.DocID();
                    while (doc < end)
                    {
                        sub.collector.Collect(doc);
                        doc = scorer.NextDoc();
                    }
                    more |= (doc != NO_MORE_DOCS);
                }
            }while (bucketTable.first != null || more);

            return(this.doc = NO_MORE_DOCS);
        }
			internal HeapedScorerDoc(ScorerDocQueue enclosingInstance, Scorer s):this(enclosingInstance, s, s.DocID())
			{
			}
		/// <summary> Adds a Scorer to the ScorerDocQueue in log(size) time if either
		/// the ScorerDocQueue is not full, or not lessThan(scorer, top()).
		/// </summary>
		/// <param name="scorer">
		/// </param>
		/// <returns> true if scorer is added, false otherwise.
		/// </returns>
		public virtual bool Insert(Scorer scorer)
		{
			if (size < maxSize)
			{
				Put(scorer);
				return true;
			}
			else
			{
				int docNr = scorer.DocID();
				if ((size > 0) && (!(docNr < topHSD.doc)))
				{
					// heap[1] is top()
					heap[1] = new HeapedScorerDoc(this, scorer, docNr);
					DownHeap();
					return true;
				}
				else
				{
					return false;
				}
			}
		}