diff --git a/autotests/unit/engine/queryparsertest.cpp b/autotests/unit/engine/queryparsertest.cpp --- a/autotests/unit/engine/queryparsertest.cpp +++ b/autotests/unit/engine/queryparsertest.cpp @@ -278,12 +278,12 @@ addRow("No phrase", { {{"no"}, {"phrase"}}, EngineQuery::And}, ""); addRow("Underscore_phrase", { {{"underscore"}, {"phrase"}}, EngineQuery::Phrase}, ""); addRow("underscore_dot.phrase", { {{"underscore"}, {"dot"}, {"phrase"}}, EngineQuery::Phrase}, ""); - addRow("\'Quoted phrase\'", { {{"quoted"}, {"phrase"}}, EngineQuery::Phrase}, "End quote as last char"); + addRow("\'Quoted phrase\'", { {{"quoted"}, {"phrase"}}, EngineQuery::Phrase}, ""); addRow("\'Quoted phrase\' anded tail", {{ {{{"quoted"}, {"phrase"}}, EngineQuery::Phrase}, {"anded"}, {"tail"}, }, EngineQuery::And}, ""); - addRow("\'Long quoted phrase\'", { {{"long"}, {"quoted"}, {"phrase"}}, EngineQuery::Phrase}, "End quote as last char"); + addRow("\'Long quoted phrase\'", { {{"long"}, {"quoted"}, {"phrase"}}, EngineQuery::Phrase}, ""); addRow("Anded dot.phrase", { { {"anded"}, {{{"dot"}, {"phrase"}}, EngineQuery::Phrase}, @@ -298,21 +298,21 @@ }, EngineQuery::And}, ""); addRow("\'One quoted with.dot\'", {{ {"one"}, {"quoted"}, {"with"}, {"dot"} - }, EngineQuery::Phrase}, "End quote as last char"); + }, EngineQuery::Phrase}, ""); addRow("\'Quoted_underscore and.dot\'", {{ {"quoted"}, {"underscore"}, {"and"}, {"dot"} - }, EngineQuery::Phrase}, "End quote as last char"); + }, EngineQuery::Phrase}, ""); addRow("Underscore_andTrailingDot_.", {{ {"underscore"}, {"andtrailingdot"} }, EngineQuery::Phrase}, ""); addRow("\'TrailingUnderscore_ andDot.\'", {{ {"trailingunderscore"}, {"anddot"} - }, EngineQuery::Phrase}, "End quote as last char"); + }, EngineQuery::Phrase}, ""); addRow("NoPhrase Under_score \'Quoted Phrase\'", {{ {"nophrase"}, {{{"under"}, {"score"}}, EngineQuery::Phrase}, {{{"quoted"}, {"phrase"}}, EngineQuery::Phrase}, - }, EngineQuery::And}, "End quote as last char"); + }, EngineQuery::And}, ""); addRow("NoPhrase \'Quoted Phrase\' Under_score", {{ {"nophrase"}, {{{"quoted"}, {"phrase"}}, EngineQuery::Phrase}, diff --git a/src/engine/queryparser.cpp b/src/engine/queryparser.cpp --- a/src/engine/queryparser.cpp +++ b/src/engine/queryparser.cpp @@ -61,10 +61,10 @@ QTextBoundaryFinder bf(QTextBoundaryFinder::Word, text); for (; bf.position() != -1; bf.toNextBoundary()) { - if (bf.boundaryReasons() & QTextBoundaryFinder::StartOfItem) { + int pos = bf.position(); + if (!(bf.boundaryReasons() & QTextBoundaryFinder::EndOfItem)) { // // Check the previous delimiter - int pos = bf.position(); if (pos != end) { QString delim = text_.mid(end, pos-end); if (delim.contains(QLatin1Char('"'))) { @@ -88,7 +88,7 @@ } } else if (!containsSpace(delim)) { - if (!inPhrase && !queries.isEmpty()) { + if (phraseQueries.isEmpty() && !queries.isEmpty()) { EngineQuery q = queries.takeLast(); q.setOp(EngineQuery::Equal); phraseQueries << q; @@ -100,9 +100,12 @@ phraseQueries.clear(); inPhrase = false; } + end = pos; } + } - start = bf.position(); + if (bf.boundaryReasons() & QTextBoundaryFinder::StartOfItem) { + start = pos; continue; } else if (bf.boundaryReasons() & QTextBoundaryFinder::EndOfItem) { @@ -140,20 +143,16 @@ if (inPhrase) { queries << EngineQuery(phraseQueries, EngineQuery::Phrase); - phraseQueries.clear(); - inPhrase = false; - } - if (!phraseQueries.isEmpty()) { + } else if (!phraseQueries.isEmpty()) { for (EngineQuery& q : phraseQueries) { if (m_autoExpandSize && q.term().size() >= m_autoExpandSize) { q.setOp(EngineQuery::StartsWith); } else { q.setOp(EngineQuery::Equal); } } queries << phraseQueries; - phraseQueries.clear(); } if (queries.size() == 1) {