#include "CLucene/StdHeader.h" #include "PhrasePositions.h" #include "CLucene/index/Terms.h" using namespace lucene::index; namespace lucene{ namespace search{ PhrasePositions::PhrasePositions(TermPositions& t, const int_t o): tp(&t), offset(o), position(0), count(0) { Next(); } PhrasePositions::~PhrasePositions(){ if ( next ) delete next; if ( tp != NULL ){ tp->close(); delete tp; tp = NULL; } } void PhrasePositions::Next() { // increments to next doc if (!tp->next()) { tp->close(); // close stream delete tp; tp = NULL; doc = INT_MAX; // sentinel value return; } doc = tp->Doc(); position = 0; } void PhrasePositions::firstPosition() { count = tp->Freq(); // read first pos nextPosition(); } bool PhrasePositions::nextPosition() { if (count-- > 0) { // read subsequent pos's position = tp->nextPosition() - offset; return true; } else return false; } }}