remwharead/src/lib/search.hpp

76 lines
2.4 KiB
C++
Raw Normal View History

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
#include <vector>
#include <string>
#include "sqlite.hpp"
2019-07-28 00:07:55 +02:00
//! @file
2019-07-27 09:59:43 +02:00
namespace remwharead
{
using std::vector;
using std::string;
2019-05-19 09:42:52 +02:00
2019-07-28 00:07:55 +02:00
/*!
2019-07-28 02:14:06 +02:00
* @brief Split expression in subexpressions.
2019-07-28 00:07:55 +02:00
*
* First it splits at `OR` or `||`, then it splits the subexpressions at
* `AND` or `&&`. The first vector contains all tags before the first `OR`.
*
2019-07-28 02:14:06 +02:00
* @return Vector of `OR`-vectors of `AND`-tags.
2019-07-28 00:07:55 +02:00
*/
2019-07-27 09:59:43 +02:00
const vector<vector<string>> parse_expression(string expression);
2019-07-28 00:07:55 +02:00
//! Convert str to lowercase. Works with unicode.
2019-07-27 09:59:43 +02:00
const string to_lowercase(const string &str);
2019-07-28 00:07:55 +02:00
/*!
2019-07-28 02:14:06 +02:00
* @brief Search in tags of database entries.
2019-07-28 00:07:55 +02:00
*
* Only matches whole tags, *Pill* does not match *Pillow*.
*
2019-07-28 02:14:06 +02:00
* @param entries Vector of Database::entry to search.
* @param expression Search expression.
* @param is_re Is it a regular expression?
2019-07-28 00:07:55 +02:00
*
2019-07-28 02:14:06 +02:00
* @return Vector of matching Database::entry.
2019-07-28 00:07:55 +02:00
*/
2019-07-27 09:59:43 +02:00
const vector<Database::entry>
search_tags(const vector<Database::entry> &entries, string expression,
const bool is_re);
2019-05-19 09:42:52 +02:00
2019-07-28 00:07:55 +02:00
/*!
2019-07-28 02:14:06 +02:00
* @brief Search in full text of database entries.
2019-07-28 00:07:55 +02:00
*
* Searches in tags, title, description and full text.
*
2019-07-28 02:14:06 +02:00
* @param entries Vector of Database::entry to search.
* @param expression Search expression.
* @param is_re Is it a regular expression?
2019-07-28 00:07:55 +02:00
*
2019-07-28 02:14:06 +02:00
* @return Vector of matching Database::entry.
2019-07-28 00:07:55 +02:00
*/
2019-07-27 09:59:43 +02:00
const vector<Database::entry>
search_all(const vector<Database::entry> &entries, string expression,
const bool is_re);
}
2019-05-19 09:42:52 +02:00
#endif // REMWHAREAD_SEARCH_HPP