remwharead/docs/classremwharead_1_1Search.html
2019-11-02 08:13:06 +01:00

266 lines
36 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.15"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>remwharead: remwharead::Search Class Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">remwharead
&#160;<span id="projectnumber">0.8.5</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.15 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><b>remwharead</b></li><li class="navelem"><a class="el" href="classremwharead_1_1Search.html">Search</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="classremwharead_1_1Search-members.html">List of all members</a> </div>
<div class="headertitle">
<div class="title">remwharead::Search Class Reference</div> </div>
</div><!--header-->
<div class="contents">
<p>Search in database entries.
<a href="classremwharead_1_1Search.html#details">More...</a></p>
<p><code>#include &lt;<a class="el" href="search_8hpp_source.html">remwharead/search.hpp</a>&gt;</code></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:a8c5f3d0f81a29aca4129571271834a78"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classremwharead_1_1Search.html#a8c5f3d0f81a29aca4129571271834a78">Search</a> (list&lt; <a class="el" href="structremwharead_1_1Database_1_1entry.html">Database::entry</a> &gt; entries)</td></tr>
<tr class="memdesc:a8c5f3d0f81a29aca4129571271834a78"><td class="mdescLeft">&#160;</td><td class="mdescRight">Defines the entries to search. <a href="#a8c5f3d0f81a29aca4129571271834a78">More...</a><br /></td></tr>
<tr class="separator:a8c5f3d0f81a29aca4129571271834a78"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a26ed67b476fa163979bb0bdcd22f964f"><td class="memItemLeft" align="right" valign="top">list&lt; <a class="el" href="structremwharead_1_1Database_1_1entry.html">Database::entry</a> &gt;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classremwharead_1_1Search.html#a26ed67b476fa163979bb0bdcd22f964f">search_tags</a> (const string &amp;expression, bool is_re) const</td></tr>
<tr class="memdesc:a26ed67b476fa163979bb0bdcd22f964f"><td class="mdescLeft">&#160;</td><td class="mdescRight">Search in tags of database entries. <a href="#a26ed67b476fa163979bb0bdcd22f964f">More...</a><br /></td></tr>
<tr class="separator:a26ed67b476fa163979bb0bdcd22f964f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ac6e0245ff0032600f8ce7ea7be5ecc3d"><td class="memItemLeft" align="right" valign="top">list&lt; <a class="el" href="structremwharead_1_1Database_1_1entry.html">Database::entry</a> &gt;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classremwharead_1_1Search.html#ac6e0245ff0032600f8ce7ea7be5ecc3d">search_all</a> (const string &amp;expression, bool is_re) const</td></tr>
<tr class="memdesc:ac6e0245ff0032600f8ce7ea7be5ecc3d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Search in full text of database entries. <a href="#ac6e0245ff0032600f8ce7ea7be5ecc3d">More...</a><br /></td></tr>
<tr class="separator:ac6e0245ff0032600f8ce7ea7be5ecc3d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aaaa3f34ff323093f1957ba5d9ecc3954"><td class="memItemLeft" align="right" valign="top">list&lt; <a class="el" href="structremwharead_1_1Database_1_1entry.html">Database::entry</a> &gt;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classremwharead_1_1Search.html#aaaa3f34ff323093f1957ba5d9ecc3954">search_all_threaded</a> (const string &amp;expression, bool is_re) const</td></tr>
<tr class="memdesc:aaaa3f34ff323093f1957ba5d9ecc3954"><td class="mdescLeft">&#160;</td><td class="mdescRight">Spawn threads of <a class="el" href="classremwharead_1_1Search.html#ac6e0245ff0032600f8ce7ea7be5ecc3d" title="Search in full text of database entries.">search_all()</a>, if it seems sensible. <a href="#aaaa3f34ff323093f1957ba5d9ecc3954">More...</a><br /></td></tr>
<tr class="separator:aaaa3f34ff323093f1957ba5d9ecc3954"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Search in database entries. </p>
<dl class="section since"><dt>Since</dt><dd>0.7.0 </dd></dl>
</div><h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a id="a8c5f3d0f81a29aca4129571271834a78"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a8c5f3d0f81a29aca4129571271834a78">&#9670;&nbsp;</a></span>Search()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">remwharead::Search::Search </td>
<td>(</td>
<td class="paramtype">list&lt; <a class="el" href="structremwharead_1_1Database_1_1entry.html">Database::entry</a> &gt;&#160;</td>
<td class="paramname"><em>entries</em></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">explicit</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Defines the entries to search. </p>
<dl class="section since"><dt>Since</dt><dd>0.7.0 </dd></dl>
<div class="fragment"><div class="line"><a name="l00037"></a><span class="lineno"> 37</span>&#160; :_entries(move(entries))</div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span>&#160;{}</div></div><!-- fragment -->
</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a id="ac6e0245ff0032600f8ce7ea7be5ecc3d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ac6e0245ff0032600f8ce7ea7be5ecc3d">&#9670;&nbsp;</a></span>search_all()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">list&lt; <a class="el" href="structremwharead_1_1Database_1_1entry.html">Database::entry</a> &gt; remwharead::Search::search_all </td>
<td>(</td>
<td class="paramtype">const string &amp;&#160;</td>
<td class="paramname"><em>expression</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">bool&#160;</td>
<td class="paramname"><em>is_re</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td> const</td>
</tr>
</table>
</div><div class="memdoc">
<p>Search in full text of database entries. </p>
<p>Searches in tags, title, description and full text.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">expression</td><td>Search expression. </td></tr>
<tr><td class="paramname">is_re</td><td>Is it a regular expression?</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>List of matching <a class="el" href="structremwharead_1_1Database_1_1entry.html" title="Describes a database entry.">Database::entry</a>.</dd></dl>
<dl class="section since"><dt>Since</dt><dd>0.7.0 </dd></dl>
<div class="fragment"><div class="line"><a name="l00131"></a><span class="lineno"> 131</span>&#160;{</div><div class="line"><a name="l00132"></a><span class="lineno"> 132</span>&#160; vector&lt;vector&lt;string&gt;&gt; searchlist = parse_expression(expression);</div><div class="line"><a name="l00133"></a><span class="lineno"> 133</span>&#160; list&lt;Database::entry&gt; result = <a class="code" href="classremwharead_1_1Search.html#a26ed67b476fa163979bb0bdcd22f964f">search_tags</a>(expression, is_re);</div><div class="line"><a name="l00134"></a><span class="lineno"> 134</span>&#160;</div><div class="line"><a name="l00135"></a><span class="lineno"> 135</span>&#160; <span class="keywordflow">for</span> (<span class="keyword">const</span> vector&lt;string&gt; &amp;terms_or : searchlist)</div><div class="line"><a name="l00136"></a><span class="lineno"> 136</span>&#160; {</div><div class="line"><a name="l00137"></a><span class="lineno"> 137</span>&#160; <span class="keywordflow">for</span> (<span class="keyword">const</span> Database::entry &amp;entry : _entries)</div><div class="line"><a name="l00138"></a><span class="lineno"> 138</span>&#160; {</div><div class="line"><a name="l00139"></a><span class="lineno"> 139</span>&#160; <span class="comment">// Add entry to result if all terms in an OR-slice match title,</span></div><div class="line"><a name="l00140"></a><span class="lineno"> 140</span>&#160; <span class="comment">// description or full text.</span></div><div class="line"><a name="l00141"></a><span class="lineno"> 141</span>&#160; <span class="keywordtype">bool</span> matched_title = <span class="keyword">true</span>;</div><div class="line"><a name="l00142"></a><span class="lineno"> 142</span>&#160; <span class="keywordtype">bool</span> matched_description = <span class="keyword">true</span>;</div><div class="line"><a name="l00143"></a><span class="lineno"> 143</span>&#160; <span class="keywordtype">bool</span> matched_fulltext = <span class="keyword">true</span>;</div><div class="line"><a name="l00144"></a><span class="lineno"> 144</span>&#160;</div><div class="line"><a name="l00145"></a><span class="lineno"> 145</span>&#160; <span class="keyword">const</span> <span class="keyword">auto</span> it = find(result.begin(), result.end(), entry);</div><div class="line"><a name="l00146"></a><span class="lineno"> 146</span>&#160; <span class="keywordflow">if</span> (it != result.end())</div><div class="line"><a name="l00147"></a><span class="lineno"> 147</span>&#160; { <span class="comment">// Skip if already in result list.</span></div><div class="line"><a name="l00148"></a><span class="lineno"> 148</span>&#160; <span class="keywordflow">continue</span>;</div><div class="line"><a name="l00149"></a><span class="lineno"> 149</span>&#160; }</div><div class="line"><a name="l00150"></a><span class="lineno"> 150</span>&#160;</div><div class="line"><a name="l00151"></a><span class="lineno"> 151</span>&#160; <span class="keywordflow">for</span> (<span class="keyword">const</span> <span class="keywordtype">string</span> &amp;term : terms_or)</div><div class="line"><a name="l00152"></a><span class="lineno"> 152</span>&#160; {</div><div class="line"><a name="l00153"></a><span class="lineno"> 153</span>&#160; <span class="keyword">const</span> <span class="keywordtype">string</span> title = to_lowercase(entry.title);</div><div class="line"><a name="l00154"></a><span class="lineno"> 154</span>&#160; <span class="keyword">const</span> <span class="keywordtype">string</span> description = to_lowercase(entry.description);</div><div class="line"><a name="l00155"></a><span class="lineno"> 155</span>&#160; <span class="keyword">const</span> <span class="keywordtype">string</span> fulltext = to_lowercase(entry.fulltext);</div><div class="line"><a name="l00156"></a><span class="lineno"> 156</span>&#160;</div><div class="line"><a name="l00157"></a><span class="lineno"> 157</span>&#160; <span class="comment">// Set matched_* to false if term is not found.</span></div><div class="line"><a name="l00158"></a><span class="lineno"> 158</span>&#160; <span class="keywordflow">if</span> (is_re)</div><div class="line"><a name="l00159"></a><span class="lineno"> 159</span>&#160; {</div><div class="line"><a name="l00160"></a><span class="lineno"> 160</span>&#160; <span class="keyword">const</span> RegEx re(term);</div><div class="line"><a name="l00161"></a><span class="lineno"> 161</span>&#160;</div><div class="line"><a name="l00162"></a><span class="lineno"> 162</span>&#160; <span class="keywordflow">if</span> (!(re == title))</div><div class="line"><a name="l00163"></a><span class="lineno"> 163</span>&#160; {</div><div class="line"><a name="l00164"></a><span class="lineno"> 164</span>&#160; matched_title = <span class="keyword">false</span>;</div><div class="line"><a name="l00165"></a><span class="lineno"> 165</span>&#160; }</div><div class="line"><a name="l00166"></a><span class="lineno"> 166</span>&#160;</div><div class="line"><a name="l00167"></a><span class="lineno"> 167</span>&#160; <span class="keywordflow">if</span> (!(re == description))</div><div class="line"><a name="l00168"></a><span class="lineno"> 168</span>&#160; {</div><div class="line"><a name="l00169"></a><span class="lineno"> 169</span>&#160; matched_description = <span class="keyword">false</span>;</div><div class="line"><a name="l00170"></a><span class="lineno"> 170</span>&#160; }</div><div class="line"><a name="l00171"></a><span class="lineno"> 171</span>&#160;</div><div class="line"><a name="l00172"></a><span class="lineno"> 172</span>&#160; <span class="keywordflow">if</span> (!(re == fulltext))</div><div class="line"><a name="l00173"></a><span class="lineno"> 173</span>&#160; {</div><div class="line"><a name="l00174"></a><span class="lineno"> 174</span>&#160; matched_fulltext = <span class="keyword">false</span>;</div><div class="line"><a name="l00175"></a><span class="lineno"> 175</span>&#160; }</div><div class="line"><a name="l00176"></a><span class="lineno"> 176</span>&#160; }</div><div class="line"><a name="l00177"></a><span class="lineno"> 177</span>&#160; <span class="keywordflow">else</span></div><div class="line"><a name="l00178"></a><span class="lineno"> 178</span>&#160; {</div><div class="line"><a name="l00179"></a><span class="lineno"> 179</span>&#160; <span class="keywordflow">if</span> (title.find(term) == string::npos)</div><div class="line"><a name="l00180"></a><span class="lineno"> 180</span>&#160; {</div><div class="line"><a name="l00181"></a><span class="lineno"> 181</span>&#160; matched_title = <span class="keyword">false</span>;</div><div class="line"><a name="l00182"></a><span class="lineno"> 182</span>&#160; }</div><div class="line"><a name="l00183"></a><span class="lineno"> 183</span>&#160;</div><div class="line"><a name="l00184"></a><span class="lineno"> 184</span>&#160; <span class="keywordflow">if</span> (description.find(term) == string::npos)</div><div class="line"><a name="l00185"></a><span class="lineno"> 185</span>&#160; {</div><div class="line"><a name="l00186"></a><span class="lineno"> 186</span>&#160; matched_description = <span class="keyword">false</span>;</div><div class="line"><a name="l00187"></a><span class="lineno"> 187</span>&#160; }</div><div class="line"><a name="l00188"></a><span class="lineno"> 188</span>&#160;</div><div class="line"><a name="l00189"></a><span class="lineno"> 189</span>&#160; <span class="keywordflow">if</span> (fulltext.find(term) == string::npos)</div><div class="line"><a name="l00190"></a><span class="lineno"> 190</span>&#160; {</div><div class="line"><a name="l00191"></a><span class="lineno"> 191</span>&#160; matched_fulltext = <span class="keyword">false</span>;</div><div class="line"><a name="l00192"></a><span class="lineno"> 192</span>&#160; }</div><div class="line"><a name="l00193"></a><span class="lineno"> 193</span>&#160; }</div><div class="line"><a name="l00194"></a><span class="lineno"> 194</span>&#160; }</div><div class="line"><a name="l00195"></a><span class="lineno"> 195</span>&#160; <span class="keywordflow">if</span> (matched_title || matched_description || matched_fulltext)</div><div class="line"><a name="l00196"></a><span class="lineno"> 196</span>&#160; {</div><div class="line"><a name="l00197"></a><span class="lineno"> 197</span>&#160; result.push_back(entry);</div><div class="line"><a name="l00198"></a><span class="lineno"> 198</span>&#160; }</div><div class="line"><a name="l00199"></a><span class="lineno"> 199</span>&#160; }</div><div class="line"><a name="l00200"></a><span class="lineno"> 200</span>&#160; }</div><div class="line"><a name="l00201"></a><span class="lineno"> 201</span>&#160;</div><div class="line"><a name="l00202"></a><span class="lineno"> 202</span>&#160; <span class="keywordflow">return</span> result;</div><div class="line"><a name="l00203"></a><span class="lineno"> 203</span>&#160;}</div><div class="ttc" id="classremwharead_1_1Search_html_a26ed67b476fa163979bb0bdcd22f964f"><div class="ttname"><a href="classremwharead_1_1Search.html#a26ed67b476fa163979bb0bdcd22f964f">remwharead::Search::search_tags</a></div><div class="ttdeci">list&lt; Database::entry &gt; search_tags(const string &amp;expression, bool is_re) const</div><div class="ttdoc">Search in tags of database entries.</div><div class="ttdef"><b>Definition:</b> search.cpp:86</div></div>
</div><!-- fragment -->
</div>
</div>
<a id="aaaa3f34ff323093f1957ba5d9ecc3954"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aaaa3f34ff323093f1957ba5d9ecc3954">&#9670;&nbsp;</a></span>search_all_threaded()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">list&lt; <a class="el" href="structremwharead_1_1Database_1_1entry.html">Database::entry</a> &gt; remwharead::Search::search_all_threaded </td>
<td>(</td>
<td class="paramtype">const string &amp;&#160;</td>
<td class="paramname"><em>expression</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">bool&#160;</td>
<td class="paramname"><em>is_re</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td> const</td>
</tr>
</table>
</div><div class="memdoc">
<p>Spawn threads of <a class="el" href="classremwharead_1_1Search.html#ac6e0245ff0032600f8ce7ea7be5ecc3d" title="Search in full text of database entries.">search_all()</a>, if it seems sensible. </p>
<p>Figure out if threads could be useful and spawn a sensible amount of them.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">expression</td><td>Search expression. </td></tr>
<tr><td class="paramname">is_re</td><td>Is it a regular expression?</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>List of matching <a class="el" href="structremwharead_1_1Database_1_1entry.html" title="Describes a database entry.">Database::entry</a>.</dd></dl>
<dl class="section since"><dt>Since</dt><dd>0.7.2 </dd></dl>
<div class="fragment"><div class="line"><a name="l00207"></a><span class="lineno"> 207</span>&#160;{</div><div class="line"><a name="l00208"></a><span class="lineno"> 208</span>&#160; list&lt;Database::entry&gt; entries = _entries;</div><div class="line"><a name="l00209"></a><span class="lineno"> 209</span>&#160;</div><div class="line"><a name="l00210"></a><span class="lineno"> 210</span>&#160; <span class="keyword">const</span> <span class="keywordtype">size_t</span> len = entries.size();</div><div class="line"><a name="l00211"></a><span class="lineno"> 211</span>&#160; constexpr <span class="keywordtype">size_t</span> min_len = 100;</div><div class="line"><a name="l00212"></a><span class="lineno"> 212</span>&#160; constexpr <span class="keywordtype">size_t</span> min_per_thread = 50;</div><div class="line"><a name="l00213"></a><span class="lineno"> 213</span>&#160; <span class="keyword">const</span> <span class="keywordtype">size_t</span> n_threads = thread::hardware_concurrency() / 3 + 1;</div><div class="line"><a name="l00214"></a><span class="lineno"> 214</span>&#160; <span class="keywordtype">size_t</span> cut_at = len;</div><div class="line"><a name="l00215"></a><span class="lineno"> 215</span>&#160; <span class="keywordflow">if</span> (len &gt; min_len)</div><div class="line"><a name="l00216"></a><span class="lineno"> 216</span>&#160; { <span class="comment">// If there are over `min_len` entries, use `n_threads` threads.</span></div><div class="line"><a name="l00217"></a><span class="lineno"> 217</span>&#160; cut_at = len / n_threads;</div><div class="line"><a name="l00218"></a><span class="lineno"> 218</span>&#160;</div><div class="line"><a name="l00219"></a><span class="lineno"> 219</span>&#160; <span class="comment">// But don&#39;t use less than `min_per_thread` entries per thread.</span></div><div class="line"><a name="l00220"></a><span class="lineno"> 220</span>&#160; <span class="keywordflow">if</span> (cut_at &lt; min_per_thread)</div><div class="line"><a name="l00221"></a><span class="lineno"> 221</span>&#160; {</div><div class="line"><a name="l00222"></a><span class="lineno"> 222</span>&#160; cut_at = min_per_thread;</div><div class="line"><a name="l00223"></a><span class="lineno"> 223</span>&#160; }</div><div class="line"><a name="l00224"></a><span class="lineno"> 224</span>&#160; }</div><div class="line"><a name="l00225"></a><span class="lineno"> 225</span>&#160;</div><div class="line"><a name="l00226"></a><span class="lineno"> 226</span>&#160; list&lt;list&lt;Database::entry&gt;&gt; segments;</div><div class="line"><a name="l00227"></a><span class="lineno"> 227</span>&#160;</div><div class="line"><a name="l00228"></a><span class="lineno"> 228</span>&#160; <span class="comment">// Use threads if list is big.</span></div><div class="line"><a name="l00229"></a><span class="lineno"> 229</span>&#160; <span class="keywordflow">while</span> (entries.size() &gt; cut_at)</div><div class="line"><a name="l00230"></a><span class="lineno"> 230</span>&#160; {</div><div class="line"><a name="l00231"></a><span class="lineno"> 231</span>&#160; list&lt;Database::entry&gt; segment;</div><div class="line"><a name="l00232"></a><span class="lineno"> 232</span>&#160;</div><div class="line"><a name="l00233"></a><span class="lineno"> 233</span>&#160; <span class="keyword">auto</span> it = entries.begin();</div><div class="line"><a name="l00234"></a><span class="lineno"> 234</span>&#160; std::advance(it, cut_at);</div><div class="line"><a name="l00235"></a><span class="lineno"> 235</span>&#160;</div><div class="line"><a name="l00236"></a><span class="lineno"> 236</span>&#160; <span class="comment">// Move the first `cut_at` entries into `segments`.</span></div><div class="line"><a name="l00237"></a><span class="lineno"> 237</span>&#160; segment.splice(segment.begin(), entries, entries.begin(), it);</div><div class="line"><a name="l00238"></a><span class="lineno"> 238</span>&#160; segments.push_back(move(segment));</div><div class="line"><a name="l00239"></a><span class="lineno"> 239</span>&#160; }</div><div class="line"><a name="l00240"></a><span class="lineno"> 240</span>&#160; <span class="comment">// Move rest of `entries` into `segments`.</span></div><div class="line"><a name="l00241"></a><span class="lineno"> 241</span>&#160; list&lt;Database::entry&gt; rest;</div><div class="line"><a name="l00242"></a><span class="lineno"> 242</span>&#160; rest.splice(rest.begin(), entries);</div><div class="line"><a name="l00243"></a><span class="lineno"> 243</span>&#160; segments.push_back(move(rest));</div><div class="line"><a name="l00244"></a><span class="lineno"> 244</span>&#160;</div><div class="line"><a name="l00245"></a><span class="lineno"> 245</span>&#160; list&lt;thread&gt; threads;</div><div class="line"><a name="l00246"></a><span class="lineno"> 246</span>&#160; <span class="keywordflow">for</span> (<span class="keyword">auto</span> &amp;segment : segments)</div><div class="line"><a name="l00247"></a><span class="lineno"> 247</span>&#160; {</div><div class="line"><a name="l00248"></a><span class="lineno"> 248</span>&#160; thread t(</div><div class="line"><a name="l00249"></a><span class="lineno"> 249</span>&#160; [&amp;]</div><div class="line"><a name="l00250"></a><span class="lineno"> 250</span>&#160; {</div><div class="line"><a name="l00251"></a><span class="lineno"> 251</span>&#160; <a class="code" href="classremwharead_1_1Search.html#a8c5f3d0f81a29aca4129571271834a78">Search</a> search(segment);</div><div class="line"><a name="l00252"></a><span class="lineno"> 252</span>&#160; <span class="comment">// Replace `segment` with `result`.</span></div><div class="line"><a name="l00253"></a><span class="lineno"> 253</span>&#160; segment = search.search_all(expression, is_re);</div><div class="line"><a name="l00254"></a><span class="lineno"> 254</span>&#160; });</div><div class="line"><a name="l00255"></a><span class="lineno"> 255</span>&#160; threads.push_back(move(t));</div><div class="line"><a name="l00256"></a><span class="lineno"> 256</span>&#160; }</div><div class="line"><a name="l00257"></a><span class="lineno"> 257</span>&#160;</div><div class="line"><a name="l00258"></a><span class="lineno"> 258</span>&#160; <span class="keywordflow">for</span> (thread &amp;t : threads)</div><div class="line"><a name="l00259"></a><span class="lineno"> 259</span>&#160; {</div><div class="line"><a name="l00260"></a><span class="lineno"> 260</span>&#160; t.join();</div><div class="line"><a name="l00261"></a><span class="lineno"> 261</span>&#160; <span class="comment">// Move each of `segments` into `entries`.</span></div><div class="line"><a name="l00262"></a><span class="lineno"> 262</span>&#160; entries.splice(entries.end(), segments.front());</div><div class="line"><a name="l00263"></a><span class="lineno"> 263</span>&#160; segments.pop_front();</div><div class="line"><a name="l00264"></a><span class="lineno"> 264</span>&#160; }</div><div class="line"><a name="l00265"></a><span class="lineno"> 265</span>&#160;</div><div class="line"><a name="l00266"></a><span class="lineno"> 266</span>&#160; <span class="keywordflow">return</span> entries;</div><div class="line"><a name="l00267"></a><span class="lineno"> 267</span>&#160;</div><div class="line"><a name="l00268"></a><span class="lineno"> 268</span>&#160;}</div><div class="ttc" id="classremwharead_1_1Search_html_a8c5f3d0f81a29aca4129571271834a78"><div class="ttname"><a href="classremwharead_1_1Search.html#a8c5f3d0f81a29aca4129571271834a78">remwharead::Search::Search</a></div><div class="ttdeci">Search(list&lt; Database::entry &gt; entries)</div><div class="ttdoc">Defines the entries to search.</div><div class="ttdef"><b>Definition:</b> search.cpp:36</div></div>
</div><!-- fragment -->
</div>
</div>
<a id="a26ed67b476fa163979bb0bdcd22f964f"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a26ed67b476fa163979bb0bdcd22f964f">&#9670;&nbsp;</a></span>search_tags()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">list&lt; <a class="el" href="structremwharead_1_1Database_1_1entry.html">Database::entry</a> &gt; remwharead::Search::search_tags </td>
<td>(</td>
<td class="paramtype">const string &amp;&#160;</td>
<td class="paramname"><em>expression</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">bool&#160;</td>
<td class="paramname"><em>is_re</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td> const</td>
</tr>
</table>
</div><div class="memdoc">
<p>Search in tags of database entries. </p>
<p>Only matches whole tags, <em>Pill</em> does not match <em>Pillow</em>.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">expression</td><td>Search expression. </td></tr>
<tr><td class="paramname">is_re</td><td>Is it a regular expression?</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>List of matching <a class="el" href="structremwharead_1_1Database_1_1entry.html" title="Describes a database entry.">Database::entry</a>.</dd></dl>
<dl class="section since"><dt>Since</dt><dd>0.7.0 </dd></dl>
<div class="fragment"><div class="line"><a name="l00089"></a><span class="lineno"> 89</span>&#160;{</div><div class="line"><a name="l00090"></a><span class="lineno"> 90</span>&#160; vector&lt;vector&lt;string&gt;&gt; searchlist = parse_expression(expression);</div><div class="line"><a name="l00091"></a><span class="lineno"> 91</span>&#160; list&lt;Database::entry&gt; result;</div><div class="line"><a name="l00092"></a><span class="lineno"> 92</span>&#160;</div><div class="line"><a name="l00093"></a><span class="lineno"> 93</span>&#160; <span class="keywordflow">for</span> (<span class="keyword">const</span> vector&lt;string&gt; &amp;tags_or : searchlist)</div><div class="line"><a name="l00094"></a><span class="lineno"> 94</span>&#160; {</div><div class="line"><a name="l00095"></a><span class="lineno"> 95</span>&#160; <span class="keywordflow">for</span> (<span class="keyword">const</span> Database::entry &amp;entry : _entries)</div><div class="line"><a name="l00096"></a><span class="lineno"> 96</span>&#160; { <span class="comment">// Add entry to result if all tags in an OR-slice match.</span></div><div class="line"><a name="l00097"></a><span class="lineno"> 97</span>&#160; <span class="keywordtype">bool</span> matched = <span class="keyword">true</span>;</div><div class="line"><a name="l00098"></a><span class="lineno"> 98</span>&#160;</div><div class="line"><a name="l00099"></a><span class="lineno"> 99</span>&#160; <span class="keywordflow">for</span> (<span class="keyword">const</span> <span class="keywordtype">string</span> &amp;tag : tags_or)</div><div class="line"><a name="l00100"></a><span class="lineno"> 100</span>&#160; {</div><div class="line"><a name="l00101"></a><span class="lineno"> 101</span>&#160; <span class="keyword">const</span> <span class="keyword">auto</span> it = find_if(</div><div class="line"><a name="l00102"></a><span class="lineno"> 102</span>&#160; entry.tags.begin(), entry.tags.end(),</div><div class="line"><a name="l00103"></a><span class="lineno"> 103</span>&#160; [&amp;, is_re](<span class="keywordtype">string</span> s)</div><div class="line"><a name="l00104"></a><span class="lineno"> 104</span>&#160; {</div><div class="line"><a name="l00105"></a><span class="lineno"> 105</span>&#160; s = to_lowercase(s);</div><div class="line"><a name="l00106"></a><span class="lineno"> 106</span>&#160; <span class="keywordflow">if</span> (is_re)</div><div class="line"><a name="l00107"></a><span class="lineno"> 107</span>&#160; {</div><div class="line"><a name="l00108"></a><span class="lineno"> 108</span>&#160; <span class="keyword">const</span> RegEx re(<span class="stringliteral">&quot;^&quot;</span> + tag + <span class="stringliteral">&quot;$&quot;</span>);</div><div class="line"><a name="l00109"></a><span class="lineno"> 109</span>&#160; <span class="keywordflow">return</span> (re == s);</div><div class="line"><a name="l00110"></a><span class="lineno"> 110</span>&#160; }</div><div class="line"><a name="l00111"></a><span class="lineno"> 111</span>&#160;</div><div class="line"><a name="l00112"></a><span class="lineno"> 112</span>&#160; <span class="keywordflow">return</span> (s == tag);</div><div class="line"><a name="l00113"></a><span class="lineno"> 113</span>&#160; });</div><div class="line"><a name="l00114"></a><span class="lineno"> 114</span>&#160; <span class="keywordflow">if</span> (it == entry.tags.end())</div><div class="line"><a name="l00115"></a><span class="lineno"> 115</span>&#160; {</div><div class="line"><a name="l00116"></a><span class="lineno"> 116</span>&#160; matched = <span class="keyword">false</span>;</div><div class="line"><a name="l00117"></a><span class="lineno"> 117</span>&#160; }</div><div class="line"><a name="l00118"></a><span class="lineno"> 118</span>&#160; }</div><div class="line"><a name="l00119"></a><span class="lineno"> 119</span>&#160; <span class="keywordflow">if</span> (matched)</div><div class="line"><a name="l00120"></a><span class="lineno"> 120</span>&#160; {</div><div class="line"><a name="l00121"></a><span class="lineno"> 121</span>&#160; result.push_back(entry);</div><div class="line"><a name="l00122"></a><span class="lineno"> 122</span>&#160; }</div><div class="line"><a name="l00123"></a><span class="lineno"> 123</span>&#160; }</div><div class="line"><a name="l00124"></a><span class="lineno"> 124</span>&#160; }</div><div class="line"><a name="l00125"></a><span class="lineno"> 125</span>&#160;</div><div class="line"><a name="l00126"></a><span class="lineno"> 126</span>&#160; <span class="keywordflow">return</span> result;</div><div class="line"><a name="l00127"></a><span class="lineno"> 127</span>&#160;}</div></div><!-- fragment -->
</div>
</div>
<hr/>The documentation for this class was generated from the following files:<ul>
<li>include/<a class="el" href="search_8hpp_source.html">search.hpp</a></li>
<li>src/lib/search.cpp</li>
</ul>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.15
</small></address>
</body>
</html>