l'aggiunta di un documento ad un crash cause indice Lucene
Domanda
Sto cercando di indice di un file mp3 con un solo fotogramma ID3. utilizzando CLucene e TagLib. il seguente codice funziona bene:
...
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);
}
...
ma questo rende il crash dell'applicazione:
...
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);
}
...
perché?!
Soluzione
Questa è una questione portata - per il momento si chiama scrittore-> AddDocument, i campi aggiunti ad esso vengono liberati. Utilizzare questo codice invece:
document->add(* new lucene::document::Field(fieldName, fieldValue, true, true, true, false));
Si consiglia di guardare a cl_demo e cl_test per vedere alcuni esempi di codice.
Altri suggerimenti
Non è necessario costruire un nuovo Lucene :: :: documento Campo per tag che si sta aggiungendo? Sembra che si sta riutilizzando lo stesso indirizzo di questo, che è problematico. Credo che un debugger potrebbe dirvi di più.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow