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 ** |
50 #include <QtCore/QDataStream> |
50 #include <QtCore/QDataStream> |
51 #include <QtCore/QTextStream> |
51 #include <QtCore/QTextStream> |
52 |
52 |
53 QT_BEGIN_NAMESPACE |
53 QT_BEGIN_NAMESPACE |
54 |
54 |
55 namespace qt { |
55 namespace fulltextsearch { |
56 namespace fulltextsearch { |
56 namespace std { |
57 namespace std { |
|
58 |
57 |
59 namespace { |
58 namespace { |
60 QStringList split( const QString &str ) |
59 QStringList split( const QString &str ) |
61 { |
60 { |
62 QStringList lst; |
61 QStringList lst; |
164 searchIndexTable.clear(); |
163 searchIndexTable.clear(); |
165 for(IndexTable::ConstIterator it = indexTable.begin(); it != indexTable.end(); ++it) { |
164 for(IndexTable::ConstIterator it = indexTable.begin(); it != indexTable.end(); ++it) { |
166 const QString fileName = it.key(); |
165 const QString fileName = it.key(); |
167 bool containsAll = true; |
166 bool containsAll = true; |
168 QStringList split = fileName.split(QLatin1String("@")); |
167 QStringList split = fileName.split(QLatin1String("@")); |
169 foreach (const QString attribute, attributes) { |
168 foreach (const QString &attribute, attributes) { |
170 if (!split.contains(attribute, Qt::CaseInsensitive)) { |
169 if (!split.contains(attribute, Qt::CaseInsensitive)) { |
171 containsAll = false; |
170 containsAll = false; |
172 break; |
171 break; |
173 } |
172 } |
174 } |
173 } |
178 } |
177 } |
179 } |
178 } |
180 |
179 |
181 void Reader::setIndexFile(const QString &namespaceName, const QString &attributes) |
180 void Reader::setIndexFile(const QString &namespaceName, const QString &attributes) |
182 { |
181 { |
183 QString extention = namespaceName + QLatin1String("@") + attributes; |
182 QString extension = namespaceName + QLatin1String("@") + attributes; |
184 indexFile = indexPath + QLatin1String("/indexdb40.") + extention; |
183 indexFile = indexPath + QLatin1String("/indexdb40.") + extension; |
185 documentFile = indexPath + QLatin1String("/indexdoc40.") + extention; |
184 documentFile = indexPath + QLatin1String("/indexdoc40.") + extension; |
186 } |
185 } |
187 |
186 |
188 bool Reader::splitSearchTerm(const QString &searchTerm, QStringList *terms, |
187 bool Reader::splitSearchTerm(const QString &searchTerm, QStringList *terms, |
189 QStringList *termSeq, QStringList *seqWords) |
188 QStringList *termSeq, QStringList *seqWords) |
190 { |
189 { |
233 return true; |
232 return true; |
234 } |
233 } |
235 |
234 |
236 void Reader::searchInIndex(const QStringList &terms) |
235 void Reader::searchInIndex(const QStringList &terms) |
237 { |
236 { |
238 foreach (const QString term, terms) { |
237 foreach (const QString &term, terms) { |
239 QVector<Document> documents; |
238 QVector<Document> documents; |
240 |
239 |
241 for(IndexTable::ConstIterator it = searchIndexTable.begin(); |
240 for(IndexTable::ConstIterator it = searchIndexTable.begin(); |
242 it != searchIndexTable.end(); ++it) { |
241 it != searchIndexTable.end(); ++it) { |
243 EntryTable entryTable = it.value().first; |
242 EntryTable entryTable = it.value().first; |
252 |
251 |
253 if (!documents.isEmpty()) { |
252 if (!documents.isEmpty()) { |
254 DocumentInfo info; |
253 DocumentInfo info; |
255 QString title, url; |
254 QString title, url; |
256 QVector<DocumentInfo> documentsInfo; |
255 QVector<DocumentInfo> documentsInfo; |
257 foreach(const Document doc, documents) { |
256 foreach(const Document &doc, documents) { |
258 info.docNumber = doc.docNumber; |
257 info.docNumber = doc.docNumber; |
259 info.frequency = doc.frequency; |
258 info.frequency = doc.frequency; |
260 info.documentUrl = documentList.at(doc.docNumber).at(1); |
259 info.documentUrl = documentList.at(doc.docNumber).at(1); |
261 info.documentTitle = documentList.at(doc.docNumber).at(0); |
260 info.documentTitle = documentList.at(doc.docNumber).at(0); |
262 documentsInfo.append(info); |
261 documentsInfo.append(info); |
517 const QString indexPath = m_indexFilesFolder; |
516 const QString indexPath = m_indexFilesFolder; |
518 |
517 |
519 mutex.unlock(); |
518 mutex.unlock(); |
520 |
519 |
521 QString queryTerm; |
520 QString queryTerm; |
522 foreach (const QHelpSearchQuery query, queryList) { |
521 foreach (const QHelpSearchQuery &query, queryList) { |
523 if (query.fieldName == QHelpSearchQuery::DEFAULT) { |
522 if (query.fieldName == QHelpSearchQuery::DEFAULT) { |
524 queryTerm = query.wordList.at(0); |
523 queryTerm = query.wordList.at(0); |
525 break; |
524 break; |
526 } |
525 } |
527 } |
526 } |
539 |
538 |
540 emit searchingStarted(); |
539 emit searchingStarted(); |
541 |
540 |
542 // setup the reader |
541 // setup the reader |
543 m_reader.setIndexPath(indexPath); |
542 m_reader.setIndexPath(indexPath); |
544 foreach(const QString namespaceName, registeredDocs) { |
543 foreach(const QString &namespaceName, registeredDocs) { |
545 mutex.lock(); |
544 mutex.lock(); |
546 if (m_cancel) { |
545 if (m_cancel) { |
547 mutex.unlock(); |
546 mutex.unlock(); |
548 searchingFinished(0); // TODO: check this ??? |
547 searchingFinished(0); // TODO: check this ??? |
549 return; |
548 return; |
551 mutex.unlock(); |
550 mutex.unlock(); |
552 |
551 |
553 const QList<QStringList> attributeSets = |
552 const QList<QStringList> attributeSets = |
554 engine.filterAttributeSets(namespaceName); |
553 engine.filterAttributeSets(namespaceName); |
555 |
554 |
556 foreach (QStringList attributes, attributeSets) { |
555 foreach (const QStringList &attributes, attributeSets) { |
557 // read all index files |
556 // read all index files |
558 m_reader.setIndexFile(namespaceName, attributes.join(QLatin1String("@"))); |
557 m_reader.setIndexFile(namespaceName, attributes.join(QLatin1String("@"))); |
559 if (!m_reader.readIndex()) { |
558 if (!m_reader.readIndex()) { |
560 qWarning("Full Text Search, could not read file for namespace: %s.", |
559 qWarning("Full Text Search, could not read file for namespace: %s.", |
561 namespaceName.toUtf8().constData()); |
560 namespaceName.toUtf8().constData()); |
575 m_reader.searchInIndex(terms); // TODO: should this be interruptible as well ??? |
574 m_reader.searchInIndex(terms); // TODO: should this be interruptible as well ??? |
576 |
575 |
577 QVector<DocumentInfo> hits = m_reader.hits(); |
576 QVector<DocumentInfo> hits = m_reader.hits(); |
578 if (!hits.isEmpty()) { |
577 if (!hits.isEmpty()) { |
579 if (termSeq.isEmpty()) { |
578 if (termSeq.isEmpty()) { |
580 foreach (const DocumentInfo docInfo, hits) { |
579 foreach (const DocumentInfo &docInfo, hits) { |
581 mutex.lock(); |
580 mutex.lock(); |
582 if (m_cancel) { |
581 if (m_cancel) { |
583 mutex.unlock(); |
582 mutex.unlock(); |
584 searchingFinished(0); // TODO: check this, speed issue while locking??? |
583 searchingFinished(0); // TODO: check this, speed issue while locking??? |
585 return; |
584 return; |
586 } |
585 } |
587 mutex.unlock(); |
586 mutex.unlock(); |
588 hitList.append(qMakePair(docInfo.documentTitle, docInfo.documentUrl)); |
587 hitList.append(qMakePair(docInfo.documentTitle, docInfo.documentUrl)); |
589 } |
588 } |
590 } else { |
589 } else { |
591 foreach (const DocumentInfo docInfo, hits) { |
590 foreach (const DocumentInfo &docInfo, hits) { |
592 mutex.lock(); |
591 mutex.lock(); |
593 if (m_cancel) { |
592 if (m_cancel) { |
594 mutex.unlock(); |
593 mutex.unlock(); |
595 searchingFinished(0); // TODO: check this, speed issue while locking??? |
594 searchingFinished(0); // TODO: check this, speed issue while locking??? |
596 return; |
595 return; |
605 } |
604 } |
606 |
605 |
607 emit searchingFinished(hitList.count()); |
606 emit searchingFinished(hitList.count()); |
608 } |
607 } |
609 |
608 |
610 } // namespace std |
609 } // namespace std |
611 } // namespace fulltextsearch |
610 } // namespace fulltextsearch |
612 } // namespace qt |
|
613 |
611 |
614 QT_END_NAMESPACE |
612 QT_END_NAMESPACE |