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 vector< 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
122 vector<vector<string>> searchlist = parse_expression(expression);
123 vector<DB::entry> result =
search_tags(expression, is_re);
125 for (
const vector<string> &terms_or : searchlist)
131 bool matched_title =
true;
132 bool matched_description =
true;
133 bool matched_fulltext =
true;
135 const auto it = find(result.begin(), result.end(), entry);
136 if (it != result.end())
141 for (
const string &term : terms_or)
143 const string title = to_lowercase(entry.title);
144 const string description = to_lowercase(entry.description);
145 const string fulltext = to_lowercase(entry.fulltext);
150 const regex re(term);
152 if(!regex_search(title, re))
154 matched_title =
false;
157 if(!regex_search(description, re))
159 matched_description =
false;
162 if(!regex_search(fulltext, re))
164 matched_fulltext =
false;
169 if (title.find(term) == string::npos)
171 matched_title =
false;
174 if (description.find(term) == string::npos)
176 matched_description =
false;
179 if (fulltext.find(term) == string::npos)
181 matched_fulltext =
false;
185 if (matched_title ==
true 186 || matched_description ==
true 187 || matched_fulltext ==
true)
189 result.push_back(entry);
struct remwharead::Database::entry entry
Describes a database entry.
const vector< Database::entry > search_tags(string expression, const bool is_re) const
Search in tags of database entries.
Definition: search.cpp:75
◆ search_tags()
const vector< 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
78 vector<vector<string>> searchlist = parse_expression(expression);
79 vector<DB::entry> result;
81 for (
const vector<string> &tags_or : searchlist)
87 for (
const string &tag : tags_or)
89 const auto it = find_if(
90 entry.tags.begin(), entry.tags.end(),
96 const regex re(
"^" + tag +
"$");
97 return regex_search(s, re);
104 if (it == entry.tags.end())
111 result.push_back(entry);
struct remwharead::Database::entry entry
Describes a database entry.
The documentation for this class was generated from the following files: