Pregunta

Estoy tratando de índice de un archivo MP3 con una sola ID3 marco. utilizando CLucene y TagLib. el siguiente código funciona bien:

...
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);
}
...

pero éste hace que el bloqueo de la aplicación:

...
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);
}
...

¿Por qué?!

¿Fue útil?

Solución

Este es un tema de alcance - en el momento de llamar escritor-> addDocument, los campos que agregó a la misma son liberados. Utilice este código en su lugar:

document->add(* new lucene::document::Field(fieldName, fieldValue, true, true, true, false));

Es posible que desee ver en cl_demo y cl_test para ver algunos ejemplos de código.

Otros consejos

No es necesario construir un nuevo documento Lucene :: :: El campo por cada etiqueta que va a agregar? Parece que va a reutilizar la misma dirección para esto, lo que es problemático. Supongo que un depurador podría dar más información.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top