<table><tr><td style="">bruns added a comment.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D11828">View Revision</a></tr></table><br /><div><div><blockquote style="border-left: 3px solid #8C98B8;
color: #6B748C;
font-style: italic;
margin: 4px 0 12px 0;
padding: 8px 12px;
background-color: #F8F9FC;">
<div style="font-style: normal;
padding-bottom: 4px;">In <a href="https://phabricator.kde.org/D11828#242402" style="background-color: #e7e7e7;
border-color: #e7e7e7;
border-radius: 3px;
padding: 0 4px;
font-weight: bold;
color: black;text-decoration: none;">D11828#242402</a>, <a href="https://phabricator.kde.org/p/michaelh/" style="
border-color: #f1f7ff;
color: #19558d;
background-color: #f1f7ff;
border: 1px solid transparent;
border-radius: 3px;
font-weight: bold;
padding: 0 4px;">@michaelh</a> wrote:</div>
<div style="margin: 0;
padding: 0;
border: 0;
color: rgb(107, 116, 140);"><p>I'm not very familiar with the concept of iterators (yet). To me it looks like <tt style="background: #ebebeb; font-size: 13px;">auto i = new OrPostingIterator(iters); i->docId();</tt> will return 0 and <tt style="background: #ebebeb; font-size: 13px;">i->next()</tt> returns a valid docId. After that <tt style="background: #ebebeb; font-size: 13px;">i->docId();</tt> is also valid.<br />
Is this how iterators work? Naively I would expect <tt style="background: #ebebeb; font-size: 13px;">i->docId();</tt> to be valid after construction or both <tt style="background: #ebebeb; font-size: 13px;">i->docId();</tt> and <tt style="background: #ebebeb; font-size: 13px;">i->next()</tt> to be invalid.</p>
<p>I have to admit, it's very difficult to understand (and I don't, really) what baloo is doing here with all this iterating over vectors of inherited iterator classes, pointer-to-pointer stuff of which some might not even exist. My brain hurts, terribly! All I can presently do is ask some simple questions. Sorry, I'm of no help here. Please take my comments as a device for better understanding and I hope it's not to much of a bother.</p></div>
</blockquote>
<p>Each PostingIterator represents a "set" of document ids. PostingIterators are not related to STL or Qt container iterators (although the "subiterators" are implemented using QVectors<>).</p>
<p>The <tt style="background: #ebebeb; font-size: 13px;">PI::next()</tt> call returns the smallest element and removes it from the set, <tt style="background: #ebebeb; font-size: 13px;">PI::docId()</tt> just returns the smallest element.</p>
<p>The result set of the OrPostingIterator is the union of its "subsets" (represented by its "subiterators", i.e. the QVector<PostingIterator*> constructor argument). Or works a little bit like an insertion sort. To return the smallest element, it creates the union of the smallest element of all subsets, and yields the smallest element of the union. It then calls <tt style="background: #ebebeb; font-size: 13px;">PI::next()</tt> on all subsets which returned the smallest element, removing it from all subsets and thus from the union.</p>
<p>In C++, you can use iterators in two different ways, either PreIncrement or PostIncrement. <tt style="background: #ebebeb; font-size: 13px;">PostingIterator::next()</tt> will behave like <tt style="background: #ebebeb; font-size: 13px;">*(++it)</tt>, i.e. it is incremented first, then the current value is returned.</p>
<p>I don't know the original justification for this design. One possible idea is to delay the actual database query until <tt style="background: #ebebeb; font-size: 13px;">next()</tt> is called the first time. For e.g. a query "a AND b AND c", one can execute "a", if not empty do "b", intersect (i.e. calling the Iterators of Result("a") and Result("b") until both return the same value), and if the intersection is non-empty, do "c".</p>
<p>Currently, it does not implement this optimization. <a href="https://phabricator.kde.org/D12025" style="background-color: #e7e7e7;
border-color: #e7e7e7;
border-radius: 3px;
padding: 0 4px;
font-weight: bold;
color: black;text-decoration: none;">D12025</a> implements one case, i.e. stopping if a leaf query returns an empty set, and propagating it upwards.</p></div></div><br /><div><strong>REPOSITORY</strong><div><div>R293 Baloo</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D11828">https://phabricator.kde.org/D11828</a></div></div><br /><div><strong>To: </strong>bruns, Baloo, michaelh<br /><strong>Cc: </strong>Frameworks, ashaposhnikov, michaelh, astippich, spoorun, ngraham, bruns, alexeymin<br /></div>