diff --git a/ftshelpers.cc b/ftshelpers.cc index 37bcfd84..8bd39667 100644 --- a/ftshelpers.cc +++ b/ftshelpers.cc @@ -459,6 +459,7 @@ void FTSResultsRequest::checkArticles( QVector< uint32_t > const & offsets, int pos = 0; int matchWordNom = 0; int unmatchWordNom = 0; + int nextNotFoundPos = 0; QVector< QStringList > allOrders; QStringList order; @@ -539,8 +540,15 @@ void FTSResultsRequest::checkArticles( QVector< uint32_t > const & offsets, if( i < wordsList.size() ) { // Word found + matchWordNom += 1; + if( matchWordNom == 1 ) + { + // Store position to remake search if sequence will not be found + nextNotFoundPos = pos + ( s.isEmpty() ? 1 : s.length() ); + } + if( matchWordNom >= words.size() ) { // All words are found @@ -563,6 +571,7 @@ void FTSResultsRequest::checkArticles( QVector< uint32_t > const & offsets, unmatchWordNom = 0; for( int i = 0; i < wordsList.size(); i++ ) wordsList[ i ].second = true; + nextNotFoundPos = 0; break; } @@ -592,6 +601,12 @@ void FTSResultsRequest::checkArticles( QVector< uint32_t > const & offsets, { matchWordNom += 1; + if( matchWordNom == 1 ) + { + // Store position to remake search if sequence will not be found + nextNotFoundPos = pos + ( s.isEmpty() ? 1 : s.length() ); + } + if( needHandleBrackets ) { if( parsedWords.size() > 1 ) @@ -628,6 +643,7 @@ void FTSResultsRequest::checkArticles( QVector< uint32_t > const & offsets, matchWordNom = 0; unmatchWordNom = 0; order.clear(); + nextNotFoundPos = 0; } else breakSearch = true; @@ -652,7 +668,13 @@ void FTSResultsRequest::checkArticles( QVector< uint32_t > const & offsets, } if( breakSearch ) break; - pos += s.isEmpty() ? 1 : s.length(); + if( nextNotFoundPos > 0 && matchWordNom == 0 ) + { + pos = nextNotFoundPos; + nextNotFoundPos = 0; + } + else + pos += s.isEmpty() ? 1 : s.length(); } }