Baloo

query.h
1 /*
2  This file is part of the KDE Baloo Project
3  SPDX-FileCopyrightText: 2013-2015 Vishesh Handa <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7 
8 #ifndef BALOO_QUERY_H
9 #define BALOO_QUERY_H
10 
11 #include "core_export.h"
12 #include "resultiterator.h"
13 
14 #include <QUrl>
15 
16 namespace Baloo {
17 
18 /**
19  * @class Query query.h <Baloo/Query>
20  *
21  * The Query class is the central class to query to search for files from the Index.
22  *
23  * This class has an inbuilt parser which recognizes words along with AND / OR and parenthesis
24  * and specific properties. This can be used with the setSearchString method
25  *
26  * @example -
27  * "Fire" -> Looks for all files which contain the word "Fire"
28  *
29  * @example -
30  * "Fire OR water" -> Looks for files which contain either "Fire" or "Water". The capitalization
31  * of the words doesn't matter as that will be ignored internally. However, OR and AND have to
32  * be in upper case.
33  *
34  * @example -
35  * "artist:Coldplay" -> Look for any files with the artist "Coldplay"
36  *
37  * @example -
38  * "artist:(Coldplay OR Maroon5) power" -> Look for files with the artist Coldplay or Maroon5 and
39  * the word "power"
40  *
41  * @example -
42  * "artist:'Noah and the Whale'" -> Look for files with the artist "Noah and the Whale"
43  *
44  * @example -
45  * "type:Audio title:Fix" -> Look for Audio files which contains the title "Fix" in its title.
46  *
47  * The Query Parser recognizes a large number of properties. These property names can be looked
48  * up in KFileMetaData::Property::Property. The type of the file can mentioned with the property
49  * 'type' or 'kind'.
50  */
51 class BALOO_CORE_EXPORT Query
52 {
53 public:
54  Query();
55  Query(const Query& rhs);
56  ~Query();
57 
58  /**
59  * Add a type to the results of the query.
60  *
61  * Every file has a higher level type such as "Audio", "Video", "Image", "Document", etc.
62  *
63  * Please note that the types are ANDed together. So searching for "Image"
64  * and "Video" will probably never return any results. Have a look at
65  * KFileMetaData::TypeInfo for a list of type names.
66  */
67  void addType(const QString& type);
68  void addTypes(const QStringList& typeList);
69  void setType(const QString& type);
70  void setTypes(const QStringList& types);
71 
72  QStringList types() const;
73 
74  /**
75  * Set some text which should be used to search for Items. This
76  * contain a single word or an entire sentence.
77  */
78  void setSearchString(const QString& str);
79  QString searchString() const;
80 
81  /**
82  * Only a maximum of \p limit results will be returned.
83  * By default the value is -1
84  */
85  void setLimit(uint limit);
86  uint limit() const;
87 
88  void setOffset(uint offset);
89  uint offset() const;
90 
91  /**
92  * Filter the results in the specified date range.
93  *
94  * The year/month/day may be set to 0 in order to ignore it.
95  */
96  void setDateFilter(int year, int month = 0, int day = 0);
97 
98  int yearFilter() const;
99  int monthFilter() const;
100  int dayFilter() const;
101 
103  /**
104  * The results are returned in the most efficient order. They can
105  * be returned in any order.
106  */
108 
109  /**
110  * The results are returned in the order Baloo decides
111  * should be ideal. This criteria is based on the mtime of the
112  * file.
113  *
114  * This is the default sorting mechanism.
115  */
117  };
118 
119  void setSortingOption(SortingOption option);
120  SortingOption sortingOption() const;
121 
122  /**
123  * Only files in this folder will be returned
124  */
125  void setIncludeFolder(const QString& folder);
126  QString includeFolder() const;
127 
128  ResultIterator exec();
129 
130  QByteArray toJSON();
131  static Query fromJSON(const QByteArray& arr);
132 
133  QUrl toSearchUrl(const QString& title = QString());
134  static Query fromSearchUrl(const QUrl& url);
135  static QString titleFromQueryUrl(const QUrl& url);
136 
137  bool operator == (const Query& rhs) const;
138  bool operator != (const Query& rhs) const;
139 
140  Query& operator=(const Query& rhs);
141 
142 private:
143  class Private;
144  Private* d;
145 };
146 
147 }
148 #endif // BALOO_QUERY_H
@ SortAuto
The results are returned in the order Baloo decides should be ideal.
Definition: query.h:116
Implements storage for docIds without any associated data Instantiated for:
Definition: coding.cpp:11
@ SortNone
The results are returned in the most efficient order.
Definition: query.h:107
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Nov 29 2023 03:56:26 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.