summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/assistant/lib/qhelpsearchengine.cpp10
-rw-r--r--tools/assistant/lib/qhelpsearchindexreader_clucene.cpp21
-rw-r--r--tools/assistant/lib/qhelpsearchindexreader_clucene_p.h5
3 files changed, 21 insertions, 15 deletions
diff --git a/tools/assistant/lib/qhelpsearchengine.cpp b/tools/assistant/lib/qhelpsearchengine.cpp
index 9faafe0..15f7f9e 100644
--- a/tools/assistant/lib/qhelpsearchengine.cpp
+++ b/tools/assistant/lib/qhelpsearchengine.cpp
@@ -96,6 +96,7 @@ private:
delete indexWriter;
}
+
int hitsCount() const
{
int count = 0;
@@ -107,12 +108,9 @@ private:
QList<QHelpSearchEngine::SearchHit> hits(int start, int end) const
{
- QList<QHelpSearchEngine::SearchHit> returnValue;
- if (indexReader) {
- for (int i = start; i < end && i < hitsCount(); ++i)
- returnValue.append(indexReader->hit(i));
- }
- return returnValue;
+ return indexReader ?
+ indexReader->hits(start, end) :
+ QList<QHelpSearchEngine::SearchHit>();
}
void updateIndex(bool reindex = false)
diff --git a/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp b/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp
index 227e558..867e060 100644
--- a/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp
+++ b/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp
@@ -86,8 +86,8 @@ void QHelpSearchIndexReader::cancelSearching()
void QHelpSearchIndexReader::search(const QString &collectionFile, const QString &indexFilesFolder,
const QList<QHelpSearchQuery> &queryList)
{
- QMutexLocker lock(&mutex);
-
+ wait();
+
this->hitList.clear();
this->m_cancel = false;
this->m_query = queryList;
@@ -99,12 +99,18 @@ void QHelpSearchIndexReader::search(const QString &collectionFile, const QString
int QHelpSearchIndexReader::hitsCount() const
{
+ QMutexLocker lock(&mutex);
return hitList.count();
}
-QHelpSearchEngine::SearchHit QHelpSearchIndexReader::hit(int index) const
+QList<QHelpSearchEngine::SearchHit> QHelpSearchIndexReader::hits(int start,
+ int end) const
{
- return hitList.at(index);
+ QList<QHelpSearchEngine::SearchHit> hits;
+ QMutexLocker lock(&mutex);
+ for (int i = start; i < end && i < hitList.count(); ++i)
+ hits.append(hitList.at(i));
+ return hits;
}
void QHelpSearchIndexReader::run()
@@ -135,7 +141,7 @@ void QHelpSearchIndexReader::run()
if(QCLuceneIndexReader::indexExists(indexPath)) {
mutex.lock();
if (m_cancel) {
- mutex.unlock();
+ mutex.unlock();
return;
}
mutex.unlock();
@@ -213,7 +219,9 @@ void QHelpSearchIndexReader::run()
#if !defined(QT_NO_EXCEPTIONS)
} catch(...) {
+ mutex.lock();
hitList.clear();
+ mutex.unlock();
emit searchingFinished(0);
}
#endif
@@ -416,8 +424,9 @@ void QHelpSearchIndexReader::boostSearchHits(const QHelpEngineCore &engine,
boostedList.append(it.value());
} while (it != hitMap.constBegin());
boostedList += hitList.mid(count, hitList.count());
-
+ mutex.lock();
hitList = boostedList;
+ mutex.unlock();
}
}
diff --git a/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h b/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h
index 47af43f..e7ac0eb 100644
--- a/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h
+++ b/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h
@@ -85,9 +85,8 @@ public:
void search(const QString &collectionFile,
const QString &indexFilesFolder,
const QList<QHelpSearchQuery> &queryList);
-
int hitsCount() const;
- QHelpSearchEngine::SearchHit hit(int index) const;
+ QList<QHelpSearchEngine::SearchHit> hits(int start, int end) const;
signals:
void searchingStarted();
@@ -105,7 +104,7 @@ private:
const QList<QHelpSearchQuery> &queryList);
private:
- QMutex mutex;
+ mutable QMutex mutex;
QList<QHelpSearchEngine::SearchHit> hitList;
QWaitCondition waitCondition;