qt5.15.2 does not work with qtconcurrent::blockingmapped

This commit is contained in:
Xiao YiFang 2022-06-08 21:38:30 +08:00
parent 76969aa49d
commit 837dcfbf63

View file

@ -447,180 +447,7 @@ void FTSResultsRequest::checkArticles( QVector< uint32_t > const & offsets,
QStringList const & words, QStringList const & words,
QRegExp const & searchRegexp ) QRegExp const & searchRegexp )
{ {
// int results = 0; QtConcurrent::blockingMap( offsets, [ & ]( uint32_t offset ) { checkSingleArticle( offset, words, searchRegexp ); } );
QString headword, articleText;
QList< uint32_t > offsetsForHeadwords;
QVector< QStringList > hiliteRegExps;
QString id = QString::fromUtf8( dict.getId().c_str() );
// RegExp mode
QRegularExpression searchRegularExpression;
if( searchMode == FTS::Wildcards )
searchRegularExpression.setPattern( wildcardsToRegexp( searchRegexp.pattern() ) );
else
searchRegularExpression.setPattern( searchRegexp.pattern() );
QRegularExpression::PatternOptions patternOptions =
QRegularExpression::DotMatchesEverythingOption | QRegularExpression::UseUnicodePropertiesOption
| QRegularExpression::MultilineOption | QRegularExpression::InvertedGreedinessOption;
if( searchRegexp.caseSensitivity() == Qt::CaseInsensitive )
patternOptions |= QRegularExpression::CaseInsensitiveOption;
searchRegularExpression.setPatternOptions( patternOptions );
if( !searchRegularExpression.isValid() )
searchRegularExpression.setPattern( "" );
if( searchMode == FTS::Wildcards || searchMode == FTS::RegExp )
{
for( int i = 0; i < offsets.size(); i++ )
{
if( Utils::AtomicInt::loadAcquire( isCancelled ) )
break;
dict.getArticleText( offsets.at( i ), headword, articleText );
articleText = articleText.normalized( QString::NormalizationForm_C );
if( ignoreDiacritics )
articleText = gd::toQString( Folding::applyDiacriticsOnly( gd::toWString( articleText ) ) );
if( articleText.contains( searchRegularExpression ) )
{
if( headword.isEmpty() )
offsetsForHeadwords.append( offsets.at( i ) );
else
foundHeadwords->append( FTS::FtsHeadword( headword, id, QStringList(), matchCase ) );
results++;
if( maxResults > 0 && results >= maxResults )
break;
}
}
}
else
{
// Words mode
Qt::CaseSensitivity cs = matchCase ? Qt::CaseSensitive : Qt::CaseInsensitive;
QVector< QPair< QString, bool > > wordsList;
if( ignoreWordsOrder )
{
for( QStringList::const_iterator it = words.begin(); it != words.end(); ++it )
wordsList.append( QPair< QString, bool >( *it, true ) );
}
for( int i = 0; i < offsets.size(); i++ )
{
if( Utils::AtomicInt::loadAcquire( isCancelled ) )
break;
QVector< QStringList > allOrders;
QStringList order;
if( ignoreWordsOrder )
{
for( int i = 0; i < wordsList.size(); i++ )
wordsList[ i ].second = true;
}
dict.getArticleText( offsets.at( i ), headword, articleText );
articleText = articleText.normalized( QString::NormalizationForm_C );
if( ignoreDiacritics )
articleText = gd::toQString( Folding::applyDiacriticsOnly( gd::toWString( articleText ) ) );
if(ignoreWordsOrder)
{
bool allMatch = true;
foreach( QString word, words )
{
if( containCJK( word ) || searchMode == FTS::PlainText )
{
if( !articleText.contains( word ) )
{
allMatch = false;
break;
}
}
else if( searchMode == FTS::WholeWords)
{
QRegularExpression tmpReg( QString( "\b%1\b" ).arg( word ),QRegularExpression::CaseInsensitiveOption|QRegularExpression::UseUnicodePropertiesOption );
if( !articleText.contains( tmpReg) )
{
allMatch = false;
break;
}
}
}
if(!allMatch)
{
continue;
}
if( distanceBetweenWords >= 0 )
{
// the article text contains all the needed words.
// determine if distance restriction is meet
QRegularExpression replaceReg( QString( "(%1)" ).arg( words.join( '|' ) ),
QRegularExpression::CaseInsensitiveOption |
QRegularExpression::UseUnicodePropertiesOption );
// use a string that could not be presented in the article.
articleText = articleText.replace( replaceReg, "=@XXXXX@=" );
auto hasCJK = false;
foreach(QString word,words)
{
if(containCJK( word ))
{
hasCJK = true;
break;
}
}
//hascjk value ,perhaps should depend on each word
auto searchRegStr = makeHiliteRegExpString( Utils::repeat( "=@XXXXX@=", words.size() ), searchMode, distanceBetweenWords,hasCJK );
QRegularExpression distanceOrderReg( searchRegStr,
QRegularExpression::CaseInsensitiveOption |
QRegularExpression::UseUnicodePropertiesOption );
// use a string that could not be presented in the article.
if(articleText.contains(distanceOrderReg))
{
if( headword.isEmpty() )
offsetsForHeadwords.append( offsets.at( i ) );
else
foundHeadwords->append( FTS::FtsHeadword( headword, id, QStringList(), matchCase ) );
++results;
if( maxResults > 0 && results >= maxResults )
break;
}
}
}
else
{
if( articleText.contains( searchRegularExpression ) )
{
if( headword.isEmpty() )
offsetsForHeadwords.append( offsets.at( i ) );
else
foundHeadwords->append( FTS::FtsHeadword( headword, id, QStringList(), matchCase ) );
++results;
if( maxResults > 0 && results >= maxResults )
break;
}
}
}
}
if( !offsetsForHeadwords.isEmpty() )
{
QVector< QString > headwords;
dict.getHeadwordsFromOffsets( offsetsForHeadwords, headwords, &isCancelled );
for( int x = 0; x < headwords.size(); x++ )
foundHeadwords->append( FTS::FtsHeadword( headwords.at( x ), id, x < hiliteRegExps.size() ? hiliteRegExps.at( x ) : QStringList(), matchCase ) );
}
} }
void FTSResultsRequest::checkSingleArticle( uint32_t offset, void FTSResultsRequest::checkSingleArticle( uint32_t offset,
@ -819,13 +646,15 @@ void FTSResultsRequest::indexSearch( BtreeIndexing::BtreeIndex & ftsIndex,
if( indexWords.isEmpty() ) if( indexWords.isEmpty() )
return; return;
auto findLinks = [ & ]( const QString & word ) -> QSet< uint32_t > QList< QSet< uint32_t > > addressLists;
auto findLinks = [ & ]( const QString & word )
{ {
QSet< uint32_t > tmp; QSet< uint32_t > tmp;
uint32_t size; uint32_t size;
if( Utils::AtomicInt::loadAcquire( isCancelled ) ) if( Utils::AtomicInt::loadAcquire( isCancelled ) )
return tmp; addressLists<< tmp;
vector< BtreeIndexing::WordArticleLink > links = vector< BtreeIndexing::WordArticleLink > links =
ftsIndex.findArticles( gd::toWString( word ), ignoreDiacritics ); ftsIndex.findArticles( gd::toWString( word ), ignoreDiacritics );
@ -833,7 +662,7 @@ void FTSResultsRequest::indexSearch( BtreeIndexing::BtreeIndex & ftsIndex,
{ {
if( Utils::AtomicInt::loadAcquire( isCancelled ) ) if( Utils::AtomicInt::loadAcquire( isCancelled ) )
return tmp; addressLists<< tmp;
vector< char > chunk; vector< char > chunk;
char * linksPtr; char * linksPtr;
@ -853,14 +682,13 @@ void FTSResultsRequest::indexSearch( BtreeIndexing::BtreeIndex & ftsIndex,
links.clear(); links.clear();
return tmp; addressLists<< tmp;
}; };
// int n = indexWords.length(); // int n = indexWords.length();
auto sets = QtConcurrent::blockingMapped( indexWords, QtConcurrent::blockingMap( indexWords, findLinks );
findLinks );
int i = 0; int i = 0;
for( auto & elem : sets ) for( auto & elem : addressLists )
{ {
if( i++ == 0 ) if( i++ == 0 )
setOfOffsets = elem; setOfOffsets = elem;
@ -887,11 +715,7 @@ void FTSResultsRequest::indexSearch( BtreeIndexing::BtreeIndex & ftsIndex,
dict.sortArticlesOffsetsForFTS( offsets, isCancelled ); dict.sortArticlesOffsetsForFTS( offsets, isCancelled );
//#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0)) checkArticles( offsets, searchWords, regexp );
QtConcurrent::blockingMap(offsets,[&](uint32_t offset){checkSingleArticle(offset,searchWords,regexp);});
//#else
// checkArticles( offsets, searchWords, regexp );
//#endif
} }
void FTSResultsRequest::combinedIndexSearch( BtreeIndexing::BtreeIndex & ftsIndex, void FTSResultsRequest::combinedIndexSearch( BtreeIndexing::BtreeIndex & ftsIndex,
@ -934,17 +758,15 @@ void FTSResultsRequest::combinedIndexSearch( BtreeIndexing::BtreeIndex & ftsInde
if( !hieroglyphsList.empty() ) if( !hieroglyphsList.empty() )
{ {
QSet< uint32_t > tmp; QList< QSet< uint32_t > > sets;
vector< BtreeIndexing::WordArticleLink > links; auto fn_wordLink = [ & ](const QString & word )
for( int i = 0; i < hieroglyphsList.size(); i++ )
{ {
links = ftsIndex.findArticles( gd::toWString( hieroglyphsList.at( i ) ) ); QSet< uint32_t > tmp;
vector< BtreeIndexing::WordArticleLink > links = ftsIndex.findArticles( gd::toWString( word ) );
for( unsigned x = 0; x < links.size(); x++ ) for( unsigned x = 0; x < links.size(); x++ )
{ {
if( Utils::AtomicInt::loadAcquire( isCancelled ) ) if( Utils::AtomicInt::loadAcquire( isCancelled ) )
return; sets<< tmp;
vector< char > chunk; vector< char > chunk;
char * linksPtr; char * linksPtr;
@ -963,11 +785,17 @@ void FTSResultsRequest::combinedIndexSearch( BtreeIndexing::BtreeIndex & ftsInde
} }
links.clear(); links.clear();
sets<< tmp;
};
QtConcurrent::blockingMap( hieroglyphsList, fn_wordLink );
if( i == 0 ) int i = 0;
setOfOffsets = tmp; for( auto & elem : sets )
{
if( i++ == 0 )
setOfOffsets = elem;
else else
setOfOffsets = setOfOffsets.intersect( tmp ); setOfOffsets = setOfOffsets.intersect( elem );
} }
allWordsLinks[ wordNom ] = setOfOffsets; allWordsLinks[ wordNom ] = setOfOffsets;