summaryrefslogtreecommitdiffstats
path: root/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp')
-rw-r--r--tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp250
1 files changed, 121 insertions, 129 deletions
diff --git a/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp b/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp
index e3cc2b0..6e49e54 100644
--- a/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp
+++ b/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp
@@ -39,6 +39,7 @@
**
****************************************************************************/
+#include "qclucenefieldnames_p.h"
#include "qhelpenginecore.h"
#include "qhelp_global.h"
#include "fulltextsearch/qhits_p.h"
@@ -407,17 +408,17 @@ public:
QString parsedTitle = QHelpGlobal::documentTitle(data);
if(!parsedData.isEmpty()) {
- document->add(new QCLuceneField(QLatin1String("content"),
+ document->add(new QCLuceneField(ContentField,
parsedData,QCLuceneField::INDEX_TOKENIZED));
- document->add(new QCLuceneField(QLatin1String("path"), fileName,
+ document->add(new QCLuceneField(PathField, fileName,
QCLuceneField::STORE_YES | QCLuceneField::INDEX_UNTOKENIZED));
- document->add(new QCLuceneField(QLatin1String("title"), parsedTitle,
+ document->add(new QCLuceneField(TitleField, parsedTitle,
QCLuceneField::STORE_YES | QCLuceneField::INDEX_UNTOKENIZED));
- document->add(new QCLuceneField(QLatin1String("titleTokenized"), parsedTitle,
+ document->add(new QCLuceneField(TitleTokenizedField, parsedTitle,
QCLuceneField::STORE_YES | QCLuceneField::INDEX_TOKENIZED));
- document->add(new QCLuceneField(QLatin1String("namespace"), namespaceName,
+ document->add(new QCLuceneField(NamespaceField, namespaceName,
QCLuceneField::STORE_YES | QCLuceneField::INDEX_UNTOKENIZED));
- document->add(new QCLuceneField(QLatin1String("attribute"), attributes,
+ document->add(new QCLuceneField(AttributeField, attributes,
QCLuceneField::STORE_YES | QCLuceneField::INDEX_TOKENIZED));
return true;
}
@@ -613,67 +614,69 @@ void QHelpSearchIndexWriter::optimizeIndex()
void QHelpSearchIndexWriter::run()
{
- QMutexLocker mutexLocker(&mutex);
+#if !defined(QT_NO_EXCEPTIONS)
+ try {
+#endif
+ QMutexLocker mutexLocker(&mutex);
- if (m_cancel)
- return;
+ if (m_cancel)
+ return;
- const bool reindex = this->m_reindex;
- const QString collectionFile(this->m_collectionFile);
+ const bool reindex = this->m_reindex;
+ const QString collectionFile(this->m_collectionFile);
- mutexLocker.unlock();
+ mutexLocker.unlock();
- QHelpEngineCore engine(collectionFile, 0);
- if (!engine.setupData())
- return;
+ QHelpEngineCore engine(collectionFile, 0);
+ if (!engine.setupData())
+ return;
- const QLatin1String key("CluceneIndexedNamespaces");
- if (reindex)
- engine.setCustomValue(key, QLatin1String(""));
-
- QMap<QString, QDateTime> indexMap;
- const QLatin1String oldKey("CluceneSearchNamespaces");
- if (!engine.customValue(oldKey, QString()).isNull()) {
- // old style qhc file < 4.4.2, need to convert...
- const QStringList indexedNamespaces = engine.customValue(oldKey).
- toString().split(QLatin1String("|"), QString::SkipEmptyParts);
- foreach (const QString &nameSpace, indexedNamespaces)
- indexMap.insert(nameSpace, QDateTime());
- engine.removeCustomValue(oldKey);
- } else {
- QDataStream dataStream(engine.customValue(key).toByteArray());
- dataStream >> indexMap;
- }
+ const QLatin1String key("CluceneIndexedNamespaces");
+ if (reindex)
+ engine.setCustomValue(key, QLatin1String(""));
+
+ QMap<QString, QDateTime> indexMap;
+ const QLatin1String oldKey("CluceneSearchNamespaces");
+ if (!engine.customValue(oldKey, QString()).isNull()) {
+ // old style qhc file < 4.4.2, need to convert...
+ const QStringList indexedNamespaces
+ = engine.customValue(oldKey).toString()
+ .split(QLatin1String("|"), QString::SkipEmptyParts);
+ foreach (const QString &nameSpace, indexedNamespaces)
+ indexMap.insert(nameSpace, QDateTime());
+ engine.removeCustomValue(oldKey);
+ } else {
+ QDataStream dataStream(engine.customValue(key).toByteArray());
+ dataStream >> indexMap;
+ }
- QString indexPath = m_indexFilesFolder;
+ QString indexPath = m_indexFilesFolder;
- QFileInfo fInfo(indexPath);
- if (fInfo.exists() && !fInfo.isWritable()) {
- qWarning("Full Text Search, could not create index (missing permissions for '%s').", qPrintable(indexPath));
- return;
- }
+ QFileInfo fInfo(indexPath);
+ if (fInfo.exists() && !fInfo.isWritable()) {
+ qWarning("Full Text Search, could not create index (missing permissions for '%s').",
+ qPrintable(indexPath));
+ return;
+ }
- emit indexingStarted();
+ emit indexingStarted();
- QCLuceneIndexWriter *writer = 0;
- QCLuceneStandardAnalyzer analyzer;
- const QStringList registeredDocs = engine.registeredDocumentations();
+ QCLuceneIndexWriter *writer = 0;
+ QCLuceneStandardAnalyzer analyzer;
+ const QStringList registeredDocs = engine.registeredDocumentations();
- QLocalSocket localSocket;
- localSocket.connectToServer(QString(QLatin1String("QtAssistant%1"))
- .arg(QLatin1String(QT_VERSION_STR)));
+ QLocalSocket localSocket;
+ localSocket.connectToServer(QString(QLatin1String("QtAssistant%1"))
+ .arg(QLatin1String(QT_VERSION_STR)));
- QLocalServer localServer;
- bool otherInstancesRunning = true;
- if (!localSocket.waitForConnected()) {
- otherInstancesRunning = false;
- localServer.listen(QString(QLatin1String("QtAssistant%1"))
- .arg(QLatin1String(QT_VERSION_STR)));
- }
+ QLocalServer localServer;
+ bool otherInstancesRunning = true;
+ if (!localSocket.waitForConnected()) {
+ otherInstancesRunning = false;
+ localServer.listen(QString(QLatin1String("QtAssistant%1"))
+ .arg(QLatin1String(QT_VERSION_STR)));
+ }
-#if !defined(QT_NO_EXCEPTIONS)
- try {
-#endif
// check if it's locked, and if the other instance is running
if (!otherInstancesRunning && QCLuceneIndexReader::isLocked(indexPath))
QCLuceneIndexReader::unlock(indexPath);
@@ -705,7 +708,8 @@ void QHelpSearchIndexWriter::run()
removeDocuments(indexPath, namespaceName);
} else {
QString path = engine.documentationFileName(namespaceName);
- if (indexMap.value(namespaceName) < QFileInfo(path).lastModified()) {
+ if (indexMap.value(namespaceName)
+ < QFileInfo(path).lastModified()) {
// make sure we remove some outdated indexed stuff
indexMap.remove(namespaceName);
removeDocuments(indexPath, namespaceName);
@@ -713,9 +717,7 @@ void QHelpSearchIndexWriter::run()
if (indexMap.contains(namespaceName)) {
// make sure we really have content indexed for namespace
- // NOTE: Extra variable just for GCC 3.3.5
- QLatin1String key("namespace");
- QCLuceneTermQuery query(QCLuceneTerm(key, namespaceName));
+ QCLuceneTermQuery query(QCLuceneTerm(NamespaceField, namespaceName));
QCLuceneIndexSearcher indexSearcher(indexPath);
QCLuceneHits hits = indexSearcher.search(query);
if (hits.length() <= 0)
@@ -728,94 +730,85 @@ void QHelpSearchIndexWriter::run()
indexMap.clear();
writer = new QCLuceneIndexWriter(indexPath, analyzer, true);
}
-#if !defined(QT_NO_EXCEPTIONS)
- } catch (...) {
- qWarning("Full Text Search, could not create index writer in '%s'.",
- qPrintable(indexPath));
- return;
- }
-#endif
-#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) {
- closeIndexWriter(writer);
- emit indexingFinished();
- return;
- }
- mutexLocker.unlock();
+ QStringList namespaces;
+ foreach(const QString &namespaceName, registeredDocs) {
+ mutexLocker.relock();
+ if (m_cancel) {
+ closeIndexWriter(writer);
+ emit indexingFinished();
+ return;
+ }
+ mutexLocker.unlock();
- namespaces.append(namespaceName);
- if (indexMap.contains(namespaceName))
- continue;
+ namespaces.append(namespaceName);
+ if (indexMap.contains(namespaceName))
+ continue;
- const QList<QStringList> attributeSets =
- engine.filterAttributeSets(namespaceName);
+ const QList<QStringList> attributeSets =
+ engine.filterAttributeSets(namespaceName);
- if (attributeSets.isEmpty()) {
- const QList<QUrl> docFiles = indexableFiles(&engine, namespaceName,
- QStringList());
- if (!addDocuments(docFiles, engine, QStringList(), namespaceName,
- writer, analyzer))
- break;
- } else {
- bool bail = false;
- foreach (const QStringList &attributes, attributeSets) {
- const QList<QUrl> docFiles = indexableFiles(&engine,
- namespaceName, attributes);
- if (!addDocuments(docFiles, engine, attributes, namespaceName,
- writer, analyzer)) {
- bail = true;
+ if (attributeSets.isEmpty()) {
+ const QList<QUrl> docFiles = indexableFiles(&engine, namespaceName,
+ QStringList());
+ if (!addDocuments(docFiles, engine, QStringList(), namespaceName,
+ writer, analyzer))
break;
+ } else {
+ bool bail = false;
+ foreach (const QStringList &attributes, attributeSets) {
+ const QList<QUrl> docFiles = indexableFiles(&engine,
+ namespaceName, attributes);
+ if (!addDocuments(docFiles, engine, attributes, namespaceName,
+ writer, analyzer)) {
+ bail = true;
+ break;
+ }
}
+ if (bail)
+ break;
}
- if (bail)
- break;
- }
- mutexLocker.relock();
- if (!m_cancel) {
- QString path(engine.documentationFileName(namespaceName));
- indexMap.insert(namespaceName, QFileInfo(path).lastModified());
- writeIndexMap(engine, indexMap);
+ mutexLocker.relock();
+ if (!m_cancel) {
+ QString path(engine.documentationFileName(namespaceName));
+ indexMap.insert(namespaceName, QFileInfo(path).lastModified());
+ writeIndexMap(engine, indexMap);
+ }
+ mutexLocker.unlock();
}
- mutexLocker.unlock();
- }
- closeIndexWriter(writer);
+ closeIndexWriter(writer);
- mutexLocker.relock();
- if (!m_cancel) {
- mutexLocker.unlock();
-
- QStringList indexedNamespaces = indexMap.keys();
- foreach(const QString &namespaceName, indexedNamespaces) {
- mutexLocker.relock();
- if (m_cancel)
- break;
+ mutexLocker.relock();
+ if (!m_cancel) {
mutexLocker.unlock();
- if (!namespaces.contains(namespaceName)) {
- indexMap.remove(namespaceName);
- writeIndexMap(engine, indexMap);
- removeDocuments(indexPath, namespaceName);
+ QStringList indexedNamespaces = indexMap.keys();
+ foreach(const QString &namespaceName, indexedNamespaces) {
+ mutexLocker.relock();
+ if (m_cancel)
+ break;
+ mutexLocker.unlock();
+
+ if (!namespaces.contains(namespaceName)) {
+ indexMap.remove(namespaceName);
+ writeIndexMap(engine, indexMap);
+ removeDocuments(indexPath, namespaceName);
+ }
}
}
+
+#if !defined(QT_NO_EXCEPTIONS)
+ } catch (...) {
+ qWarning("%s: Failed because of CLucene exception.", Q_FUNC_INFO);
}
+#endif
+
emit indexingFinished();
}
@@ -858,8 +851,7 @@ void QHelpSearchIndexWriter::removeDocuments(const QString &indexPath,
return;
QCLuceneIndexReader reader = QCLuceneIndexReader::open(indexPath);
- reader.deleteDocuments(QCLuceneTerm(QLatin1String("namespace"),
- namespaceName));
+ reader.deleteDocuments(QCLuceneTerm(NamespaceField, namespaceName));
reader.close();
}