2019-05-19 09:42:52 +02:00
|
|
|
/* This file is part of remwharead.
|
|
|
|
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
|
|
|
*
|
|
|
|
* 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, version 3.
|
|
|
|
*
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef REMWHAREAD_SEARCH_HPP
|
|
|
|
#define REMWHAREAD_SEARCH_HPP
|
|
|
|
|
2019-09-30 13:20:36 +02:00
|
|
|
#include "sqlite.hpp"
|
2019-08-08 15:19:42 +02:00
|
|
|
#include <list>
|
2019-05-19 09:42:52 +02:00
|
|
|
#include <string>
|
2019-08-08 15:19:42 +02:00
|
|
|
#include <vector>
|
2019-05-19 09:42:52 +02:00
|
|
|
|
2019-07-27 09:59:43 +02:00
|
|
|
namespace remwharead
|
|
|
|
{
|
2019-09-30 13:20:36 +02:00
|
|
|
using std::list;
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
2019-05-19 09:42:52 +02:00
|
|
|
|
2019-09-30 13:20:36 +02:00
|
|
|
/*!
|
|
|
|
* @brief %Search in database entries.
|
|
|
|
*
|
|
|
|
* @since 0.7.0
|
|
|
|
*
|
|
|
|
* @headerfile search.hpp remwharead/search.hpp
|
|
|
|
*/
|
|
|
|
class Search
|
|
|
|
{
|
|
|
|
public:
|
2019-07-28 00:07:55 +02:00
|
|
|
/*!
|
2019-09-30 13:20:36 +02:00
|
|
|
* @brief Defines the entries to search.
|
2019-07-28 00:07:55 +02:00
|
|
|
*
|
2019-08-06 11:20:30 +02:00
|
|
|
* @since 0.7.0
|
2019-07-28 00:07:55 +02:00
|
|
|
*/
|
2019-09-30 13:20:36 +02:00
|
|
|
explicit Search(list<Database::entry> entries);
|
2019-05-19 10:55:45 +02:00
|
|
|
|
2019-09-30 13:20:36 +02:00
|
|
|
/*!
|
|
|
|
* @brief %Search in tags of database entries.
|
|
|
|
*
|
|
|
|
* Only matches whole tags, *Pill* does not match *Pillow*.
|
|
|
|
*
|
|
|
|
* @param expression %Search expression.
|
|
|
|
* @param is_re Is it a regular expression?
|
|
|
|
*
|
|
|
|
* @return List of matching Database::entry.
|
|
|
|
*
|
|
|
|
* @since 0.7.0
|
|
|
|
*/
|
2019-10-30 08:51:07 +01:00
|
|
|
[[nodiscard]]
|
2019-09-30 13:20:36 +02:00
|
|
|
list<Database::entry> search_tags(const string &expression, bool is_re)
|
|
|
|
const;
|
2019-05-19 09:42:52 +02:00
|
|
|
|
2019-09-30 13:20:36 +02:00
|
|
|
/*!
|
|
|
|
* @brief %Search in full text of database entries.
|
|
|
|
*
|
|
|
|
* Searches in tags, title, description and full text.
|
|
|
|
*
|
|
|
|
* @param expression %Search expression.
|
|
|
|
* @param is_re Is it a regular expression?
|
|
|
|
*
|
|
|
|
* @return List of matching Database::entry.
|
|
|
|
*
|
|
|
|
* @since 0.7.0
|
|
|
|
*/
|
2019-10-30 08:51:07 +01:00
|
|
|
[[nodiscard]]
|
2019-09-30 13:20:36 +02:00
|
|
|
list<Database::entry> search_all(const string &expression, bool is_re)
|
|
|
|
const;
|
2019-08-09 00:14:26 +02:00
|
|
|
|
2019-09-30 13:20:36 +02:00
|
|
|
/*!
|
|
|
|
* @brief Spawn threads of search_all(), if it seems sensible.
|
|
|
|
*
|
|
|
|
* Figure out if threads could be useful and spawn a sensible amount of
|
|
|
|
* them.
|
|
|
|
*
|
|
|
|
* @param expression %Search expression.
|
|
|
|
* @param is_re Is it a regular expression?
|
|
|
|
*
|
|
|
|
* @return List of matching Database::entry.
|
|
|
|
*
|
|
|
|
* @since 0.7.2
|
|
|
|
*/
|
|
|
|
// TODO(tastytea): Think of something more elegant.
|
2019-10-30 08:51:07 +01:00
|
|
|
[[nodiscard]]
|
2019-09-30 13:20:36 +02:00
|
|
|
list<Database::entry> search_all_threaded(const string &expression,
|
|
|
|
bool is_re) const;
|
2019-08-06 11:20:30 +02:00
|
|
|
|
2019-09-30 13:20:36 +02:00
|
|
|
private:
|
|
|
|
const list<Database::entry> _entries;
|
2019-08-06 11:20:30 +02:00
|
|
|
|
2019-09-30 13:20:36 +02:00
|
|
|
/*!
|
|
|
|
* @brief Split expression into subexpressions.
|
|
|
|
*
|
|
|
|
* First it splits at `OR` or `||`, then it splits the subexpressions
|
|
|
|
* at `AND` or `&&`. The first vector contains all tags before the
|
|
|
|
* first `OR`.
|
|
|
|
*
|
|
|
|
* @return Vector of `OR`-vectors of `AND`-tags.
|
|
|
|
*
|
|
|
|
* @since 0.7.0
|
|
|
|
*/
|
2019-10-30 08:51:07 +01:00
|
|
|
[[nodiscard]]
|
2019-09-30 13:20:36 +02:00
|
|
|
vector<vector<string>> parse_expression(const string &expression) const;
|
2019-08-06 11:20:30 +02:00
|
|
|
|
2019-09-30 13:20:36 +02:00
|
|
|
/*!
|
|
|
|
* @brief Convert str to lowercase. Works with unicode.
|
|
|
|
*
|
|
|
|
* @since 0.7.0
|
|
|
|
*/
|
2019-10-30 08:51:07 +01:00
|
|
|
[[nodiscard]]
|
2019-09-30 13:20:36 +02:00
|
|
|
inline string to_lowercase(const string &str) const;
|
|
|
|
};
|
2019-09-25 03:58:29 +02:00
|
|
|
} // namespace remwharead
|
2019-05-19 10:55:45 +02:00
|
|
|
|
2019-05-19 09:42:52 +02:00
|
|
|
#endif // REMWHAREAD_SEARCH_HPP
|