Akonadi

searchhandler.cpp
1/***************************************************************************
2 * SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org> *
3 * *
4 * SPDX-License-Identifier: LGPL-2.0-or-later *
5 ***************************************************************************/
6
7#include "searchhandler.h"
8
9#include "akonadi.h"
10#include "akonadiserver_search_debug.h"
11#include "connection.h"
12#include "handlerhelper.h"
13#include "itemfetchhelper.h"
14#include "search/agentsearchengine.h"
15#include "search/searchmanager.h"
16#include "search/searchrequest.h"
17#include "searchhelper.h"
18
19using namespace Akonadi;
20using namespace Akonadi::Server;
21
22SearchHandler::SearchHandler(AkonadiServer &akonadi)
23 : Handler(akonadi)
24{
25}
26
28{
29 const auto &cmd = Protocol::cmdCast<Protocol::SearchCommand>(m_command);
30
31 if (cmd.query().isEmpty()) {
32 return failureResponse("No query specified");
33 }
34
35 QList<qint64> collectionIds;
36 bool recursive = cmd.recursive();
37
38 if (cmd.collections().isEmpty() || cmd.collections() == QList<qint64>{0LL}) {
39 collectionIds << 0;
40 recursive = true;
41 }
42
43 QList<qint64> collections = collectionIds;
44 if (recursive) {
45 collections += SearchHelper::matchSubcollectionsByMimeType(collectionIds, cmd.mimeTypes());
46 }
47
48 qCDebug(AKONADISERVER_SEARCH_LOG) << "SEARCH:";
49 qCDebug(AKONADISERVER_SEARCH_LOG) << "\tQuery:" << cmd.query();
50 qCDebug(AKONADISERVER_SEARCH_LOG) << "\tMimeTypes:" << cmd.mimeTypes();
51 qCDebug(AKONADISERVER_SEARCH_LOG) << "\tCollections:" << collections;
52 qCDebug(AKONADISERVER_SEARCH_LOG) << "\tRemote:" << cmd.remote();
53 qCDebug(AKONADISERVER_SEARCH_LOG) << "\tRecursive" << recursive;
54
55 if (collections.isEmpty()) {
56 return successResponse<Protocol::SearchResponse>();
57 }
58
59 mItemFetchScope = cmd.itemFetchScope();
60 mTagFetchScope = cmd.tagFetchScope();
61
62 SearchRequest request(connection()->sessionId(), akonadi().searchManager(), akonadi().agentSearchManager());
63 request.setCollections(collections);
64 request.setMimeTypes(cmd.mimeTypes());
65 request.setQuery(cmd.query());
66 request.setRemoteSearch(cmd.remote());
67 QObject::connect(&request, &SearchRequest::resultsAvailable, &request, [this](const QSet<qint64> &results) {
68 processResults(results);
69 });
70 request.exec();
71
72 // qCDebug(AKONADISERVER_SEARCH_LOG) << "\tResult:" << uids;
73 qCDebug(AKONADISERVER_SEARCH_LOG) << "\tResult:" << mAllResults.count() << "matches";
74
75 return successResponse<Protocol::SearchResponse>();
76}
77
78void SearchHandler::processResults(const QSet<qint64> &results)
79{
80 QSet<qint64> newResults = results;
81 newResults.subtract(mAllResults);
82 mAllResults.unite(newResults);
83
84 if (newResults.isEmpty()) {
85 return;
86 }
87
88 Scope scope;
89 scope.setUidSet({newResults.begin(), newResults.end()});
90
91 ItemFetchHelper fetchHelper(connection(), scope, mItemFetchScope, mTagFetchScope, akonadi());
92 fetchHelper.fetchItems();
93}
The handler interfaces describes an entity capable of handling an AkonadiIMAP command.
Definition handler.h:32
bool parseStream() override
Parse and handle the IMAP message using the streaming parser.
Helper integration between Akonadi and Qt.
bool isEmpty() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
iterator begin()
qsizetype count() const const
iterator end()
bool isEmpty() const const
QSet< T > & subtract(const QSet< T > &other)
QSet< T > & unite(const QSet< T > &other)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:13:38 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.