7#include "searchrequest.h"
9#include "abstractsearchplugin.h"
11#include "akonadiserver_search_debug.h"
12#include "connection.h"
13#include "searchmanager.h"
14#include "searchtaskmanager.h"
16using namespace Akonadi::Server;
18SearchRequest::SearchRequest(
const QByteArray &connectionId,
SearchManager &searchManager, SearchTaskManager &agentSearchManager)
19 : mConnectionId(connectionId)
20 , mSearchManager(searchManager)
21 , mAgentSearchManager(agentSearchManager)
25SearchRequest::~SearchRequest()
29QByteArray SearchRequest::connectionId()
const
34void SearchRequest::setQuery(
const QString &query)
39QString SearchRequest::query()
const
44void SearchRequest::setCollections(
const QList<qint64> &collectionsIds)
46 mCollections = collectionsIds;
49QList<qint64> SearchRequest::collections()
const
54void SearchRequest::setMimeTypes(
const QStringList &mimeTypes)
56 mMimeTypes = mimeTypes;
59QStringList SearchRequest::mimeTypes()
const
64void SearchRequest::setRemoteSearch(
bool remote)
66 mRemoteSearch = remote;
69bool SearchRequest::remoteSearch()
const
74void SearchRequest::setStoreResults(
bool storeResults)
76 mStoreResults = storeResults;
79QSet<qint64> SearchRequest::results()
const
84void SearchRequest::emitResults(
const QSet<qint64> &results)
86 Q_EMIT resultsAvailable(results);
88 mResults.unite(results);
92void SearchRequest::searchPlugins()
94 const QList<AbstractSearchPlugin *> plugins = mSearchManager.searchPlugins();
95 for (AbstractSearchPlugin *plugin : plugins) {
96 const QSet<qint64> result = plugin->search(mQuery, mCollections, mMimeTypes);
101void SearchRequest::exec()
103 qCInfo(AKONADISERVER_SEARCH_LOG) <<
"Executing search" << mConnectionId;
110 if (!mRemoteSearch) {
111 qCInfo(AKONADISERVER_SEARCH_LOG) <<
"Search " << mConnectionId <<
"done (without remote search)";
116 task.id = mConnectionId;
118 task.mimeTypes = mMimeTypes;
119 task.collections = mCollections;
120 task.complete =
false;
122 mAgentSearchManager.addTask(&task);
124 task.sharedLock.lock();
130 task.notifier.wait(&
task.sharedLock);
132 qCDebug(AKONADISERVER_SEARCH_LOG) <<
task.pendingResults.count() <<
"search results available in search" <<
task.id;
133 if (!
task.pendingResults.isEmpty()) {
134 emitResults(
task.pendingResults);
136 task.pendingResults.clear();
139 if (!
task.pendingResults.isEmpty()) {
140 emitResults(
task.pendingResults);
142 task.sharedLock.unlock();
144 qCInfo(AKONADISERVER_SEARCH_LOG) <<
"Search" << mConnectionId <<
"done (with remote search)";
147#include "moc_searchrequest.cpp"
SearchManager creates and deletes persistent searches for all currently active search engines.
QTaskBuilder< Task > task(Task &&task)