コード例 #1
0
ファイル: IndexTestCase.cpp プロジェクト: hxfxjun/firtex2
void IndexTestCase::testInt32ForwardIndex()
{
    DocumentSchema schema;
    schema.addSortableField("Int32Id", FieldType::INT32, false);

    const static size_t NUM_DOCS = 1000;
    stringstream ss;
    for (size_t i = 0; i < NUM_DOCS; ++i)
    {
        ss << i << ";";
    }

    GLOBAL_CONF().Build.buildThreadCount = 1;
    buildIndex(schema, ss.str());

    tstring str = getTestPath();
    Index index;
    index.open(str, Index::READ, NULL);
    IndexReaderPtr pReader = index.acquireReader();
    CPPUNIT_ASSERT(pReader != NULL);
    ForwardIndexIteratorPtr pForIndexIt = pReader->forwardIndexReader("Int32Id");
    CPPUNIT_ASSERT(pForIndexIt != NULL);
    Int32ForwardIndexIteratorPtr pInt32ForIndexIt =
        pForIndexIt.cast<Int32ForwardIndexIterator>();
    CPPUNIT_ASSERT(pInt32ForIndexIt != NULL);
    
    int32_t value = 0;
    docid_t docId = 0;
    for (; docId < (docid_t)NUM_DOCS; ++docId)
    {
        CPPUNIT_ASSERT(pInt32ForIndexIt->seek(docId, value));
        CPPUNIT_ASSERT_EQUAL((int32_t)docId, value);
    }
    CPPUNIT_ASSERT(!pInt32ForIndexIt->seek(docId, value));
}
コード例 #2
0
ファイル: IndexTestCase.cpp プロジェクト: hxfxjun/firtex2
void IndexTestCase::testInt32_IF()
{
    DocumentSchema schema;
    schema.addField("Int32", "INT32_IF", false);

    const static size_t NUM_DOCS = 1000;
    stringstream ss;
    for (size_t i = 0; i < NUM_DOCS; ++i)
    {
        ss << (i % 100) << ";";
    }

    GLOBAL_CONF().Build.buildThreadCount = 1;
    buildIndex(schema, ss.str());

    tstring str = getTestPath();
    Index index;
    index.open(str, Index::READ, NULL);
    IndexReaderPtr pReader = index.acquireReader();
    CPPUNIT_ASSERT(pReader != NULL);
    TermReaderPtr pTermReader = pReader->termReader();
    CPPUNIT_ASSERT(pTermReader);
    TermIteratorPtr pTermIterator = pTermReader->termIterator("Int32");
    CPPUNIT_ASSERT(pTermIterator != NULL);

    while (pTermIterator->hasNext())
    {
        TermIterator::TermEntry entry = pTermIterator->next();
        const TermMeta& termMeta = entry.postingIterator->getTermMeta();
        CPPUNIT_ASSERT_EQUAL((df_t)10, termMeta.getDocFreq());
        CPPUNIT_ASSERT_EQUAL((ctf_t)10, termMeta.getCTF());
    }

    Term term("Int32", "0");
    TermPostingIteratorPtr pPost = pTermReader->seek(&term);
    CPPUNIT_ASSERT(pPost);
    docid_t docId = pPost->skipTo(0);
    CPPUNIT_ASSERT_EQUAL((docid_t)0, docId);
    docId = pPost->skipTo(901);
    CPPUNIT_ASSERT_EQUAL((docid_t)INVALID_DOCID, docId);

    ForwardIndexIteratorPtr pForIndexIt = pReader->forwardIndexReader("Int32");
    CPPUNIT_ASSERT(pForIndexIt != NULL);
    Int32ForwardIndexIteratorPtr pInt32ForIndexIt =
        pForIndexIt.cast<Int32ForwardIndexIterator>();
    CPPUNIT_ASSERT(pInt32ForIndexIt != NULL);
    
    int32_t value = 0;
    docId = 0;
    for (; docId < (docid_t)NUM_DOCS; ++docId)
    {
        CPPUNIT_ASSERT(pInt32ForIndexIt->seek(docId, value));
        CPPUNIT_ASSERT_EQUAL((int32_t)(docId % 100), value);
    }
    CPPUNIT_ASSERT(!pInt32ForIndexIt->seek(docId, value));
}
コード例 #3
0
void ForwardIndexTestCase::testWriteAndReadWithMultiBarrels()
{
    const size_t NUM_BARRELS = 3;
    const size_t NUM_DOCS = 300;
    vector<int32_t> v1;
    vector<int64_t> v2;
    vector<float> v3;

    float fVal = 0.5;
    size_t idx = 0;
    for (size_t i = 0; i < NUM_BARRELS; ++i)
    {
        stringstream ss;
        for (size_t j = 0; j < NUM_DOCS; ++j)
        {
            ss << idx << "," << idx * 9381 << "," << fVal * idx << ";";
            v1.push_back(idx);
            v2.push_back(idx * 9381);
            v3.push_back(fVal * idx);
            ++idx;
        }
        buildForwardIndex(ss.str());
    }

    Index index;
    index.open(getIndexPath(), Index::READ, NULL);
    IndexReaderPtr pReader = index.acquireReader();
    
    ForwardIndexIteratorPtr fdIter = pReader->forwardIndexReader("Number1");
    CPPUNIT_ASSERT(fdIter != NULL);
    checkForwardIndex<int32_t>(fdIter, v1);

    fdIter = pReader->forwardIndexReader("Number2");
    CPPUNIT_ASSERT(fdIter != NULL);
    checkForwardIndex<int64_t>(fdIter, v2);

    fdIter = pReader->forwardIndexReader("Price");
    CPPUNIT_ASSERT(fdIter != NULL);
    checkForwardIndex<float>(fdIter, v3);
}
コード例 #4
0
void ForwardIndexTestCase::testWriteAndRead()
{
    const size_t NUM_DOCS = 100;
    vector<int32_t> v1;
    vector<int64_t> v2;
    vector<float> v3;

    float fVal = 0.5;
    stringstream ss;
    for (size_t i = 0; i < NUM_DOCS; ++i)
    {
        ss << i << "," << i * 9381 << "," << fVal * i << ";";
        v1.push_back(i);
        v2.push_back(i * 9381);
        v3.push_back(fVal * i);
    }

    GLOBAL_CONF().Build.buildThreadCount = 1;

    buildForwardIndex(ss.str());

    Index index;
    index.open(getIndexPath(), Index::READ, NULL);
    IndexReaderPtr pReader = index.acquireReader();
    
    ForwardIndexIteratorPtr fdIter = pReader->forwardIndexReader("Number1");
    CPPUNIT_ASSERT(fdIter != NULL);
    checkForwardIndex<int32_t>(fdIter, v1);

    fdIter = pReader->forwardIndexReader("Number2");
    CPPUNIT_ASSERT(fdIter != NULL);
    checkForwardIndex<int64_t>(fdIter, v2);

    fdIter = pReader->forwardIndexReader("Price");
    CPPUNIT_ASSERT(fdIter != NULL);
    checkForwardIndex<float>(fdIter, v3);
}