diff options
Diffstat (limited to 'src/backend/drivers/cswordmoduleinfo.cpp')
-rw-r--r-- | src/backend/drivers/cswordmoduleinfo.cpp | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/src/backend/drivers/cswordmoduleinfo.cpp b/src/backend/drivers/cswordmoduleinfo.cpp index b1e646f..a7ceca9 100644 --- a/src/backend/drivers/cswordmoduleinfo.cpp +++ b/src/backend/drivers/cswordmoduleinfo.cpp @@ -11,8 +11,6 @@ #include <QSharedPointer> #include <CLucene.h> -#include <CLucene/util/Misc.h> -#include <CLucene/util/Reader.h> #include <QByteArray> #include <QCoreApplication> #include <QDebug> @@ -43,7 +41,7 @@ #include <versekey.h> -#ifdef BT_DEBUG +#if 0 namespace { /** HELPER Method to dump all current EntryAttributes of a module. */ @@ -223,7 +221,7 @@ bool CSwordModuleInfo::hasIndex() const { return lucene::index::IndexReader::indexExists(getModuleStandardIndexLocation().toAscii().constData()); } -void CSwordModuleInfo::buildIndex() { +bool CSwordModuleInfo::buildIndex() { m_cancelIndexing = false; @@ -260,7 +258,6 @@ void CSwordModuleInfo::buildIndex() { QSharedPointer<lucene::index::IndexWriter> writer( new lucene::index::IndexWriter(index.toAscii().constData(), &an, true) ); //always create a new index writer->setMaxFieldLength(BT_MAX_LUCENE_FIELD_LENGTH); writer->setUseCompoundFile(true); //merge segments into a single file - writer->setMinMergeDocs(1000); m_module->setPosition(sword::TOP); unsigned long verseLowIndex = m_module->Index(); @@ -406,12 +403,22 @@ void CSwordModuleInfo::buildIndex() { emit hasIndexChanged(true); } } + catch (CLuceneError &e) { + qWarning() << "CLucene exception occurred while indexing:" << e.what(); + util::showWarning(0, QCoreApplication::tr("Indexing aborted"), QCoreApplication::tr("An internal error occurred while building the index: %1").arg(e.what())); + deleteIndex(); + m_cancelIndexing = false; + return false; + } catch (...) { qWarning("CLucene exception occurred while indexing"); util::showWarning(0, QCoreApplication::tr("Indexing aborted"), QCoreApplication::tr("An internal error occurred while building the index.")); deleteIndex(); m_cancelIndexing = false; + return false; } + + return true; } void CSwordModuleInfo::deleteIndex() { @@ -442,10 +449,10 @@ int CSwordModuleInfo::searchIndexed(const QString &searchedText, QList<sword::VerseKey*> list; if (s) { - m_module->SetKey(*s); + m_module->setKey(*s); } - results.ClearList(); + results.clear(); try { // do not use any stop words @@ -455,7 +462,11 @@ int CSwordModuleInfo::searchIndexed(const QString &searchedText, lucene_utf8towcs(wcharBuffer, searchedText.toUtf8().constData(), BT_MAX_LUCENE_FIELD_LENGTH); QSharedPointer<lucene::search::Query> q( lucene::queryParser::QueryParser::parse((const TCHAR*)wcharBuffer, (const TCHAR*)_T("content"), &analyzer) ); +#ifdef CLUCENE2 + QSharedPointer<lucene::search::Hits> h( searcher.search(q.data(), lucene::search::Sort::INDEXORDER()) ); +#else QSharedPointer<lucene::search::Hits> h( searcher.search(q.data(), lucene::search::Sort::INDEXORDER) ); +#endif /// \warning This is a workaround for Sword constness const bool useScope = (const_cast<sword::ListKey&>(scope).Count() > 0); @@ -465,7 +476,11 @@ int CSwordModuleInfo::searchIndexed(const QString &searchedText, QSharedPointer<sword::SWKey> swKey( module()->CreateKey() ); - for (int i = 0; i < h->length(); ++i) { +#ifdef CLUCENE2 + for (unsigned int i = 0; i < h->length(); ++i) { +#else + for (int i = 0; i < h->length(); ++i) { +#endif doc = &h->doc(i); lucene_wcstoutf8(utfBuffer, (const wchar_t*)doc->get((const TCHAR*)_T("key")), BT_MAX_LUCENE_FIELD_LENGTH); @@ -691,14 +706,14 @@ CSwordModuleInfo::TextDirection CSwordModuleInfo::textDirection() const { } void CSwordModuleInfo::write(CSwordKey *key, const QString &newText) { - module()->KeyText(key->key().toUtf8().constData()); + module()->setKey(key->key().toUtf8().constData()); //don't store a pointer to the const char* value somewhere because QCString doesn't keep the value of it module()->setEntry(isUnicode() ? newText.toUtf8().constData() : newText.toLocal8Bit().constData()); } bool CSwordModuleInfo::deleteEntry(CSwordKey * const key) { - module()->KeyText(isUnicode() ? key->key().toUtf8().constData() : key->key().toLocal8Bit().constData()); + module()->setKey(isUnicode() ? key->key().toUtf8().constData() : key->key().toLocal8Bit().constData()); if (module()) { module()->deleteEntry(); @@ -751,7 +766,7 @@ void CSwordModuleInfo::initCachedLanguage() { } Rendering::CEntryDisplay * CSwordModuleInfo::getDisplay() const { - return dynamic_cast < Rendering::CEntryDisplay * >(m_module->Disp()); + return dynamic_cast<Rendering::CEntryDisplay *>(m_module->getDisplay()); } QString CSwordModuleInfo::aboutText() const { |