opt: respect maxResult parameter (#1611)

* opt: respect maxResult parameter

* opt: respect maxResult parameter

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
xiaoyifang 2024-06-24 13:33:47 +08:00 committed by GitHub
parent 2b9d17251b
commit c82db14ea7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -272,6 +272,9 @@ void BtreeWordSearchRequest::findMatches()
QMutexLocker _( &dataMutex );
for ( auto & x : chain ) {
if ( Utils::AtomicInt::loadAcquire( isCancelled ) ) {
break;
}
if ( useWildcards ) {
wstring word = Utf8::decode( x.prefix + x.word );
wstring result = Folding::applyDiacriticsOnly( word );
@ -290,15 +293,15 @@ void BtreeWordSearchRequest::findMatches()
|| (int)resultFolded.size() - initialFoldedSize <= maxSuffixVariation ) )
addMatch( Utf8::decode( x.prefix + x.word ) );
}
if ( matches.size() >= maxResults ) {
break;
}
}
if ( Utils::AtomicInt::loadAcquire( isCancelled ) )
break;
if ( matches.size() >= maxResults ) {
// For now we actually allow more than maxResults if the last
// chain yield more than one result. That's ok and maybe even more
// desirable.
break;
}
}