#include <vector>
#include <string>
#include "sqlite.hpp"
Go to the source code of this file.
|
const vector< vector< string > > | remwharead::parse_expression (string expression) |
| Split expression in subexpressions. More...
|
|
const string | remwharead::to_lowercase (const string &str) |
| Convert str to lowercase. Works with unicode. More...
|
|
const vector< DB::entry > | remwharead::search_tags (const vector< Database::entry > &entries, string expression, const bool is_re) |
| Search in tags of database entries. More...
|
|
const vector< DB::entry > | remwharead::search_all (const vector< Database::entry > &entries, string expression, const bool is_re) |
| Search in full text of database entries. More...
|
|
◆ parse_expression()
const vector< vector< string > > remwharead::parse_expression |
( |
string |
expression | ) |
|
Split expression in 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
.
- Returns
- Vector of
OR
-vectors of AND
-tags.
33 vector<vector<string>> searchlist;
34 const regex re_or(
"(.+?) (OR|\\|\\|) ");
35 const regex re_and(
"(.+?) (AND|&&) ");
38 vector<string> subexpressions;
40 while (regex_search(expression, match, re_or))
42 subexpressions.push_back(match[1].str());
43 expression = match.suffix().str();
45 subexpressions.push_back(expression);
49 for (
string sub : subexpressions)
52 while (regex_search(sub, match, re_and))
54 terms.push_back(to_lowercase(match[1].str()));
55 sub = match.suffix().str();
57 terms.push_back(to_lowercase(sub));
58 searchlist.push_back(terms);
◆ search_all()
const vector< Database::entry > remwharead::search_all |
( |
const vector< Database::entry > & |
entries, |
|
|
string |
expression, |
|
|
const bool |
is_re |
|
) |
| |
Search in full text of database entries.
Searches in tags, title, description and full text.
- Parameters
-
entries | Vector of Database::entry to search. |
expression | Search expression. |
is_re | Is it a regular expression? |
- Returns
- Vector of matching Database::entry.
120 vector<vector<string>> searchlist = parse_expression(expression);
121 vector<DB::entry> result = search_tags(entries, expression, is_re);
123 for (
const vector<string> &terms_or : searchlist)
125 for (
const DB::entry &entry : entries)
129 bool matched_title =
true;
130 bool matched_description =
true;
131 bool matched_fulltext =
true;
133 const auto it = find(result.begin(), result.end(), entry);
134 if (it != result.end())
139 for (
const string &term : terms_or)
141 const string title = to_lowercase(entry.title);
142 const string description = to_lowercase(entry.description);
143 const string fulltext = to_lowercase(entry.fulltext);
148 const regex re(term);
150 if(!regex_search(title, re))
152 matched_title =
false;
155 if(!regex_search(description, re))
157 matched_description =
false;
160 if(!regex_search(fulltext, re))
162 matched_fulltext =
false;
167 if (title.find(term) == string::npos)
169 matched_title =
false;
172 if (description.find(term) == string::npos)
174 matched_description =
false;
177 if (fulltext.find(term) == string::npos)
179 matched_fulltext =
false;
183 if (matched_title ==
true 184 || matched_description ==
true 185 || matched_fulltext ==
true)
187 result.push_back(entry);
◆ search_tags()
const vector< Database::entry > remwharead::search_tags |
( |
const vector< Database::entry > & |
entries, |
|
|
string |
expression, |
|
|
const bool |
is_re |
|
) |
| |
Search in tags of database entries.
Only matches whole tags, Pill does not match Pillow.
- Parameters
-
entries | Vector of Database::entry to search. |
expression | Search expression. |
is_re | Is it a regular expression? |
- Returns
- Vector of matching Database::entry.
76 vector<vector<string>> searchlist = parse_expression(expression);
77 vector<DB::entry> result;
79 for (
const vector<string> &tags_or : searchlist)
81 for (
const DB::entry &entry : entries)
85 for (
const string &tag : tags_or)
87 const auto it = find_if(
88 entry.tags.begin(), entry.tags.end(),
89 [&tag, is_re](
string s)
94 const regex re(
"^" + tag +
"$");
95 return regex_search(s, re);
102 if (it == entry.tags.end())
109 result.push_back(entry);
◆ to_lowercase()
const string remwharead::to_lowercase |
( |
const string & |
str | ) |
|
Convert str to lowercase. Works with unicode.
67 icu::UnicodeString uni(str.c_str());
69 uni.toLower().toUTF8String(out);