我試圖索引一個MP3文件只有一個ID3幀。使用CLucene和TagLib。下面的代碼工作正常:將文檔添加到Lucene索引導致崩潰
...
TagLib::MPEG::File file("/home/user/Depeche Mode - Personal Jesus.mp3");
if (file.ID3v2Tag()) {
TagLib::ID3v2::FrameList frameList = file.ID3v2Tag()->frameList();
lucene::document::Document *document = new lucene::document::Document;
TagLib::ID3v2::FrameList::ConstIterator frame = frameList.begin();
std::wstring field_name((*frame)->frameID().begin(), (*frame)->frameID().end());
const wchar_t *fieldName = field_name.c_str();
const wchar_t *fieldValue = (*frame)->toString().toWString().c_str();
lucene::document::Field field(fieldName, fieldValue, true, true, true, false);
document->add(field);
writer->addDocument(document);
}
...
但是這一次使應用程序崩潰:
...
TagLib::MPEG::File file("/home/user/Depeche Mode - Personal Jesus.mp3");
if (file.ID3v2Tag()) {
TagLib::ID3v2::FrameList frameList = file.ID3v2Tag()->frameList();
lucene::document::Document *document = new lucene::document::Document;
for (TagLib::ID3v2::FrameList::ConstIterator frame = frameList.begin(); frame != frameList.end(); frame++) {
std::wstring field_name((*frame)->frameID().begin(), (*frame)->frameID().end());
const wchar_t *fieldName = field_name.c_str();
const wchar_t *fieldValue = (*frame)->toString().toWString().c_str();
lucene::document::Field field(fieldName, fieldValue, true, true, true, false);
document->add(field);
}
writer->addDocument(document);
}
...
這是爲什麼?
它工作[沒有第一個分號],但我不明白爲什麼字段被快速釋放;-)無論如何,謝謝你! – theorist 2010-07-01 15:37:25
正如我所說,範圍:http://msdn.microsoft.com/en-us/library/b7kfh662%28VS.80%29.aspx。別客氣。 – synhershko 2010-07-01 15:51:43