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
132 vector<vector<string>> searchlist = parse_expression(expression);
133 list<Database::entry> result =
search_tags(expression, is_re);
135 for (
const vector<string> &terms_or : searchlist)
137 for (
const Database::entry &entry : _entries)
141 bool matched_title =
true;
142 bool matched_description =
true;
143 bool matched_fulltext =
true;
145 const auto it = find(result.begin(), result.end(), entry);
146 if (it != result.end())
151 for (
const string &term : terms_or)
153 const string title = to_lowercase(entry.title);
154 const string description = to_lowercase(entry.description);
155 const string fulltext = to_lowercase(entry.fulltext);
160 const RegEx re(term);
164 matched_title =
false;
167 if (!(re == description))
169 matched_description =
false;
172 if (!(re == fulltext))
174 matched_fulltext =
false;
179 if (title.find(term) == string::npos)
181 matched_title =
false;
184 if (description.find(term) == string::npos)
186 matched_description =
false;
189 if (fulltext.find(term) == string::npos)
191 matched_fulltext =
false;
195 if (matched_title || matched_description || matched_fulltext)
197 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
208 list<Database::entry> entries = _entries;
210 const size_t len = entries.size();
211 constexpr
size_t min_len = 100;
212 constexpr
size_t min_per_thread = 50;
213 const size_t n_threads = thread::hardware_concurrency() / 3 + 1;
217 cut_at = len / n_threads;
220 if (cut_at < min_per_thread)
222 cut_at = min_per_thread;
226 list<list<Database::entry>> segments;
229 while (entries.size() > cut_at)
231 list<Database::entry> segment;
233 auto it = entries.begin();
234 std::advance(it, cut_at);
237 segment.splice(segment.begin(), entries, entries.begin(), it);
238 segments.push_back(move(segment));
241 list<Database::entry> rest;
242 rest.splice(rest.begin(), entries);
243 segments.push_back(move(rest));
245 list<thread> threads;
246 for (
auto &segment : segments)
253 segment = search.search_all(expression, is_re);
255 threads.push_back(move(t));
258 for (thread &t : threads)
262 entries.splice(entries.end(), segments.front());
263 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
90 vector<vector<string>> searchlist = parse_expression(expression);
91 list<Database::entry> result;
93 for (
const vector<string> &tags_or : searchlist)
95 for (
const Database::entry &entry : _entries)
99 for (
const string &tag : tags_or)
101 const auto it = find_if(
102 entry.tags.begin(), entry.tags.end(),
108 const RegEx re(
"^" + tag +
"$");
114 if (it == entry.tags.end())
121 result.push_back(entry);
The documentation for this class was generated from the following files: