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