static void verifyDocFreq(const DirectoryPtr& dir) {
    IndexReaderPtr reader = IndexReader::open(dir, true);

    // create enumeration of all terms
    TermEnumPtr termEnum = reader->terms();
    // go to the first term (aaa)
    termEnum->next();
    // assert that term is 'aaa'
    EXPECT_EQ(L"aaa", termEnum->term()->text());
    EXPECT_EQ(200, termEnum->docFreq());
    // go to the second term (bbb)
    termEnum->next();
    // assert that term is 'bbb'
    EXPECT_EQ(L"bbb", termEnum->term()->text());
    EXPECT_EQ(100, termEnum->docFreq());

    termEnum->close();

    // create enumeration of terms after term 'aaa', including 'aaa'
    termEnum = reader->terms(newLucene<Term>(L"content", L"aaa"));
    // assert that term is 'aaa'
    EXPECT_EQ(L"aaa", termEnum->term()->text());
    EXPECT_EQ(200, termEnum->docFreq());
    // go to term 'bbb'
    termEnum->next();
    // assert that term is 'bbb'
    EXPECT_EQ(L"bbb", termEnum->term()->text());
    EXPECT_EQ(100, termEnum->docFreq());

    termEnum->close();
}
 void FilteredTermEnum::setEnum(TermEnumPtr actualEnum)
 {
     this->actualEnum = actualEnum;
     // Find the first term that matches
     TermPtr term(actualEnum->term());
     if (term && termCompare(term))
         currentTerm = term;
     else
         next();
 }
void SegmentTermDocs::seek(const TermEnumPtr& termEnum) {
    TermInfoPtr ti;
    TermPtr term;

    SegmentTermEnumPtr segmentTermEnum(boost::dynamic_pointer_cast<SegmentTermEnum>(termEnum));
    SegmentReaderPtr parent(_parent);

    // use comparison of fieldinfos to verify that termEnum belongs to the same segment as this SegmentTermDocs
    if (segmentTermEnum && segmentTermEnum->fieldInfos == parent->core->fieldInfos) { // optimized case
        term = segmentTermEnum->term();
        ti = segmentTermEnum->termInfo();
    } else { // punt case
        term = termEnum->term();
        ti = parent->core->getTermsReader()->get(term);
    }

    seek(ti, term);
}
TEST_F(ParallelTermEnumTest, testParallelTermEnum) {
    ParallelReaderPtr pr = newLucene<ParallelReader>();
    pr->add(ir1);
    pr->add(ir2);

    TermDocsPtr td = pr->termDocs();
    TermEnumPtr te = pr->terms();

    EXPECT_TRUE(te->next());
    EXPECT_EQ(L"field1:brown", te->term()->toString());
    td->seek(te->term());
    EXPECT_TRUE(td->next());
    EXPECT_EQ(0, td->doc());
    EXPECT_TRUE(!td->next());
    EXPECT_TRUE(te->next());
    EXPECT_EQ(L"field1:fox", te->term()->toString());
    td->seek(te->term());
    EXPECT_TRUE(td->next());
    EXPECT_EQ(0, td->doc());
    EXPECT_TRUE(!td->next());
    EXPECT_TRUE(te->next());
    EXPECT_EQ(L"field1:jumps", te->term()->toString());
    td->seek(te->term());
    EXPECT_TRUE(td->next());
    EXPECT_EQ(0, td->doc());
    EXPECT_TRUE(!td->next());
    EXPECT_TRUE(te->next());
    EXPECT_EQ(L"field1:quick", te->term()->toString());
    td->seek(te->term());
    EXPECT_TRUE(td->next());
    EXPECT_EQ(0, td->doc());
    EXPECT_TRUE(!td->next());
    EXPECT_TRUE(te->next());
    EXPECT_EQ(L"field1:the", te->term()->toString());
    td->seek(te->term());
    EXPECT_TRUE(td->next());
    EXPECT_EQ(0, td->doc());
    EXPECT_TRUE(!td->next());
    EXPECT_TRUE(te->next());
    EXPECT_EQ(L"field2:brown", te->term()->toString());
    td->seek(te->term());
    EXPECT_TRUE(td->next());
    EXPECT_EQ(0, td->doc());
    EXPECT_TRUE(!td->next());
    EXPECT_TRUE(te->next());
    EXPECT_EQ(L"field2:fox", te->term()->toString());
    td->seek(te->term());
    EXPECT_TRUE(td->next());
    EXPECT_EQ(0, td->doc());
    EXPECT_TRUE(!td->next());
    EXPECT_TRUE(te->next());
    EXPECT_EQ(L"field2:jumps", te->term()->toString());
    td->seek(te->term());
    EXPECT_TRUE(td->next());
    EXPECT_EQ(0, td->doc());
    EXPECT_TRUE(!td->next());
    EXPECT_TRUE(te->next());
    EXPECT_EQ(L"field2:quick", te->term()->toString());
    td->seek(te->term());
    EXPECT_TRUE(td->next());
    EXPECT_EQ(0, td->doc());
    EXPECT_TRUE(!td->next());
    EXPECT_TRUE(te->next());
    EXPECT_EQ(L"field2:the", te->term()->toString());
    td->seek(te->term());
    EXPECT_TRUE(td->next());
    EXPECT_EQ(0, td->doc());
    EXPECT_TRUE(!td->next());
    EXPECT_TRUE(te->next());
    EXPECT_EQ(L"field3:dog", te->term()->toString());
    td->seek(te->term());
    EXPECT_TRUE(td->next());
    EXPECT_EQ(0, td->doc());
    EXPECT_TRUE(!td->next());
    EXPECT_TRUE(te->next());
    EXPECT_EQ(L"field3:fox", te->term()->toString());
    td->seek(te->term());
    EXPECT_TRUE(td->next());
    EXPECT_EQ(0, td->doc());
    EXPECT_TRUE(!td->next());
    EXPECT_TRUE(te->next());
    EXPECT_EQ(L"field3:jumps", te->term()->toString());
    td->seek(te->term());
    EXPECT_TRUE(td->next());
    EXPECT_EQ(0, td->doc());
    EXPECT_TRUE(!td->next());
    EXPECT_TRUE(te->next());
    EXPECT_EQ(L"field3:lazy", te->term()->toString());
    td->seek(te->term());
    EXPECT_TRUE(td->next());
    EXPECT_EQ(0, td->doc());
    EXPECT_TRUE(!td->next());
    EXPECT_TRUE(te->next());
    EXPECT_EQ(L"field3:over", te->term()->toString());
    td->seek(te->term());
    EXPECT_TRUE(td->next());
    EXPECT_EQ(0, td->doc());
    EXPECT_TRUE(!td->next());
    EXPECT_TRUE(te->next());
    EXPECT_EQ(L"field3:the", te->term()->toString());
    td->seek(te->term());
    EXPECT_TRUE(td->next());
    EXPECT_EQ(0, td->doc());
    EXPECT_TRUE(!td->next());
    EXPECT_TRUE(!te->next());
}