<table><tr><td style="">poboiko created this revision.<br />poboiko added reviewers: Baloo, ngraham, bruns.<br />Herald added projects: Frameworks, Baloo.<br />poboiko requested review of this revision.
</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/D22166">View Revision</a></tr></table><br /><div><strong>REVISION SUMMARY</strong><div><p>AdvancedQueryParser's lexxer can actually handle double quotes:<br />
for query <tt style="background: #ebebeb; font-size: 13px;">a "b c" d</tt>, it returns three tokens (<tt style="background: #ebebeb; font-size: 13px;">a</tt>, <tt style="background: #ebebeb; font-size: 13px;">b c</tt>, <tt style="background: #ebebeb; font-size: 13px;">d</tt>).<br />
However, when building <tt style="background: #ebebeb; font-size: 13px;">Term</tt>, all of them end up having <tt style="background: #ebebeb; font-size: 13px;">Auto</tt> comparator,<br />
which for strings then resolves to <tt style="background: #ebebeb; font-size: 13px;">Contains</tt>.<br />
Finally, inside <tt style="background: #ebebeb; font-size: 13px;">SearchStore::constructContainsQuery</tt>, we simply split such<br />
multi-word term and build an <tt style="background: #ebebeb; font-size: 13px;">EngineQuery::StartsWith</tt> query for <tt style="background: #ebebeb; font-size: 13px;">b</tt> and <tt style="background: #ebebeb; font-size: 13px;">c</tt>.</p>

<p>This patch sets <tt style="background: #ebebeb; font-size: 13px;">Equal</tt> comparator for those terms that are inside double quotes.<br />
For that we call <tt style="background: #ebebeb; font-size: 13px;">SearchStore::constructEqualsQuery</tt>, which treats it as<br />
<tt style="background: #ebebeb; font-size: 13px;">EngineQuery::Phrase</tt>, which is precicely what we want.</p>

<p>Code-wise, it's more convenient to create a separate class <tt style="background: #ebebeb; font-size: 13px;">Token</tt> (instead of<br />
treating tokens as <tt style="background: #ebebeb; font-size: 13px;">QString</tt>), which is aware if this token is inside double quotes.<br />
This patch also moves some of the token-processing routine inside this class<br />
(see <tt style="background: #ebebeb; font-size: 13px;">toVariant</tt>, <tt style="background: #ebebeb; font-size: 13px;">toComp</tt>, <tt style="background: #ebebeb; font-size: 13px;">toOp</tt> methods)</p>

<p>Also, introduce various tests with double-quoted queries.</p></div></div><br /><div><strong>TEST PLAN</strong><div><div class="remarkup-code-block" style="margin: 12px 0;" data-code-lang="console" data-sigil="remarkup-code-block"><pre class="remarkup-code" style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; padding: 12px; margin: 0; background: rgba(71, 87, 120, 0.08);"><span style="color: #000080">$ ctest</span>
<span style="color: #000080">$ echo "some unique phrase" > ~/test</span>
<span style="color: #000080">$ baloosearch '"some unique phrase"'</span></pre></div>

<p>(only <tt style="background: #ebebeb; font-size: 13px;">~/test</tt> should pop up)</p></div></div><br /><div><strong>REPOSITORY</strong><div><div>R293 Baloo</div></div></div><br /><div><strong>BRANCH</strong><div><div>phrasesearch</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D22166">https://phabricator.kde.org/D22166</a></div></div><br /><div><strong>AFFECTED FILES</strong><div><div>autotests/unit/lib/advancedqueryparsertest.cpp<br />
src/lib/advancedqueryparser.cpp</div></div></div><br /><div><strong>To: </strong>poboiko, Baloo, ngraham, bruns<br /><strong>Cc: </strong>kde-frameworks-devel, LeGast00n, fbampaloukas, domson, ashaposhnikov, michaelh, astippich, spoorun, ngraham, bruns, abrahams<br /></div>