void index(const tstring& sDir) { IndexWriterPtr pIndexWriter = m_pIndex->acquireWriter(); DirectoryIterator di(sDir, false); while(di.hasNext()) { const File& f = di.next(); if(f.isFile()) { BinaryFile bf; bf.open(f.getPath().c_str(), BinaryFile::READ); if(bf.isFileOpen()) { size_t nRead = (size_t)bf.getLength(); if (nRead > 0) { DocumentPtr pDoc = new Document(pIndexWriter->getDocSchema()); pDoc->addField(0, f.getPath().c_str()); char* buf = new char[nRead + 1]; bf.read(buf, nRead); buf[nRead] = 0; pDoc->addField(1, buf, nRead, false); delete[] buf; pIndexWriter->addDocument(pDoc); } } } } docPool.commit(); pIndexWriter->close(); }
void DateTimeIndexTestCase::buildDateTimeIndex(const string& sDocs) { try { DocumentSchema schema; schema.addField("DateTime1", "DATETIME_I", true); Index index; index.open(getIndexPath(), Index::WRITE, &schema); IndexWriterPtr pIndexWriter = index.acquireWriter(); StringTokenizer st(sDocs, ";", StringTokenizer::TOKEN_TRIM | StringTokenizer::TOKEN_IGNORE_EMPTY); for (StringTokenizer::Iterator it = st.begin(); it != st.end(); ++it) { DocumentPtr pDoc = new Document(pIndexWriter->getDocSchema()); pDoc->addField(0, (*it).c_str()); pIndexWriter->addDocument(pDoc); } pIndexWriter->close(); } catch (const FirteXException& ) { CPPUNIT_ASSERT(false); } }