From 303a3cf5ba48dd9857a1fb9600cedd604c71de8d Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 6 Dec 2015 19:01:03 +0100 Subject: Added TypeIndex A central location for all types to specify what properties are indexed, and how to query them. --- common/domain/mail.cpp | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'common/domain') diff --git a/common/domain/mail.cpp b/common/domain/mail.cpp index 0170357..1a877cb 100644 --- a/common/domain/mail.cpp +++ b/common/domain/mail.cpp @@ -29,41 +29,40 @@ #include "../propertymapper.h" #include "../query.h" #include "../definitions.h" +#include "../typeindex.h" #include "mail_generated.h" using namespace Akonadi2::ApplicationDomain; -ResultSet TypeImplementation::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction) +static TypeIndex &getIndex() { - QVector keys; - if (query.propertyFilter.contains("uid")) { - Index uidIndex("mail.index.uid", transaction); - uidIndex.lookup(query.propertyFilter.value("uid").toByteArray(), [&](const QByteArray &value) { - keys << value; - }, - [](const Index::Error &error) { - Warning() << "Error in uid index: " << error.message; - }); - appliedFilters << "uid"; + static TypeIndex *index = 0; + if (!index) { + index = new TypeIndex("mail"); + index->addProperty("uid"); + index->addProperty("sender"); + index->addProperty("senderName"); + index->addProperty("subject"); + index->addProperty("date"); } - return ResultSet(keys); + return *index; +} + +ResultSet TypeImplementation::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction) +{ + return getIndex().query(query, appliedFilters, transaction); } void TypeImplementation::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) { - const auto uid = bufferAdaptor.getProperty("uid"); - if (uid.isValid()) { - Index("mail.index.uid", transaction).add(uid.toByteArray(), identifier); - } + Trace() << "Indexing " << identifier; + getIndex().add(identifier, bufferAdaptor, transaction); } void TypeImplementation::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) { - const auto uid = bufferAdaptor.getProperty("uid"); - if (uid.isValid()) { - Index("mail.index.uid", transaction).remove(uid.toByteArray(), identifier); - } + getIndex().remove(identifier, bufferAdaptor, transaction); } QSharedPointer::Buffer> > TypeImplementation::initializeReadPropertyMapper() -- cgit v1.2.3