예제 #1
0
        void doPrevSetBit(BitArray a, FixedBitSet b)
        {
            int aa = a.Length + rnd.Next(100);
            int bb = aa;

            do
            {
                // aa = a.prevSetBit(aa-1);
                aa--;
                while ((aa >= 0) && (!a.Get(aa)))
                {
                    aa--;
                }
                if (b.Length() == 0)
                {
                    bb = -1;
                }
                else if (bb > b.Length() - 1)
                {
                    bb = b.PrevSetBit(b.Length() - 1);
                }
                else if (bb < 1)
                {
                    bb = -1;
                }
                else
                {
                    bb = bb >= 1 ? b.PrevSetBit(bb - 1) : -1;
                }
                Assert.AreEqual(aa, bb);
            } while (aa >= 0);
        }
            public override int Advance(int parentTarget)
            {
                //System.out.println("Q.advance parentTarget=" + parentTarget);
                if (parentTarget == NO_MORE_DOCS)
                {
                    return(_parentDoc = NO_MORE_DOCS);
                }

                if (parentTarget == 0)
                {
                    // Callers should only be passing in a docID from
                    // the parent space, so this means this parent
                    // has no children (it got docID 0), so it cannot
                    // possibly match.  We must handle this case
                    // separately otherwise we pass invalid -1 to
                    // prevSetBit below:
                    return(NextDoc());
                }

                _prevParentDoc = _parentBits.PrevSetBit(parentTarget - 1);

                //System.out.println("  rolled back to prevParentDoc=" + prevParentDoc + " vs parentDoc=" + parentDoc);
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(_prevParentDoc >= _parentDoc);
                }
                if (_prevParentDoc > _nextChildDoc)
                {
                    _nextChildDoc = _childScorer.Advance(_prevParentDoc);
                    // System.out.println("  childScorer advanced to child docID=" + nextChildDoc);
                    //} else {
                    //System.out.println("  skip childScorer advance");
                }

                // Parent & child docs are supposed to be orthogonal:
                if (_nextChildDoc == _prevParentDoc)
                {
                    throw IllegalStateException.Create("child query must only match non-parent docs, but parent docID=" + _nextChildDoc + " matched childScorer=" + _childScorer.GetType());
                }

                int nd = NextDoc();

                //System.out.println("  return nextParentDoc=" + nd);
                return(nd);
            }
예제 #3
0
            public override int NextDoc()
            {
                //System.out.println("Q.nextDoc() parentDoc=" + parentDoc + " childDoc=" + childDoc);

                // Loop until we hit a childDoc that's accepted
                while (true)
                {
                    if (_childDoc + 1 == _parentDoc)
                    {
                        // OK, we are done iterating through all children
                        // matching this one parent doc, so we now nextDoc()
                        // the parent.  Use a while loop because we may have
                        // to skip over some number of parents w/ no
                        // children:
                        while (true)
                        {
                            _parentDoc = _parentScorer.NextDoc();
                            ValidateParentDoc();

                            if (_parentDoc == 0)
                            {
                                // Degenerate but allowed: first parent doc has no children
                                // TODO: would be nice to pull initial parent
                                // into ctor so we can skip this if... but it's
                                // tricky because scorer must return -1 for
                                // .doc() on init...
                                _parentDoc = _parentScorer.NextDoc();
                                ValidateParentDoc();
                            }

                            if (_parentDoc == NO_MORE_DOCS)
                            {
                                _childDoc = NO_MORE_DOCS;
                                //System.out.println("  END");
                                return(_childDoc);
                            }

                            // Go to first child for this next parentDoc:
                            _childDoc = 1 + _parentBits.PrevSetBit(_parentDoc - 1);

                            if (_childDoc == _parentDoc)
                            {
                                // This parent has no children; continue
                                // parent loop so we move to next parent
                                continue;
                            }

                            if (_acceptDocs != null && !_acceptDocs.Get(_childDoc))
                            {
                                goto nextChildDocContinue;
                            }

                            if (_childDoc < _parentDoc)
                            {
                                if (_doScores)
                                {
                                    _parentScore = _parentScorer.GetScore();
                                    _parentFreq  = _parentScorer.Freq;
                                }
                                //System.out.println("  " + childDoc);
                                return(_childDoc);
                            }
                            else
                            {
                                // Degenerate but allowed: parent has no children
                            }
                        }
                    }

                    Debug.Assert(_childDoc < _parentDoc, "childDoc=" + _childDoc + " parentDoc=" + _parentDoc);
                    _childDoc++;
                    if (_acceptDocs != null && !_acceptDocs.Get(_childDoc))
                    {
                        continue;
                    }
                    //System.out.println("  " + childDoc);
                    return(_childDoc);

                    nextChildDocContinue :;
                }
            }
예제 #4
0
		void doPrevSetBit(BitArray a, FixedBitSet b)
		{
			int aa = a.Length + rnd.Next(100);
			int bb = aa;
			do
			{
				// aa = a.prevSetBit(aa-1);
				aa--;
				while ((aa >= 0) && (!a.Get(aa)))
				{
					aa--;
				}
				if (b.Length() == 0)
				{
					bb = -1;
				}
				else if (bb > b.Length() - 1)
				{
					bb = b.PrevSetBit(b.Length() - 1);
				}
				else if (bb < 1)
				{
					bb = -1;
				}
				else
				{
					bb = bb >= 1 ? b.PrevSetBit(bb - 1) : -1;
				}
				Assert.AreEqual(aa, bb);
			} while (aa >= 0);
		}