equal
deleted
inserted
replaced
1 /**************************************************************************** |
1 /**************************************************************************** |
2 ** |
2 ** |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
4 ** All rights reserved. |
4 ** All rights reserved. |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
6 ** |
6 ** |
7 ** This file is part of the Qt Assistant of the Qt Toolkit. |
7 ** This file is part of the Qt Assistant of the Qt Toolkit. |
8 ** |
8 ** |
53 #include <QtCore/QTextCodec> |
53 #include <QtCore/QTextCodec> |
54 #include <QtCore/QTextStream> |
54 #include <QtCore/QTextStream> |
55 |
55 |
56 QT_BEGIN_NAMESPACE |
56 QT_BEGIN_NAMESPACE |
57 |
57 |
58 namespace qt { |
58 namespace fulltextsearch { |
59 namespace fulltextsearch { |
59 namespace std { |
60 namespace std { |
|
61 |
60 |
62 Writer::Writer(const QString &path) |
61 Writer::Writer(const QString &path) |
63 : indexPath(path) |
62 : indexPath(path) |
64 , indexFile(QString()) |
63 , indexFile(QString()) |
65 , documentFile(QString()) |
64 , documentFile(QString()) |
102 QFile docFile(documentFile); |
101 QFile docFile(documentFile); |
103 if (!(status = docFile.open(QFile::WriteOnly))) |
102 if (!(status = docFile.open(QFile::WriteOnly))) |
104 return status; |
103 return status; |
105 |
104 |
106 QDataStream docStream(&docFile); |
105 QDataStream docStream(&docFile); |
107 foreach(const QStringList list, documentList) { |
106 foreach(const QStringList &list, documentList) { |
108 docStream << list.at(0); |
107 docStream << list.at(0); |
109 docStream << list.at(1); |
108 docStream << list.at(1); |
110 } |
109 } |
111 docFile.close(); |
110 docFile.close(); |
112 |
111 |
124 docFile.remove(); |
123 docFile.remove(); |
125 } |
124 } |
126 |
125 |
127 void Writer::setIndexFile(const QString &namespaceName, const QString &attributes) |
126 void Writer::setIndexFile(const QString &namespaceName, const QString &attributes) |
128 { |
127 { |
129 QString extention = namespaceName + QLatin1String("@") + attributes; |
128 QString extension = namespaceName + QLatin1String("@") + attributes; |
130 indexFile = indexPath + QLatin1String("/indexdb40.") + extention; |
129 indexFile = indexPath + QLatin1String("/indexdb40.") + extension; |
131 documentFile = indexPath + QLatin1String("/indexdoc40.") + extention; |
130 documentFile = indexPath + QLatin1String("/indexdoc40.") + extension; |
132 } |
131 } |
133 |
132 |
134 void Writer::insertInIndex(const QString &string, int docNum) |
133 void Writer::insertInIndex(const QString &string, int docNum) |
135 { |
134 { |
136 if (string == QLatin1String("amp") || string == QLatin1String("nbsp")) |
135 if (string == QLatin1String("amp") || string == QLatin1String("nbsp")) |
190 this->m_cancel = false; |
189 this->m_cancel = false; |
191 this->m_reindex = reindex; |
190 this->m_reindex = reindex; |
192 this->m_collectionFile = collectionFile; |
191 this->m_collectionFile = collectionFile; |
193 this->m_indexFilesFolder = indexFilesFolder; |
192 this->m_indexFilesFolder = indexFilesFolder; |
194 |
193 |
195 start(QThread::NormalPriority); |
194 start(QThread::LowestPriority); |
196 } |
195 } |
197 |
196 |
198 void QHelpSearchIndexWriter::run() |
197 void QHelpSearchIndexWriter::run() |
199 { |
198 { |
200 mutex.lock(); |
199 mutex.lock(); |
224 |
223 |
225 emit indexingStarted(); |
224 emit indexingStarted(); |
226 |
225 |
227 QStringList namespaces; |
226 QStringList namespaces; |
228 Writer writer(indexPath); |
227 Writer writer(indexPath); |
229 foreach(const QString namespaceName, registeredDocs) { |
228 foreach(const QString &namespaceName, registeredDocs) { |
230 mutex.lock(); |
229 mutex.lock(); |
231 if (m_cancel) { |
230 if (m_cancel) { |
232 mutex.unlock(); |
231 mutex.unlock(); |
233 return; |
232 return; |
234 } |
233 } |
240 continue; |
239 continue; |
241 |
240 |
242 const QList<QStringList> attributeSets = |
241 const QList<QStringList> attributeSets = |
243 engine.filterAttributeSets(namespaceName); |
242 engine.filterAttributeSets(namespaceName); |
244 |
243 |
245 foreach (QStringList attributes, attributeSets) { |
244 foreach (const QStringList &attributes, attributeSets) { |
246 // cleanup maybe old or unfinished files |
245 // cleanup maybe old or unfinished files |
247 writer.setIndexFile(namespaceName, attributes.join(QLatin1String("@"))); |
246 writer.setIndexFile(namespaceName, attributes.join(QLatin1String("@"))); |
248 writer.removeIndex(); |
247 writer.removeIndex(); |
249 |
248 |
250 QSet<QString> documentsSet; |
249 QSet<QString> documentsSet; |
264 documentsSet.insert(s); |
263 documentsSet.insert(s); |
265 } |
264 } |
266 |
265 |
267 int docNum = 0; |
266 int docNum = 0; |
268 const QStringList documentsList(documentsSet.toList()); |
267 const QStringList documentsList(documentsSet.toList()); |
269 foreach(const QString url, documentsList) { |
268 foreach(const QString &url, documentsList) { |
270 if (m_cancel) |
269 if (m_cancel) |
271 return; |
270 return; |
272 |
271 |
273 QByteArray data(engine.fileData(url)); |
272 QByteArray data(engine.fileData(url)); |
274 if (data.isEmpty()) |
273 if (data.isEmpty()) |
345 continue; |
344 continue; |
346 |
345 |
347 const QList<QStringList> attributeSets = |
346 const QList<QStringList> attributeSets = |
348 engine.filterAttributeSets(namespaceName); |
347 engine.filterAttributeSets(namespaceName); |
349 |
348 |
350 foreach (QStringList attributes, attributeSets) { |
349 foreach (const QStringList &attributes, attributeSets) { |
351 writer.setIndexFile(namespaceName, attributes.join(QLatin1String("@"))); |
350 writer.setIndexFile(namespaceName, attributes.join(QLatin1String("@"))); |
352 writer.removeIndex(); |
351 writer.removeIndex(); |
353 } |
352 } |
354 |
353 |
355 engine.setCustomValue(key, removeNamespace( |
354 engine.setCustomValue(key, removeNamespace( |
377 value.remove(namespaceName + QLatin1String("|")); |
376 value.remove(namespaceName + QLatin1String("|")); |
378 |
377 |
379 return value; |
378 return value; |
380 } |
379 } |
381 |
380 |
382 } // namespace std |
381 } // namespace std |
383 } // namespace fulltextsearch |
382 } // namespace fulltextsearch |
384 } // namespace qt |
|
385 |
383 |
386 QT_END_NAMESPACE |
384 QT_END_NAMESPACE |