diff --git a/README.md b/README.md new file mode 100644 index 0000000..c9864b6 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Akonadi Search + +Xapian-based indexing and query infrastructure for Akonadi. diff --git a/core/query.h b/core/query.h index 3b4f682..975b247 100644 --- a/core/query.h +++ b/core/query.h @@ -1,164 +1,165 @@ /* * This file is part of the KDE Akonadi Search Project * Copyright (C) 2013 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . * */ #ifndef AKONADI_SEARCH_CORE_QUERY_H #define AKONADI_SEARCH_CORE_QUERY_H #include "search_core_export.h" #include "resultiterator.h" class QVariant; namespace Akonadi { namespace Search { class Term; +/** Search query. */ class AKONADI_SEARCH_CORE_EXPORT Query { public: Query(); Query(const Term &t); Query(const Query &rhs); ~Query(); void setTerm(const Term &t); Term term() const; /** * Add a type to the results of the query. * * Each Item in the result must contain one of the types. * This is generally used to filter only Files, Emails, Tags, etc * * One can add multiple types in one go by separating individual types * with a '/'. Eg - "File/Audio". * * Please note that the types are ANDed together. So searching for "Image" * and "Video" will probably never return any results. Have a look at * KFileMetaData::TypeInfo for a list of type names. */ void addType(const QString &type); void addTypes(const QStringList &typeList); void setType(const QString &type); void setTypes(const QStringList &types); QStringList types() const; /** * Set some text which should be used to search for Items. This * contain a single word or an entire sentence. * * Each search backend will interpret it in its own way, and try * to give the best possible results. */ void setSearchString(const QString &str); QString searchString() const; /** * Only a maximum of \p limit results will be returned. * By default the limit is 100000. */ void setLimit(uint limit); uint limit() const; void setOffset(uint offset); uint offset() const; /** * Filter the results in the specified date range. * * The year/month/day may be set to -1 in order to ignore it. */ void setDateFilter(int year, int month = -1, int day = -1); int yearFilter() const; int monthFilter() const; int dayFilter() const; enum SortingOption { /** * The results are returned in the most efficient order. They can * be returned in any order. */ SortNone, /** * The results are returned in the order the SearchStore decides * should be ideal. This criteria could be based on any factors. * Read the documentation for the corresponding search store. */ SortAuto, /** * The results are returned based on the explicit property specified. * The implementation of this depends on the search store. */ SortProperty }; void setSortingOption(SortingOption option); SortingOption sortingOption() const; /** * Sets the property that should be used for sorting. This automatically * set the sorting mechanism to SortProperty */ void setSortingProperty(const QString &property); QString sortingProperty() const; /** * Adds a custom option which any search backend could use * to configure the query result. * * Each backend has their own custom options which should be * looked up in their corresponding documentation */ void addCustomOption(const QString &option, const QVariant &value); void removeCustomOption(const QString &option); QVariant customOption(const QString &option) const; QVariantMap customOptions() const; ResultIterator exec(); QByteArray toJSON() const; static Query fromJSON(const QByteArray &arr); QUrl toSearchUrl(const QString &title = QString()); static Query fromSearchUrl(const QUrl &url); static QString titleFromQueryUrl(const QUrl &url); bool operator == (const Query &rhs) const; Query &operator=(const Query &rhs); private: class Private; Private *d; }; } } #endif // AKONADI_SEARCH_CORE_QUERY_H diff --git a/core/resultiterator.h b/core/resultiterator.h index 8f9e2b3..541e9aa 100644 --- a/core/resultiterator.h +++ b/core/resultiterator.h @@ -1,85 +1,86 @@ /* * This file is part of the KDE Akonadi Search Project * Copyright (C) 2013 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . * */ #ifndef AKONADI_SEARCH_CORE_RESULT_ITERATOR_H #define AKONADI_SEARCH_CORE_RESULT_ITERATOR_H #include "search_core_export.h" #include "searchstore.h" #include namespace Akonadi { namespace Search { class SearchStore; class Result; class Q_DECL_HIDDEN ResultIteratorPrivate : public QSharedData { public: ResultIteratorPrivate() : queryId(0) , store(nullptr) { } ~ResultIteratorPrivate() { if (store) { store->close(queryId); } } int queryId; SearchStore *store; }; +/** Result iterator. */ class AKONADI_SEARCH_CORE_EXPORT ResultIterator { public: ResultIterator(); ResultIterator(const ResultIterator &rhs); ~ResultIterator(); ResultIterator &operator=(const ResultIterator &other); // internal ResultIterator(int id, SearchStore *store); bool next(); QByteArray id() const; QUrl url() const; QString text() const; QString icon() const; private: QExplicitlySharedDataPointer d; }; } } #endif // AKONADI_SEARCH_CORE_RESULT_ITERATOR_H diff --git a/core/searchstore.h b/core/searchstore.h index 3b2bd8e..e1b0dd5 100644 --- a/core/searchstore.h +++ b/core/searchstore.h @@ -1,102 +1,104 @@ /* * This file is part of the KDE Akonadi Search Project * Copyright (C) 2013 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . * */ #ifndef AKONADI_SEARCH_CORE_SEARCHSTORE_H #define AKONADI_SEARCH_CORE_SEARCHSTORE_H #include #include #include #include #include "search_core_export.h" namespace Akonadi { +/** Akonadi search infrastructure. */ namespace Search { class Query; +/** Search store. */ class AKONADI_SEARCH_CORE_EXPORT SearchStore : public QObject { Q_OBJECT public: explicit SearchStore(QObject *parent = nullptr); ~SearchStore() override; /** * Override search stores for testing */ static void overrideSearchStores(const QList &overrideSearchStores); typedef QList< QSharedPointer > List; /** * Gives a list of available search stores. These stores must be managed and * deleted by the caller */ static List searchStores(); /** * Returns a list of types which can be searched for * in this store */ virtual QStringList types() = 0; /** * Executes the particular query synchronously. * * \return Returns a integer representating the integer */ virtual int exec(const Query &query) = 0; virtual bool next(int queryId) = 0; virtual void close(int queryId) = 0; virtual QByteArray id(int queryId) = 0; virtual QUrl url(int queryId); virtual QString text(int queryId); virtual QString icon(int queryId); virtual QString property(int queryId, const QString &propName); }; // // Convenience functions // inline QByteArray serialize(const QByteArray &namespace_, int id) { return namespace_ + ':' + QByteArray::number(id); } inline int deserialize(const QByteArray &namespace_, const QByteArray &str) { // The +1 is for the ':' return str.mid(namespace_.size() + 1).toInt(); } } // namespace Search } // namespace Akonadi Q_DECLARE_INTERFACE(Akonadi::Search::SearchStore, "org.kde.Akonadi.Search.SearchStore") #endif // AKONADI_SEARCH_CORE_SEARCHSTORE_H diff --git a/core/term.h b/core/term.h index 53dd114..4938e37 100644 --- a/core/term.h +++ b/core/term.h @@ -1,165 +1,166 @@ /* * This file is part of the KDE Akonadi Search Project * Copyright (C) 2013 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . * */ #ifndef AKONADI_SEARCH_CORE_TERM_H #define AKONADI_SEARCH_CORE_TERM_H #include "search_core_export.h" #include #include #include namespace Akonadi { namespace Search { +/** Search term. */ class AKONADI_SEARCH_CORE_EXPORT Term { public: enum Comparator { Auto, Equal, Contains, Greater, GreaterEqual, Less, LessEqual }; enum Operation { None, And, Or }; Term(); Term(const Term &t); /** * The Item must contain the property \p property */ Term(const QString &property); /** * The Item must contain the property \p property with * value \value. * * The default comparator is Auto which has the following behavior * For Strings - Contains * For DateTime - Contains * For any other type - Equals */ Term(const QString &property, const QVariant &value, Comparator c = Auto); /** * This term is a combination of other terms */ Term(Operation op); Term(Operation op, const Term &t); Term(Operation op, const QList &t); Term(const Term &lhs, Operation op, const Term &rhs); ~Term(); bool isValid() const; /** * Negate this term. Negation only applies for Equal or Contains * For other Comparators you must invert it yourself */ void setNegation(bool isNegated); bool negated() const; bool isNegated() const; void addSubTerm(const Term &term); void setSubTerms(const QList &terms); /** * Returns the first subTerm in the list of subTerms */ Term subTerm() const; QList subTerms() const; void setOperation(Operation op); Operation operation() const; bool isEmpty() const; bool empty() const; /** * Return the property this term is targeting */ QString property() const; void setProperty(const QString &property); QVariant value() const; void setValue(const QVariant &value); Comparator comparator() const; void setComparator(Comparator c); void setUserData(const QString &name, const QVariant &value); QVariant userData(const QString &name) const; QVariantMap toVariantMap() const; static Term fromVariantMap(const QVariantMap &map); bool operator == (const Term &rhs) const; Term &operator=(const Term &rhs); private: class Private; Private *d; }; inline Term operator &&(const Term &lhs, const Term &rhs) { Term t(Term::And); t.addSubTerm(lhs); t.addSubTerm(rhs); return t; } inline Term operator ||(const Term &lhs, const Term &rhs) { Term t(Term::Or); t.addSubTerm(lhs); t.addSubTerm(rhs); return t; } inline Term operator !(const Term &rhs) { Term t(rhs); t.setNegation(!rhs.isNegated()); return t; } } } AKONADI_SEARCH_CORE_EXPORT QDebug operator <<(QDebug d, const Akonadi::Search::Term &t); #endif // AKONADI_SEARCH_CORE_TERM_H diff --git a/lib/collectionquery.h b/lib/collectionquery.h index 4639343..db1cff3 100644 --- a/lib/collectionquery.h +++ b/lib/collectionquery.h @@ -1,81 +1,83 @@ /* * This file is part of the KDE Akonadi Search Project * Copyright (C) 2014 Christian Mollekopf * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . * */ #ifndef AKONADI_SEARCH_PIM_COLLECTION_QUERY_H #define AKONADI_SEARCH_PIM_COLLECTION_QUERY_H #include "search_pim_export.h" #include "query.h" #include "resultiterator.h" #include #include namespace Akonadi { namespace Search { +/** PIM specific search API. */ namespace PIM { +/** Collection query. */ class AKONADI_SEARCH_PIM_EXPORT CollectionQuery : public Query { public: CollectionQuery(); ~CollectionQuery() override; void setNamespace(const QStringList &ns); void setMimetype(const QStringList &mt); /** * Matches the string \p match in the name. */ void nameMatches(const QString &match); void identifierMatches(const QString &match); void pathMatches(const QString &match); void setLimit(int limit); int limit() const; /** * Execute the query and return an iterator to fetch * the results */ ResultIterator exec() override; /** * For testing */ void setDatabaseDir(const QString &dir); private: //@cond PRIVATE struct Private; Private *const d; //@endcond }; } } } #endif // AKONADI_SEARCH_PIM_COLLECTION_QUERY_H diff --git a/lib/contactcompleter.h b/lib/contactcompleter.h index 8dcfdb3..617266f 100644 --- a/lib/contactcompleter.h +++ b/lib/contactcompleter.h @@ -1,52 +1,53 @@ /* * This file is part of the KDE Akonadi Search Project * Copyright (C) 2013 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . * */ #ifndef AKONADI_SEARCH_PIM_CONTACTCOMPLETER_H #define AKONADI_SEARCH_PIM_CONTACTCOMPLETER_H #include #include "search_pim_export.h" namespace Akonadi { namespace Search { namespace PIM { // FIXME: Make this async!! +/** Contact completer. */ class AKONADI_SEARCH_PIM_EXPORT ContactCompleter { public: explicit ContactCompleter(const QString &prefix, int limit = 10); QStringList complete(); private: QString m_prefix; int m_limit; }; } } } #endif // AKONADI_SEARCH_PIM_CONTACTCOMPLETER_H diff --git a/lib/emailquery.h b/lib/emailquery.h index b3fd5c4..c939958 100644 --- a/lib/emailquery.h +++ b/lib/emailquery.h @@ -1,124 +1,125 @@ /* * This file is part of the KDE Akonadi Search Project * Copyright (C) 2013 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . * */ #ifndef AKONADI_SEARCH_PIM_EMAIL_QUERY_H #define AKONADI_SEARCH_PIM_EMAIL_QUERY_H #include "search_pim_export.h" #include "query.h" #include #include namespace Akonadi { namespace Search { namespace PIM { +/** Email query. */ class AKONADI_SEARCH_PIM_EXPORT EmailQuery : public Query { public: EmailQuery(); ~EmailQuery() override; enum OpType { OpAnd = 0, OpOr }; void setSplitSearchMatchString(bool split); void setSearchType(OpType op); void setInvolves(const QStringList &involves); void addInvolves(const QString &email); void setTo(const QStringList &to); void addTo(const QString &to); void setFrom(const QString &from); void addFrom(const QString &from); void setCc(const QStringList &cc); void addCc(const QString &cc); void setBcc(const QStringList &bcc); void addBcc(const QString &bcc); void setCollection(const QList &collections); void addCollection(Akonadi::Collection::Id id); /** * By default the importance is ignored */ void setImportant(bool important = true); /** * By default the read status is ignored */ void setRead(bool read = true); /** * By default the attachment status is ignored */ void setAttachment(bool hasAttachment = true); /** * Matches the string \p match anywhere in the entire email * body */ void matches(const QString &match); /** * Matches the string \p subjectMatch specifically in the * email subject */ void subjectMatches(const QString &subjectMatch); /** * Matches the string \p bodyMatch specifically in the body email */ void bodyMatches(const QString &bodyMatch); void setLimit(int limit); int limit() const; /** * Execute the query and return an iterator to fetch * the results */ ResultIterator exec() override; private: //@cond PRIVATE class Private; Private *const d; //@endcond }; } } } #endif // AKONADI_SEARCH_PIM_EMAIL_QUERY_H diff --git a/lib/indexeditems.h b/lib/indexeditems.h index e459b97..cba362a 100644 --- a/lib/indexeditems.h +++ b/lib/indexeditems.h @@ -1,63 +1,65 @@ /* * This file is part of the KDE Akonadi Search Project * Copyright (C) 2016-2019 Laurent Montel * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . * */ #ifndef INDEXEDITEMS_H #define INDEXEDITEMS_H #include #include "search_pim_export.h" #include namespace Akonadi { namespace Search { namespace PIM { class IndexedItemsPrivate; + +/** Indexed items. */ class AKONADI_SEARCH_PIM_EXPORT IndexedItems : public QObject { Q_OBJECT public: explicit IndexedItems(QObject *parent = nullptr); ~IndexedItems(); void setOverrideDbPrefixPath(const QString &path); qlonglong indexedItems(const qlonglong id); void findIndexedInDatabase(QSet &indexed, Akonadi::Collection::Id collectionId, const QString &dbPath); void findIndexed(QSet &indexed, Akonadi::Collection::Id collectionId); QString emailIndexingPath() const; QString collectionIndexingPath() const; QString calendarIndexingPath() const; QString akonotesIndexingPath() const; QString emailContactsIndexingPath() const; QString contactIndexingPath() const; private: IndexedItemsPrivate *const d; }; } } } #endif // INDEXEDITEMS_H diff --git a/lib/query.h b/lib/query.h index 0ce5d0c..58e3bb5 100644 --- a/lib/query.h +++ b/lib/query.h @@ -1,53 +1,54 @@ /* * This file is part of the KDE Akonadi Search Project * Copyright (C) 2013 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . * */ #ifndef AKONADI_SEARCH_PIM_QUERY_H #define AKONADI_SEARCH_PIM_QUERY_H #include "search_pim_export.h" #include namespace Akonadi { namespace Search { namespace PIM { class ResultIterator; +/** Query base class. */ class AKONADI_SEARCH_PIM_EXPORT Query { public: Query(); virtual ~Query(); virtual ResultIterator exec() = 0; static Query *fromJSON(const QByteArray &json); static QString defaultLocation(const QString &dbName); }; } } } #endif // AKONADI_SEARCH_PIM_QUERY_H diff --git a/lib/resultiterator.h b/lib/resultiterator.h index fe13da2..0400b2e 100644 --- a/lib/resultiterator.h +++ b/lib/resultiterator.h @@ -1,65 +1,66 @@ /* * This file is part of the KDE Akonadi Search Project * Copyright (C) 2013 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . * */ #ifndef AKONADI_SEARCH_PIM_RESULT_ITERATOR_H #define AKONADI_SEARCH_PIM_RESULT_ITERATOR_H #include "search_pim_export.h" #include namespace Akonadi { namespace Search { namespace PIM { class ContactQuery; class EmailQuery; class NoteQuery; +/** Result iterator. */ class AKONADI_SEARCH_PIM_EXPORT ResultIterator { public: ResultIterator(); ResultIterator(const ResultIterator &ri); ~ResultIterator(); Akonadi::Item::Id id(); bool next(); private: friend class ContactQuery; friend class EmailQuery; friend class NoteQuery; friend class CollectionQuery; class Private; Private *d; }; } } } #endif // AKONADI_SEARCH_PIM_RESULT_ITERATOR_H diff --git a/xapian/xapiandatabase.h b/xapian/xapiandatabase.h index bdc8280..2f1fa42 100644 --- a/xapian/xapiandatabase.h +++ b/xapian/xapiandatabase.h @@ -1,96 +1,97 @@ /* * Copyright (C) 2014 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #ifndef AKONADI_SEARCH_XAPIANDATABASE_H #define AKONADI_SEARCH_XAPIANDATABASE_H #include #include "search_xapian_export.h" #include #include #include namespace Akonadi { namespace Search { class XapianDocument; +/** Xapian database. */ class AKONADI_SEARCH_XAPIAN_EXPORT XapianDatabase { public: /** * Create the Xapian db at path \p path. The parameter \p * writeOnly locks the database as long as this object is * valid */ explicit XapianDatabase(const QString &path, bool writeOnly = false); ~XapianDatabase(); void replaceDocument(uint id, const Xapian::Document &doc); void replaceDocument(uint id, const XapianDocument &doc); void deleteDocument(uint id); /** * Commit all the pending changes. This may not commit * at this instance as the db might be locked by another process * It emits the committed signal on completion */ void commit(); XapianDocument document(uint id); /** * A pointer to the actual db. Only use this when doing queries */ Xapian::Database *db() { if (m_db) { m_db->reopen(); return m_db; } return &m_wDb; } /** * Returns true if the XapianDatabase has changes which need to * be committed */ bool haveChanges() const; private: Xapian::Database *m_db = nullptr; Xapian::WritableDatabase m_wDb; typedef QPair DocIdPair; QVector m_docsToAdd; QVector m_docsToRemove; std::string m_path; bool m_writeOnly = false; Xapian::WritableDatabase createWritableDb(); }; } } #endif // AKONADI_SEARCH_XAPIANDATABASE_H diff --git a/xapian/xapianqueryparser.h b/xapian/xapianqueryparser.h index 59a0732..42ec8eb 100644 --- a/xapian/xapianqueryparser.h +++ b/xapian/xapianqueryparser.h @@ -1,61 +1,62 @@ /* * * Copyright (C) 2014 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #ifndef AKONADI_SEARCH_XAPIAN_QUERYPARSER_H #define AKONADI_SEARCH_XAPIAN_QUERYPARSER_H #include #include #include "search_xapian_export.h" namespace Akonadi { namespace Search { +/** Xapian query parser. */ class AKONADI_SEARCH_XAPIAN_EXPORT XapianQueryParser { public: XapianQueryParser(); void setDatabase(Xapian::Database *db); Xapian::Query parseQuery(const QString &str, const QString &prefix = QString()); /** * Expands word to every possible option which it can be expanded to. */ Xapian::Query expandWord(const QString &word, const QString &prefix = QString()); /** * Set if each word in the string should be treated as a partial word * and should be expanded to every possible word. */ void setAutoExapand(bool autoexpand); private: Xapian::Database *m_db = nullptr; bool m_autoExpand; }; } } #endif // AKONADI_SEARCH_XAPIAN_QUERYPARSER_H diff --git a/xapian/xapiantermgenerator.h b/xapian/xapiantermgenerator.h index 3ff6bc6..098add8 100644 --- a/xapian/xapiantermgenerator.h +++ b/xapian/xapiantermgenerator.h @@ -1,57 +1,58 @@ /* * * Copyright (C) 2014 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #ifndef AKONADI_SEARCH_XAPIAN_TERMGENERATOR_H #define AKONADI_SEARCH_XAPIAN_TERMGENERATOR_H #include #include #include "search_xapian_export.h" namespace Akonadi { namespace Search { +/** Xapian term generator. */ class AKONADI_SEARCH_XAPIAN_EXPORT XapianTermGenerator { public: explicit XapianTermGenerator(Xapian::Document *doc); void indexText(const QString &text); void indexText(const QString &text, const QString &prefix, int wdfInc = 1); void setPosition(int position); int position() const; void setDocument(Xapian::Document *doc); static QStringList termList(const QString &text); private: Xapian::Document *m_doc = nullptr; Xapian::TermGenerator m_termGen; int m_position; }; } } #endif // AKONADI_SEARCH_XAPIAN_TERMGENERATOR_H