bool NearSpansUnordered::next()
 {
     if (firstTime)
     {
         initList(true);
         listToQueue(); // initialize queue
         firstTime = false;
     }
     else if (more)
     {
         if (min()->next()) // trigger further scanning
             queue->updateTop(); // maintain queue
         else
             more = false;
     }
     
     while (more)
     {
         bool queueStale = false;
         
         if (min()->doc() != max->doc()) // maintain list
         {
             queueToList();
             queueStale = true;
         }
         
         // skip to doc with all clauses
         
         while (more && first->doc() < last->doc())
         {
             more = first->skipTo(last->doc()); // skip first upto last
             firstToLast(); // and move it to the end
             queueStale = true;
         }
         
         if (!more)
             return false;
         
         // found doc with all clauses
         
         if (queueStale) // maintain the queue
         {
             listToQueue();
             queueStale = false;
         }
         
         if (atMatch())
             return true;
         
         more = min()->next();
         if (more)
             queue->updateTop(); // maintain queue
     }
     return false; // no more matches
 }
Ejemplo n.º 2
0
	qreal ExactPhraseScorer::phraseFreq(){
	//Func - Returns the freqency of the phrase
	//Pre  - first != NULL
	//       last  != NULL
	//       pq    != NULL
	//       size of the PhraseQueue pq is 0
	//Post - The frequency of the phrase has been returned

		CND_PRECONDITION(first != NULL,"first is NULL");
		CND_PRECONDITION(last  != NULL,"last is NULL");
		CND_PRECONDITION(pq    != NULL,"pq is NULL");
		CND_PRECONDITION(pq->size()==0,"pq is not empty");

		//build pq from list

		//Add the nodes of the list of PhrasePositions and store them
		//into the PhraseQueue pq so it can used to build
		//a list of sorted nodes
		for (PhrasePositions* pp = first; pp != NULL; pp = pp->_next) {
			//Read the first TermPosition of the current PhrasePositions pp
			pp->firstPosition();
			//Store the current PhrasePositions pp into the PhraseQueue pq
			pq->put(pp);
		}
		//pqToList requires that first and last be NULL when it's called.  
		//This is done at the beginning of pqToList()
		//In this case, the nodes of the linked list are referenced by pq (see
		//above loop), so we can clear our pointers to the head and tail of the
		//linked list without fear of leaking the nodes.
		
		//rebuild list from pq
		pqToList();

		//Initialize freq at 0
		int32_t freq = 0;

		//find position with all terms
		do {
			//scan forward in first
			while (first->position < last->position){
				do{
					if (!first->nextPosition()){
						return (qreal)freq;
					}
				} while (first->position < last->position);
				//Make the current first node the last node in the list
				firstToLast();
			}
			//all equal: a match has been found
			freq++;
		} while (last->nextPosition());

		return (qreal)freq;
	}
Ejemplo n.º 3
0
	// next without initial increment
	bool PhraseScorer::doNext() {
		while (more) {
			while (more && first->doc < last->doc) {      // find doc w/ all the terms
				more = first->skipTo(last->doc);            // skip first upto last
				firstToLast();                            // and move it to the end
			}

			if (more) {
				// found a doc with all of the terms
				freq = phraseFreq();                      // check for phrase
				if (freq == 0.0f)                         // no match
					more = last->next();                     // trigger further scanning
				else
					return true;                            // found a match
			}
		}
		return false;                                 // no more matches
	}