Akonadi::ItemSearchJob Class

class Akonadi::ItemSearchJob

Job that searches for items in the Akonadi storage. More...

Header: #include <Akonadi/ItemSearchJob>
CMake: find_package(KPim6 REQUIRED COMPONENTS AkonadiCore)
target_link_libraries(mytarget PRIVATE KPim6::AkonadiCore)
Inherits: Akonadi::Job

Public Functions

ItemSearchJob(QObject *parent = nullptr)
ItemSearchJob(const Akonadi::SearchQuery &query, QObject *parent = nullptr)
virtual ~ItemSearchJob() override
Akonadi::ItemFetchScope &fetchScope()
bool isRecursive() const
bool isRemoteSearchEnabled() const
Akonadi::Item::List items() const
QStringList mimeTypes() const
Akonadi::Collection::List searchCollections() const
void setFetchScope(const Akonadi::ItemFetchScope &fetchScope)
void setMimeTypes(const QStringList &mimeTypes)
void setQuery(const Akonadi::SearchQuery &query)
void setRecursive(bool recursive)
void setRemoteSearchEnabled(bool enabled)
void setSearchCollections(const Akonadi::Collection::List &collections)
void setTagFetchScope(const Akonadi::TagFetchScope &fetchScope)
Akonadi::TagFetchScope &tagFetchScope()

Signals

void itemsReceived(const Akonadi::Item::List &items)

Detailed Description

This job searches for items that match a given search query and returns the list of matching item.

 SearchQuery query;
 query.addTerm(SearchTerm("From", "user1@domain.example", SearchTerm::CondEqual));
 query.addTerm(SearchTerm("Date", QDateTime(QDate( 2014, 01, 27), QTime(00, 00, 00)), SearchTerm::CondGreaterThan);

 auto job = new Akonadi::ItemSearchJob(query);
 job->fetchScope().fetchFullPayload();
 connect(job, &Akonadi::ItemSearchJob::result, this, &MyClass::searchResult));

 ...

 MyClass::searchResult(KJob *job)
 {
   auto searchJob = qobject_cast<Akonadi::ItemSearchJob*>(job);
   const Akonadi::Item::List items = searchJob->items();
   for (const Akonadi::Item &item : items) {
     // extract the payload and do further stuff
   }
 }

Author: Tobias Koenig <tokoe@kde.org>

Member Function Documentation

[explicit] ItemSearchJob::ItemSearchJob(QObject *parent = nullptr)

Creates an invalid search job.

parent The parent object.

[explicit] ItemSearchJob::ItemSearchJob(const Akonadi::SearchQuery &query, QObject *parent = nullptr)

Creates an item search job.

query The search query. parent The parent object.

[override virtual noexcept] ItemSearchJob::~ItemSearchJob()

Destroys the item search job.

Akonadi::ItemFetchScope &ItemSearchJob::fetchScope()

Returns the item fetch scope.

Since this returns a reference it can be used to conveniently modify the current scope in-place, i.e. by calling a method on the returned reference without storing it in a local variable. See the ItemFetchScope documentation for an example.

Returns a reference to the current item fetch scope

See also setFetchScope(), for, replacing, the, current, item, fetch, and scope.

bool ItemSearchJob::isRecursive() const

Returns whether the search is recursive

bool ItemSearchJob::isRemoteSearchEnabled() const

Returns whether remote search is enabled.

Akonadi::Item::List ItemSearchJob::items() const

Returns the items that matched the search query.

[signal] void ItemSearchJob::itemsReceived(const Akonadi::Item::List &items)

This signal is emitted whenever new matching items have been fetched completely.

Note: This is an optimization, instead of waiting for the end of the job and calling items(), you can connect to this signal and get the items incrementally.

items The matching items.

QStringList ItemSearchJob::mimeTypes() const

Returns list of mime types to search in

See also setMimeTypes().

Akonadi::Collection::List ItemSearchJob::searchCollections() const

Returns list of collections to search.

This list does not include child collections that will be searched when recursive search is enabled

See also setSearchCollections().

void ItemSearchJob::setFetchScope(const Akonadi::ItemFetchScope &fetchScope)

Sets the item fetch scope.

The ItemFetchScope controls how much of an matching item's data is fetched from the server, e.g. whether to fetch the full item payload or only meta data.

fetchScope The new scope for item fetch operations.

See also fetchScope().

void ItemSearchJob::setMimeTypes(const QStringList &mimeTypes)

Search only for items of given mime types.

See also mimeTypes().

void ItemSearchJob::setQuery(const Akonadi::SearchQuery &query)

Sets the search query.

void ItemSearchJob::setRecursive(bool recursive)

Sets whether the search should recurse into collections

When set to true, all child collections of the specific collections will be search recursively.

recursive Whether to search recursively

See also isRecursive().

void ItemSearchJob::setRemoteSearchEnabled(bool enabled)

Sets whether resources should be queried too.

When set to true, Akonadi will search local indexed items and will also query resources that support server-side search, to forward the query to remote storage (for example using SEARCH feature on IMAP servers) and merge their results with results from local index.

This is useful especially when searching resources, that don't fetch full payload by default, for example the IMAP resource, which only fetches headers by default and the body is fetched on demand, which means that emails that were not yet fully fetched cannot be indexed in local index, and thus cannot be searched. With remote search, even those emails can be included in search results.

This feature is disabled by default.

Results are streamed back to client as they are received from queried sources, so this job can take some time to finish, but will deliver initial results from local index fairly quickly.

enabled Whether remote search is enabled

See also isRemoteSearchEnabled().

void ItemSearchJob::setSearchCollections(const Akonadi::Collection::List &collections)

Search only in given collections.

When recursive search is enabled, all child collections of each specified collection will be searched too

By default all collections are be searched.

collections Collections to search

See also searchCollections().

void ItemSearchJob::setTagFetchScope(const Akonadi::TagFetchScope &fetchScope)

Sets the tag fetch scope.

The tag fetch scope affects what scope of tags for each Item will be retrieved.

See also tagFetchScope().

Akonadi::TagFetchScope &ItemSearchJob::tagFetchScope()

Returns the tag fetch scope.

Since this returns a reference it can be used to conveniently modify the current scope in-place.

See also setTagFetchScope().