File indexing completed on 2024-05-12 05:11:18
0001 /* 0002 * This file is part of the KDE Akonadi Search Project 0003 * SPDX-FileCopyrightText: 2013 Vishesh Handa <me@vhanda.in> 0004 * 0005 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 * 0007 */ 0008 0009 #pragma once 0010 0011 #include "resultiterator.h" 0012 #include "search_core_export.h" 0013 0014 #include <memory> 0015 0016 class QVariant; 0017 0018 namespace Akonadi 0019 { 0020 namespace Search 0021 { 0022 class Term; 0023 class QueryPrivate; 0024 0025 /** Search query. */ 0026 class AKONADI_SEARCH_CORE_EXPORT Query 0027 { 0028 public: 0029 Query(); 0030 Query(const Term &t); 0031 Query(const Query &rhs); 0032 ~Query(); 0033 0034 void setTerm(const Term &t); 0035 [[nodiscard]] Term term() const; 0036 0037 /** 0038 * Add a type to the results of the query. 0039 * 0040 * Each Item in the result must contain one of the types. 0041 * This is generally used to filter only Files, Emails, Tags, etc 0042 * 0043 * One can add multiple types in one go by separating individual types 0044 * with a '/'. Eg - "File/Audio". 0045 * 0046 * Please note that the types are ANDed together. So searching for "Image" 0047 * and "Video" will probably never return any results. Have a look at 0048 * KFileMetaData::TypeInfo for a list of type names. 0049 */ 0050 void addType(const QString &type); 0051 void addTypes(const QStringList &typeList); 0052 void setType(const QString &type); 0053 void setTypes(const QStringList &types); 0054 0055 [[nodiscard]] QStringList types() const; 0056 0057 /** 0058 * Set some text which should be used to search for Items. This 0059 * contain a single word or an entire sentence. 0060 * 0061 * Each search backend will interpret it in its own way, and try 0062 * to give the best possible results. 0063 */ 0064 void setSearchString(const QString &str); 0065 [[nodiscard]] QString searchString() const; 0066 0067 /** 0068 * Only a maximum of \p limit results will be returned. 0069 * By default the limit is 100000. 0070 */ 0071 void setLimit(uint limit); 0072 [[nodiscard]] uint limit() const; 0073 0074 void setOffset(uint offset); 0075 [[nodiscard]] uint offset() const; 0076 0077 /** 0078 * Filter the results in the specified date range. 0079 * 0080 * The year/month/day may be set to -1 in order to ignore it. 0081 */ 0082 void setDateFilter(int year, int month = -1, int day = -1); 0083 0084 [[nodiscard]] int yearFilter() const; 0085 [[nodiscard]] int monthFilter() const; 0086 [[nodiscard]] int dayFilter() const; 0087 0088 enum SortingOption { 0089 /** 0090 * The results are returned in the most efficient order. They can 0091 * be returned in any order. 0092 */ 0093 SortNone, 0094 0095 /** 0096 * The results are returned in the order the SearchStore decides 0097 * should be ideal. This criteria could be based on any factors. 0098 * Read the documentation for the corresponding search store. 0099 */ 0100 SortAuto, 0101 0102 /** 0103 * The results are returned based on the explicit property specified. 0104 * The implementation of this depends on the search store. 0105 */ 0106 SortProperty 0107 }; 0108 0109 void setSortingOption(SortingOption option); 0110 [[nodiscard]] SortingOption sortingOption() const; 0111 0112 /** 0113 * Sets the property that should be used for sorting. This automatically 0114 * set the sorting mechanism to SortProperty 0115 */ 0116 void setSortingProperty(const QString &property); 0117 [[nodiscard]] QString sortingProperty() const; 0118 0119 /** 0120 * Adds a custom option which any search backend could use 0121 * to configure the query result. 0122 * 0123 * Each backend has their own custom options which should be 0124 * looked up in their corresponding documentation 0125 */ 0126 void addCustomOption(const QString &option, const QVariant &value); 0127 void removeCustomOption(const QString &option); 0128 QVariant customOption(const QString &option) const; 0129 [[nodiscard]] QVariantMap customOptions() const; 0130 0131 [[nodiscard]] ResultIterator exec(); 0132 0133 [[nodiscard]] QByteArray toJSON() const; 0134 static Query fromJSON(const QByteArray &arr); 0135 0136 [[nodiscard]] QUrl toSearchUrl(const QString &title = QString()); 0137 static Query fromSearchUrl(const QUrl &url); 0138 static QString titleFromQueryUrl(const QUrl &url); 0139 0140 bool operator==(const Query &rhs) const; 0141 0142 Query &operator=(const Query &rhs); 0143 0144 private: 0145 std::unique_ptr<QueryPrivate> const d; 0146 }; 0147 } 0148 }