Akonadi Search

core/query.h
1 /*
2  * This file is part of the KDE Akonadi Search Project
3  * SPDX-FileCopyrightText: 2013 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 
9 #pragma once
10 
11 #include "resultiterator.h"
12 #include "search_core_export.h"
13 
14 #include <memory>
15 
16 class QVariant;
17 
18 namespace Akonadi
19 {
20 namespace Search
21 {
22 class Term;
23 class QueryPrivate;
24 
25 /** Search query. */
26 class AKONADI_SEARCH_CORE_EXPORT Query
27 {
28 public:
29  Query();
30  Query(const Term &t);
31  Query(const Query &rhs);
32  ~Query();
33 
34  void setTerm(const Term &t);
35  [[nodiscard]] Term term() const;
36 
37  /**
38  * Add a type to the results of the query.
39  *
40  * Each Item in the result must contain one of the types.
41  * This is generally used to filter only Files, Emails, Tags, etc
42  *
43  * One can add multiple types in one go by separating individual types
44  * with a '/'. Eg - "File/Audio".
45  *
46  * Please note that the types are ANDed together. So searching for "Image"
47  * and "Video" will probably never return any results. Have a look at
48  * KFileMetaData::TypeInfo for a list of type names.
49  */
50  void addType(const QString &type);
51  void addTypes(const QStringList &typeList);
52  void setType(const QString &type);
53  void setTypes(const QStringList &types);
54 
55  [[nodiscard]] QStringList types() const;
56 
57  /**
58  * Set some text which should be used to search for Items. This
59  * contain a single word or an entire sentence.
60  *
61  * Each search backend will interpret it in its own way, and try
62  * to give the best possible results.
63  */
64  void setSearchString(const QString &str);
65  [[nodiscard]] QString searchString() const;
66 
67  /**
68  * Only a maximum of \p limit results will be returned.
69  * By default the limit is 100000.
70  */
71  void setLimit(uint limit);
72  [[nodiscard]] uint limit() const;
73 
74  void setOffset(uint offset);
75  [[nodiscard]] uint offset() const;
76 
77  /**
78  * Filter the results in the specified date range.
79  *
80  * The year/month/day may be set to -1 in order to ignore it.
81  */
82  void setDateFilter(int year, int month = -1, int day = -1);
83 
84  [[nodiscard]] int yearFilter() const;
85  [[nodiscard]] int monthFilter() const;
86  [[nodiscard]] int dayFilter() const;
87 
89  /**
90  * The results are returned in the most efficient order. They can
91  * be returned in any order.
92  */
94 
95  /**
96  * The results are returned in the order the SearchStore decides
97  * should be ideal. This criteria could be based on any factors.
98  * Read the documentation for the corresponding search store.
99  */
101 
102  /**
103  * The results are returned based on the explicit property specified.
104  * The implementation of this depends on the search store.
105  */
106  SortProperty
107  };
108 
109  void setSortingOption(SortingOption option);
110  [[nodiscard]] SortingOption sortingOption() const;
111 
112  /**
113  * Sets the property that should be used for sorting. This automatically
114  * set the sorting mechanism to SortProperty
115  */
116  void setSortingProperty(const QString &property);
117  [[nodiscard]] QString sortingProperty() const;
118 
119  /**
120  * Adds a custom option which any search backend could use
121  * to configure the query result.
122  *
123  * Each backend has their own custom options which should be
124  * looked up in their corresponding documentation
125  */
126  void addCustomOption(const QString &option, const QVariant &value);
127  void removeCustomOption(const QString &option);
128  QVariant customOption(const QString &option) const;
129  [[nodiscard]] QVariantMap customOptions() const;
130 
131  [[nodiscard]] ResultIterator exec();
132 
133  [[nodiscard]] QByteArray toJSON() const;
134  static Query fromJSON(const QByteArray &arr);
135 
136  [[nodiscard]] QUrl toSearchUrl(const QString &title = QString());
137  static Query fromSearchUrl(const QUrl &url);
138  static QString titleFromQueryUrl(const QUrl &url);
139 
140  bool operator==(const Query &rhs) const;
141 
142  Query &operator=(const Query &rhs);
143 
144 private:
145  std::unique_ptr<QueryPrivate> const d;
146 };
147 }
148 }
@ SortAuto
The results are returned in the order the SearchStore decides should be ideal.
Definition: core/query.h:100
Search term.
Definition: term.h:26
Search query.
Definition: core/query.h:26
@ SortNone
The results are returned in the most efficient order.
Definition: core/query.h:93
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Dec 5 2023 04:11:35 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.