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
-
expression | Search expression. |
is_re | Is it a regular expression? |
- Returns
- List of matching Database::entry.
- Since
- 0.7.0
129 vector<vector<string>> searchlist = parse_expression(expression);
130 list<DB::entry> result =
search_tags(expression, is_re);
132 for (
const vector<string> &terms_or : searchlist)
138 bool matched_title =
true;
139 bool matched_description =
true;
140 bool matched_fulltext =
true;
142 const auto it = find(result.begin(), result.end(), entry);
143 if (it != result.end())
148 for (
const string &term : terms_or)
150 const string title = to_lowercase(entry.title);
151 const string description = to_lowercase(entry.description);
152 const string fulltext = to_lowercase(entry.fulltext);
157 const regex re(term);
159 if(!regex_search(title, re))
161 matched_title =
false;
164 if(!regex_search(description, re))
166 matched_description =
false;
169 if(!regex_search(fulltext, re))
171 matched_fulltext =
false;
176 if (title.find(term) == string::npos)
178 matched_title =
false;
181 if (description.find(term) == string::npos)
183 matched_description =
false;
186 if (fulltext.find(term) == string::npos)
188 matched_fulltext =
false;
192 if (matched_title ==
true 193 || matched_description ==
true 194 || matched_fulltext ==
true)
196 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:82
◆ search_all_threaded()
const list< Database::entry > remwharead::Search::search_all_threaded |
( |
string |
expression, |
|
|
const bool |
is_re |
|
) |
| const |
Spawn threads of search_all(), if it seems sensible.
Figure out if threads could be useful and spawn a sensible amount of them.
- Parameters
-
expression | Search expression. |
is_re | Is it a regular expression? |
- Returns
- List of matching Database::entry.
- Since
- 0.7.2
207 list<Database::entry> entries = _entries;
209 const size_t len = entries.size();
210 constexpr
size_t min_len = 100;
211 constexpr
size_t min_per_thread = 50;
212 const size_t n_threads = thread::hardware_concurrency() / 3 + 1;
216 cut_at = len / n_threads;
219 if (cut_at < min_per_thread)
221 cut_at = min_per_thread;
225 list<list<Database::entry>> segments;
228 while (entries.size() > cut_at)
230 list<Database::entry> segment;
232 auto it = entries.begin();
233 std::advance(it, cut_at);
236 segment.splice(segment.begin(), entries, entries.begin(), it);
237 segments.push_back(move(segment));
240 segments.push_back(move(entries));
242 list<thread> threads;
243 for (
auto &segment : segments)
250 segment = search.search_all(expression, is_re);
252 threads.push_back(move(t));
255 for (thread &t : threads)
259 entries.splice(entries.end(), segments.front());
260 segments.pop_front();
Search(const list< Database::entry > &entries)
Defines the entries to search.
Definition: search.cpp:38
◆ 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
- List of matching Database::entry.
- Since
- 0.7.0
85 vector<vector<string>> searchlist = parse_expression(expression);
86 list<DB::entry> result;
88 for (
const vector<string> &tags_or : searchlist)
94 for (
const string &tag : tags_or)
96 const auto it = find_if(
97 entry.tags.begin(), entry.tags.end(),
103 const regex re(
"^" + tag +
"$");
104 return regex_search(s, re);
111 if (it == entry.tags.end())
118 result.push_back(entry);
struct remwharead::Database::entry entry
Describes a database entry.
The documentation for this class was generated from the following files: