Search in database entries.
More...
#include <remwharead/search.hpp>
Search in database entries.
- Since
- 0.7.0
◆ Search()
Defines the entries to search.
- Since
- 0.7.0
◆ search_all()
const list< DB::entry > remwharead::Search::search_all |
( |
string |
expression, |
|
|
const bool |
is_re |
|
) |
| const |
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.
- Since
- 0.7.0
124 vector<vector<string>> searchlist = parse_expression(expression);
125 list<DB::entry> result =
search_tags(expression, is_re);
127 for (
const vector<string> &terms_or : searchlist)
133 bool matched_title =
true;
134 bool matched_description =
true;
135 bool matched_fulltext =
true;
137 const auto it = find(result.begin(), result.end(), entry);
138 if (it != result.end())
143 for (
const string &term : terms_or)
145 const string title = to_lowercase(entry.title);
146 const string description = to_lowercase(entry.description);
147 const string fulltext = to_lowercase(entry.fulltext);
152 const regex re(term);
154 if(!regex_search(title, re))
156 matched_title =
false;
159 if(!regex_search(description, re))
161 matched_description =
false;
164 if(!regex_search(fulltext, re))
166 matched_fulltext =
false;
171 if (title.find(term) == string::npos)
173 matched_title =
false;
176 if (description.find(term) == string::npos)
178 matched_description =
false;
181 if (fulltext.find(term) == string::npos)
183 matched_fulltext =
false;
187 if (matched_title ==
true 188 || matched_description ==
true 189 || matched_fulltext ==
true)
191 result.push_back(entry);
struct remwharead::Database::entry entry
Describes a database entry.
const list< Database::entry > search_tags(string expression, const bool is_re) const
Search in tags of database entries.
Definition: search.cpp:77
◆ search_tags()
const list< DB::entry > remwharead::Search::search_tags |
( |
string |
expression, |
|
|
const bool |
is_re |
|
) |
| const |
Search in tags of database entries.
Only matches whole tags, Pill does not match Pillow.
- Parameters
-
expression | Search expression. |
is_re | Is it a regular expression? |
- Returns
- Vector of matching Database::entry.
- Since
- 0.7.0
80 vector<vector<string>> searchlist = parse_expression(expression);
81 list<DB::entry> result;
83 for (
const vector<string> &tags_or : searchlist)
89 for (
const string &tag : tags_or)
91 const auto it = find_if(
92 entry.tags.begin(), entry.tags.end(),
98 const regex re(
"^" + tag +
"$");
99 return regex_search(s, re);
106 if (it == entry.tags.end())
113 result.push_back(entry);
struct remwharead::Database::entry entry
Describes a database entry.
The documentation for this class was generated from the following files: