From: Jonas P. <jon...@gm...> - 2013-08-04 12:25:00
|
Dear all I have the following problem. When the application starts, the method loadIndex is called and this method tries to load an existing index. This method works fine when there is an index and when there is no index. However during the execution of the program, the method startIndexing can be called. When a new IndexWriter is created I get the following message: Exception at 0x75ccc41f, code: 0xe06d7363: C++ exception, flags=0x1 (execution cannot be continued) (first chance) at c:\users\clucene-core-2.3.3.4\clucene-core-2.3.3.4\src\core\clucene\store\directory.cpp:54 However when I check the index directory, I see that the index is being generated by the method startIndexing. However when the execution flow reaches the statement IndexReader* r = IndexReader::open(indexDirectory.toStdString().c_str()); the following message is shown: :0: error: Exception at 0x56e37bea, code: 0xc0000005: read access violation at: 0x0, flags=0x0 (first chance) I have no idea what the problem can be. I use Qt 5.1, Qt creator and MSVC 2010. I compiled the CLucene code as a DLL to which I link in the application. void IndexingEngine::loadIndex(Dataset *dataset, QString indexDirectory) { try{ if ( IndexReader::indexExists(indexDirectory.toStdString().c_str()) ){ if ( IndexReader::isLocked(indexDirectory.toStdString().c_str()) ){ IndexReader::unlock(indexDirectory.toStdString().c_str()); } } else return; QStringList *termsInIndex = new QStringList(); IndexReader* r = IndexReader ::open(indexDirectory.toStdString().c_str()); TermEnum* te = r->*terms*(); int32_t nterms; for (nterms = 0; te->*next*() == true; nterms++) { termsInIndex->append(QString::fromStdWString(te->*term* ()->text())); } _CLLDELETE(te); r->close(); _CLLDELETE(r); }catch(CLuceneError& err){ printf("Error: %s\n", err.what()); }catch(...){ printf("Unknown error\n"); } } void IndexingEngine::startIndexingTXT(Dataset *dataset, bool clearIndex, QString indexDirectory) { int i=0; const char* target = indexDirectory.toStdString().c_str(); IndexWriter* writer = NULL; lucene::analysis::WhitespaceAnalyzer an; try{ if ( !clearIndex && IndexReader::indexExists(target) ){ if ( IndexReader::isLocked(target) ){ IndexReader::unlock(target); } writer = _CLNEW IndexWriter( target, &an, false); }else{ writer = _CLNEW IndexWriter( indexDirectory.toStdString().c_str() ,&an, true); } writer->setMaxFieldLength(0x7FFFFFFFL); // LUCENE_INT32_MAX_SHOULDBE writer->setUseCompoundFile(false); { QDirIterator it2 (dataset->getDatasetDirectory(), QDir:: NoDotAndDotDot | QDir::Files | QDir::Dirs); while (it2.hasNext()) { it2.next(); QFile file; file.setFileName(it2.filePath()); file.*open*(QIODevice::ReadOnly | QIODevice::Text); QString filename = it2.fileName(); QString contents = file.readAll(); Document doc; doc.clear(); doc.add( *_CLNEW Field(_T("filename"), filename.toStdWString().c_str(), Field::STORE_YES | Field::INDEX_UNTOKENIZED ) ); doc.add( *_CLNEW Field(_T("contents"), contents.toStdWString().c_str(), Field::STORE_YES | Field::INDEX_TOKENIZED) ); writer->addDocument( &doc ); i++; file.*close*(); } } writer->setUseCompoundFile(true); writer->optimize(); writer->close(); _CLLDELETE(writer); QStringList *termsInIndex = new QStringList(); IndexReader* r = IndexReader ::open(indexDirectory.toStdString().c_str()); TermEnum* te = r->*terms*(); int32_t nterms; for (nterms = 0; te->*next*() == true; nterms++) { termsInIndex->append(QString::fromStdWString(te->*term* ()->text())); } _CLLDELETE(te); r->close(); _CLLDELETE(r); progress->setValue(100); }catch(CLuceneError& err){ printf("Error: %s\n", err.what()); }catch(...){ printf("Unknown error\n"); } _lucene_shutdown(); } |