void IndexTestCase::testRefreshIndexAfterOptimize() { DocumentSchema schema; schema.addTextField("BODY"); stringstream ss; const size_t NUM_DOCS = 1000; for (size_t i = 0; i < NUM_DOCS; ++i) { ss << "body" << i << " hot;"; } buildIndex(schema, ss.str()); tstring str = getTestPath(); Index index; index.open(str, Index::READ, NULL); IndexReaderPtr pIndexReader1 = index.acquireReader(); checkDocFreq(pIndexReader1, "BODY", "hot", NUM_DOCS); buildIndex(schema, ss.str(), true); //Optimize index { Index index2; index2.open(str, Index::APPEND, NULL); IndexWriterPtr pIndexWriter = index2.acquireWriter(); pIndexWriter->optimizeIndex(); } IndexReaderPtr pIndexReader2 = index.acquireReader(true); CPPUNIT_ASSERT(pIndexReader1 != pIndexReader2); checkDocFreq(pIndexReader2, "BODY", "hot", 2 * NUM_DOCS); }
void IndexMergerAppRunner::indexMerge() { try { if (!m_sLexiDir.empty()) { GLOBAL_CONF().General.dictionaryPath = m_sLexiDir; } std::cout << "Open index: [ " << m_sIndexPath << "]" << std::endl; IndexPtr pIndex(new Index()); pIndex->open(m_sIndexPath, Index::APPEND, NULL); IndexWriterPtr pWriter = pIndex->acquireWriter(); if (m_nMergeMode == 2) { std::cout << "Begin optimize index: [ " << m_sIndexPath << "]" << std::endl; pWriter->optimizeIndex(); } else { std::cout << "Begin merge index: [ " << m_sIndexPath << "]" << std::endl; pWriter->mergeIndex(); } } catch(const FirteXException& fe) { cout << "Merge index FAILED: " << fe.what() << endl; } }
void IndexTestCase::testIndexOptimize() { GLOBAL_CONF().Merge.maxAllowedOpenFiles = 16; DocumentSchema schema; schema.addTextField("BODY"); stringstream ss; const size_t NUM_DOCS = 1000; for (size_t i = 0; i < NUM_DOCS; ++i) { ss << "body" << i << " hot;"; } try { buildIndex(schema, ss.str()); buildIndex(schema, ss.str(), true); } catch (const FirteXException& e) { cout << "ERROR: " << e.what() << endl; CPPUNIT_ASSERT(false); } tstring str = getTestPath(); { Index index; index.open(str, Index::APPEND, NULL); IndexWriterPtr pIndexWriter = index.acquireWriter(); CPPUNIT_ASSERT(pIndexWriter != NULL); try { pIndexWriter->optimizeIndex(); } catch (const FirteXException& e) { cout << "ERROR: " << e.what() << endl; CPPUNIT_ASSERT(false); } } Index index; try { index.open(str, Index::READ, NULL); IndexReaderPtr pIndexReader = index.acquireReader(); checkDocFreq(pIndexReader, "BODY", "hot", 2 * NUM_DOCS); } catch (const FirteXException& e) { cout << "ERROR: " << e.what() << endl; CPPUNIT_ASSERT(false); } }