summaryrefslogtreecommitdiffstats
path: root/tools/assistant/lib
diff options
context:
space:
mode:
authorkh1 <qt-info@nokia.com>2009-08-17 13:11:32 (GMT)
committerkh1 <qt-info@nokia.com>2009-08-17 13:16:50 (GMT)
commit4929da8ad0a43220c3cbd2d9f11db4c535028243 (patch)
tree2ba30e16bb51f97c6cffec8989b76a09d5f57909 /tools/assistant/lib
parent9e144490bfa059050f8b90645db80b1fd45fd2b1 (diff)
downloadQt-4929da8ad0a43220c3cbd2d9f11db4c535028243.zip
Qt-4929da8ad0a43220c3cbd2d9f11db4c535028243.tar.gz
Qt-4929da8ad0a43220c3cbd2d9f11db4c535028243.tar.bz2
Add some more exception around to clucene index writer.
Reviewed-by: ck
Diffstat (limited to 'tools/assistant/lib')
-rw-r--r--tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp78
-rw-r--r--tools/assistant/lib/qhelpsearchindexwriter_clucene_p.h2
2 files changed, 60 insertions, 20 deletions
diff --git a/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp b/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp
index 6f7c035..4651d2e 100644
--- a/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp
+++ b/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp
@@ -590,15 +590,24 @@ void QHelpSearchIndexWriter::updateIndex(const QString &collectionFile,
void QHelpSearchIndexWriter::optimizeIndex()
{
- if (QCLuceneIndexReader::indexExists(m_indexFilesFolder)) {
- if (QCLuceneIndexReader::isLocked(m_indexFilesFolder))
- return;
-
- QCLuceneStandardAnalyzer analyzer;
- QCLuceneIndexWriter writer(m_indexFilesFolder, analyzer, false);
- writer.optimize();
- writer.close();
+#if !defined(QT_NO_EXCEPTIONS)
+ try {
+#endif
+ if (QCLuceneIndexReader::indexExists(m_indexFilesFolder)) {
+ if (QCLuceneIndexReader::isLocked(m_indexFilesFolder))
+ return;
+
+ QCLuceneStandardAnalyzer analyzer;
+ QCLuceneIndexWriter writer(m_indexFilesFolder, analyzer, false);
+ writer.optimize();
+ writer.close();
+ }
+#if !defined(QT_NO_EXCEPTIONS)
+ } catch (...) {
+ qWarning("Full Text Search, could not optimize index.");
+ return;
}
+#endif
}
void QHelpSearchIndexWriter::run()
@@ -720,21 +729,30 @@ void QHelpSearchIndexWriter::run()
}
#if !defined(QT_NO_EXCEPTIONS)
} catch (...) {
- qWarning("Full Text Search, could not create index writer in '%s'.", qPrintable(indexPath));
+ qWarning("Full Text Search, could not create index writer in '%s'.",
+ qPrintable(indexPath));
return;
}
#endif
- writer->setMergeFactor(100);
- writer->setMinMergeDocs(1000);
- writer->setMaxFieldLength(QCLuceneIndexWriter::DEFAULT_MAX_FIELD_LENGTH);
+#if !defined(QT_NO_EXCEPTIONS)
+ try {
+#endif
+ writer->setMergeFactor(100);
+ writer->setMinMergeDocs(1000);
+ writer->setMaxFieldLength(QCLuceneIndexWriter::DEFAULT_MAX_FIELD_LENGTH);
+#if !defined(QT_NO_EXCEPTIONS)
+ } catch (...) {
+ qWarning("Full Text Search, could not set writer properties.");
+ return;
+ }
+#endif
QStringList namespaces;
foreach(const QString &namespaceName, registeredDocs) {
mutexLocker.relock();
if (m_cancel) {
- writer->close();
- delete writer;
+ closeIndexWriter(writer);
emit indexingFinished();
return;
}
@@ -777,8 +795,7 @@ void QHelpSearchIndexWriter::run()
mutexLocker.unlock();
}
- writer->close();
- delete writer;
+ closeIndexWriter(writer);
mutexLocker.relock();
if (!m_cancel) {
@@ -813,15 +830,23 @@ bool QHelpSearchIndexWriter::addDocuments(const QList<QUrl> docFiles,
foreach(const QUrl &url, docFiles) {
QCLuceneDocument document;
DocumentHelper helper(url.toString(), engine.fileData(url));
- if (helper.addFieldsToDocument(&document, namespaceName, attrList))
- writer->addDocument(document, analyzer);
-
+ if (helper.addFieldsToDocument(&document, namespaceName, attrList)) {
+#if !defined(QT_NO_EXCEPTIONS)
+ try {
+#endif
+ writer->addDocument(document, analyzer);
+#if !defined(QT_NO_EXCEPTIONS)
+ } catch (...) {
+ qWarning("Full Text Search, could not properly add documents.");
+ return false;
+ }
+#endif
+ }
locker.relock();
if (m_cancel)
return false;
locker.unlock();
}
-
return true;
}
@@ -861,6 +886,19 @@ QList<QUrl> QHelpSearchIndexWriter::indexableFiles(QHelpEngineCore *helpEngine,
return docFiles;
}
+void QHelpSearchIndexWriter::closeIndexWriter(QCLuceneIndexWriter *writer)
+{
+#if !defined(QT_NO_EXCEPTIONS)
+ try {
+#endif
+ writer->close();
+ delete writer;
+#if !defined(QT_NO_EXCEPTIONS)
+ } catch (...) {
+ qWarning("Full Text Search, could not properly close index writer.");
+ }
+#endif
+}
} // namespace clucene
} // namespace fulltextsearch
diff --git a/tools/assistant/lib/qhelpsearchindexwriter_clucene_p.h b/tools/assistant/lib/qhelpsearchindexwriter_clucene_p.h
index e9a917b..d4bb755 100644
--- a/tools/assistant/lib/qhelpsearchindexwriter_clucene_p.h
+++ b/tools/assistant/lib/qhelpsearchindexwriter_clucene_p.h
@@ -104,6 +104,8 @@ private:
QList<QUrl> indexableFiles(QHelpEngineCore *helpEngine,
const QString &namespaceName, const QStringList &attributes) const;
+ void closeIndexWriter(QCLuceneIndexWriter *writer);
+
private:
QMutex mutex;
QWaitCondition waitCondition;