File indexing completed on 2024-04-28 07:40:11
0001 /* 0002 This file is part of the KDE Baloo Project 0003 SPDX-FileCopyrightText: 2013-2015 Vishesh Handa <vhanda@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 #ifndef BALOO_QUERY_H 0009 #define BALOO_QUERY_H 0010 0011 #include "core_export.h" 0012 #include "resultiterator.h" 0013 0014 #include <QUrl> 0015 0016 #include <memory> 0017 0018 namespace Baloo { 0019 0020 /** 0021 * @class Query query.h <Baloo/Query> 0022 * 0023 * The Query class is the central class to query to search for files from the Index. 0024 * 0025 * This class has an inbuilt parser which recognizes words along with AND / OR and parenthesis 0026 * and specific properties. This can be used with the setSearchString method 0027 * 0028 * @example - 0029 * "Fire" -> Looks for all files which contain the word "Fire" 0030 * 0031 * @example - 0032 * "Fire OR water" -> Looks for files which contain either "Fire" or "Water". The capitalization 0033 * of the words doesn't matter as that will be ignored internally. However, OR and AND have to 0034 * be in upper case. 0035 * 0036 * @example - 0037 * "artist:Coldplay" -> Look for any files with the artist "Coldplay" 0038 * 0039 * @example - 0040 * "artist:(Coldplay OR Maroon5) power" -> Look for files with the artist Coldplay or Maroon5 and 0041 * the word "power" 0042 * 0043 * @example - 0044 * "artist:'Noah and the Whale'" -> Look for files with the artist "Noah and the Whale" 0045 * 0046 * @example - 0047 * "type:Audio title:Fix" -> Look for Audio files which contains the title "Fix" in its title. 0048 * 0049 * The Query Parser recognizes a large number of properties. These property names can be looked 0050 * up in KFileMetaData::Property::Property. The type of the file can mentioned with the property 0051 * 'type' or 'kind'. 0052 */ 0053 class BALOO_CORE_EXPORT Query 0054 { 0055 public: 0056 Query(); 0057 Query(const Query& rhs); 0058 ~Query(); 0059 0060 /** 0061 * Add a type to the results of the query. 0062 * 0063 * Every file has a higher level type such as "Audio", "Video", "Image", "Document", etc. 0064 * 0065 * Please note that the types are ANDed together. So searching for "Image" 0066 * and "Video" will probably never return any results. Have a look at 0067 * KFileMetaData::TypeInfo for a list of type names. 0068 */ 0069 void addType(const QString& type); 0070 void addTypes(const QStringList& typeList); 0071 void setType(const QString& type); 0072 void setTypes(const QStringList& types); 0073 0074 QStringList types() const; 0075 0076 /** 0077 * Set some text which should be used to search for Items. This 0078 * contain a single word or an entire sentence. 0079 */ 0080 void setSearchString(const QString& str); 0081 QString searchString() const; 0082 0083 /** 0084 * Only a maximum of \p limit results will be returned. 0085 * By default the value is -1 0086 */ 0087 void setLimit(uint limit); 0088 uint limit() const; 0089 0090 void setOffset(uint offset); 0091 uint offset() const; 0092 0093 /** 0094 * Filter the results in the specified date range. 0095 * 0096 * The year/month/day may be set to 0 in order to ignore it. 0097 */ 0098 void setDateFilter(int year, int month = 0, int day = 0); 0099 0100 int yearFilter() const; 0101 int monthFilter() const; 0102 int dayFilter() const; 0103 0104 enum SortingOption { 0105 /** 0106 * The results are returned in the most efficient order. They can 0107 * be returned in any order. 0108 */ 0109 SortNone, 0110 0111 /** 0112 * The results are returned in the order Baloo decides 0113 * should be ideal. This criteria is based on the mtime of the 0114 * file. 0115 * 0116 * This is the default sorting mechanism. 0117 */ 0118 SortAuto, 0119 }; 0120 0121 void setSortingOption(SortingOption option); 0122 SortingOption sortingOption() const; 0123 0124 /** 0125 * Only files in this folder will be returned 0126 */ 0127 void setIncludeFolder(const QString& folder); 0128 QString includeFolder() const; 0129 0130 ResultIterator exec(); 0131 0132 QByteArray toJSON(); 0133 static Query fromJSON(const QByteArray& arr); 0134 0135 QUrl toSearchUrl(const QString& title = QString()); 0136 static Query fromSearchUrl(const QUrl& url); 0137 static QString titleFromQueryUrl(const QUrl& url); 0138 0139 bool operator == (const Query& rhs) const; 0140 bool operator != (const Query& rhs) const; 0141 0142 Query& operator=(const Query& rhs); 0143 0144 private: 0145 class Private; 0146 std::unique_ptr<Private> const d; 0147 }; 0148 0149 } 0150 #endif // BALOO_QUERY_H