2020-11-03 08:58:59 +01:00
|
|
|
/*
|
2023-09-09 10:57:05 +02:00
|
|
|
** Copyright (C) 2008-2023 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
2020-11-03 08:58:59 +01:00
|
|
|
**
|
|
|
|
** This program is free software; you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation; either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** This program is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with this program; if not, write to the Free Software Foundation,
|
|
|
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __MU_QUERY_HH__
|
|
|
|
#define __MU_QUERY_HH__
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <mu-store.hh>
|
2020-11-28 09:11:07 +01:00
|
|
|
#include <mu-query-results.hh>
|
2020-11-03 08:58:59 +01:00
|
|
|
#include <utils/mu-utils.hh>
|
2022-03-28 07:58:04 +02:00
|
|
|
#include <utils/mu-option.hh>
|
2022-04-28 21:58:15 +02:00
|
|
|
#include <utils/mu-result.hh>
|
2022-03-20 13:12:41 +01:00
|
|
|
#include <message/mu-message.hh>
|
2020-11-03 08:58:59 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
namespace Mu {
|
2020-11-28 09:11:07 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
class Query {
|
2022-01-30 13:28:30 +01:00
|
|
|
public:
|
2021-10-20 11:18:15 +02:00
|
|
|
/**
|
|
|
|
* Run a query on the store
|
|
|
|
*
|
|
|
|
* @param expr the search expression
|
2022-04-28 21:58:15 +02:00
|
|
|
* @param sortfield_id the sortfield-id. Default to Date
|
2021-10-20 11:18:15 +02:00
|
|
|
* @param flags query flags
|
|
|
|
* @param maxnum maximum number of results to return. 0 for 'no limit'
|
|
|
|
*
|
2022-04-28 21:58:15 +02:00
|
|
|
* @return the query-results or an error
|
2021-10-20 11:18:15 +02:00
|
|
|
*/
|
2022-04-28 21:58:15 +02:00
|
|
|
Result<QueryResults> run(const std::string& expr,
|
|
|
|
Field::Id sortfield_id = Field::Id::Date,
|
2022-03-28 07:58:04 +02:00
|
|
|
QueryFlags flags = QueryFlags::None,
|
|
|
|
size_t maxnum = 0) const;
|
2020-11-03 08:58:59 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
/**
|
|
|
|
* run a Xapian query to count the number of matches; for the syntax, please
|
|
|
|
* refer to the mu-query manpage
|
|
|
|
*
|
|
|
|
* @param expr the search expression; use "" to match all messages
|
|
|
|
*
|
|
|
|
* @return the number of matches
|
|
|
|
*/
|
|
|
|
size_t count(const std::string& expr = "") const;
|
2020-11-03 08:58:59 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
/**
|
|
|
|
* For debugging, get the internal string representation of the parsed
|
|
|
|
* query
|
|
|
|
*
|
|
|
|
* @param expr a xapian search expression
|
|
|
|
* @param xapian if true, show Xapian's internal representation,
|
|
|
|
* otherwise, mu's.
|
2020-11-03 08:58:59 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
* @return the string representation of the query
|
|
|
|
*/
|
|
|
|
std::string parse(const std::string& expr, bool xapian) const;
|
2021-06-13 17:36:24 +02:00
|
|
|
|
2022-01-30 13:28:30 +01:00
|
|
|
private:
|
|
|
|
friend class Store;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a new Query instance.
|
|
|
|
*
|
|
|
|
* @param store a MuStore object
|
|
|
|
*/
|
|
|
|
Query(const Store& store);
|
|
|
|
/**
|
|
|
|
* DTOR
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
~Query();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move CTOR
|
|
|
|
*
|
|
|
|
* @param other
|
|
|
|
*/
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
struct Private;
|
|
|
|
std::unique_ptr<Private> priv_;
|
2020-11-03 08:58:59 +01:00
|
|
|
};
|
2021-06-13 17:36:24 +02:00
|
|
|
} // namespace Mu
|
2020-11-03 08:58:59 +01:00
|
|
|
|
|
|
|
#endif /*__MU_QUERY_HH__*/
|