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
37 :_entries(move(entries))
◆ search_all()
list< Database::entry > remwharead::Search::search_all |
( |
const string & |
expression, |
|
|
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
131 vector<vector<string>> searchlist = parse_expression(expression);
132 list<Database::entry> result =
search_tags(expression, is_re);
134 for (
const vector<string> &terms_or : searchlist)
136 for (
const Database::entry &entry : _entries)
140 bool matched_title =
true;
141 bool matched_description =
true;
142 bool matched_fulltext =
true;
144 const auto it = find(result.begin(), result.end(), entry);
145 if (it != result.end())
150 for (
const string &term : terms_or)
152 const string title = to_lowercase(entry.title);
153 const string description = to_lowercase(entry.description);
154 const string fulltext = to_lowercase(entry.fulltext);
159 const RegEx re(term);
163 matched_title =
false;
166 if (!(re == description))
168 matched_description =
false;
171 if (!(re == fulltext))
173 matched_fulltext =
false;
178 if (title.find(term) == string::npos)
180 matched_title =
false;
183 if (description.find(term) == string::npos)
185 matched_description =
false;
188 if (fulltext.find(term) == string::npos)
190 matched_fulltext =
false;
194 if (matched_title || matched_description || matched_fulltext)
196 result.push_back(entry);
list< Database::entry > search_tags(const string &expression, bool is_re) const
Search in tags of database entries.
Definition: search.cpp:86
◆ search_all_threaded()
list< Database::entry > remwharead::Search::search_all_threaded |
( |
const string & |
expression, |
|
|
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 list<Database::entry> rest;
241 rest.splice(rest.begin(), entries);
242 segments.push_back(move(rest));
244 list<thread> threads;
245 for (
auto &segment : segments)
252 segment = search.search_all(expression, is_re);
254 threads.push_back(move(t));
257 for (thread &t : threads)
261 entries.splice(entries.end(), segments.front());
262 segments.pop_front();
Search(list< Database::entry > entries)
Defines the entries to search.
Definition: search.cpp:36
◆ search_tags()
list< Database::entry > remwharead::Search::search_tags |
( |
const string & |
expression, |
|
|
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
89 vector<vector<string>> searchlist = parse_expression(expression);
90 list<Database::entry> result;
92 for (
const vector<string> &tags_or : searchlist)
94 for (
const Database::entry &entry : _entries)
98 for (
const string &tag : tags_or)
100 const auto it = find_if(
101 entry.tags.begin(), entry.tags.end(),
107 const RegEx re(
"^" + tag +
"$");
113 if (it == entry.tags.end())
120 result.push_back(entry);
The documentation for this class was generated from the following files: