Full-text search: Use separate thread pool for search requests

This commit is contained in:
Abs62 2022-09-06 17:40:22 +03:00
parent c5f0f536fa
commit e333a03d7c
18 changed files with 83 additions and 42 deletions

View file

@ -274,7 +274,8 @@ class AardDictionary: public BtreeIndexing::BtreeDictionary
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ); bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr );
virtual void getArticleText( uint32_t articleAddress, QString & headword, QString & text ); virtual void getArticleText( uint32_t articleAddress, QString & headword, QString & text );
virtual void makeFTSIndex(QAtomicInt & isCancelled, bool firstIteration ); virtual void makeFTSIndex(QAtomicInt & isCancelled, bool firstIteration );
@ -657,9 +658,10 @@ sptr< Dictionary::DataRequest > AardDictionary::getSearchResults( QString const
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ) bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr )
{ {
return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics, ftsThreadPoolPtr );
} }
/// AardDictionary::getArticle() /// AardDictionary::getArticle()

8
bgl.cc
View file

@ -244,7 +244,8 @@ namespace
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ); bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr );
virtual QString const& getDescription(); virtual QString const& getDescription();
virtual void getArticleText( uint32_t articleAddress, QString & headword, QString & text ); virtual void getArticleText( uint32_t articleAddress, QString & headword, QString & text );
@ -1211,9 +1212,10 @@ sptr< Dictionary::DataRequest > BglDictionary::getSearchResults( QString const &
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ) bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr )
{ {
return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics, ftsThreadPoolPtr );
} }

View file

@ -135,7 +135,8 @@ public:
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ); bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr );
void getArticleText( uint32_t articleAddress, QString & headword, QString & text ); void getArticleText( uint32_t articleAddress, QString & headword, QString & text );
virtual void makeFTSIndex(QAtomicInt & isCancelled, bool firstIteration ); virtual void makeFTSIndex(QAtomicInt & isCancelled, bool firstIteration );
@ -599,9 +600,10 @@ sptr< Dictionary::DataRequest > DictdDictionary::getSearchResults( QString const
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ) bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr )
{ {
return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics, ftsThreadPoolPtr );
} }
} // anonymous namespace } // anonymous namespace

View file

@ -175,7 +175,7 @@ sptr< DataRequest > Class::getResource( string const & /*name*/ )
return new DataRequestInstant( false ); return new DataRequestInstant( false );
} }
sptr< DataRequest > Class::getSearchResults(const QString &, int, bool, int, int, bool, bool ) sptr< DataRequest > Class::getSearchResults(const QString &, int, bool, int, int, bool, bool, QThreadPool * )
{ {
return new DataRequestInstant( false ); return new DataRequestInstant( false );
} }

View file

@ -9,6 +9,7 @@
#include <map> #include <map>
#include <QObject> #include <QObject>
#include <QIcon> #include <QIcon>
#include <QThreadPool>
#include "cpp_features.hh" #include "cpp_features.hh"
#include "sptr.hh" #include "sptr.hh"
#include "ex.hh" #include "ex.hh"
@ -400,7 +401,8 @@ public:
int distanceBetweenWords, int distanceBetweenWords,
int maxArticlesPerDictionary, int maxArticlesPerDictionary,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ); bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr );
// Return dictionary description if presented // Return dictionary description if presented
virtual QString const& getDescription(); virtual QString const& getDescription();

8
dsl.cc
View file

@ -236,7 +236,8 @@ public:
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ); bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr );
virtual QString const& getDescription(); virtual QString const& getDescription();
virtual QString getMainFilename(); virtual QString getMainFilename();
@ -2047,9 +2048,10 @@ sptr< Dictionary::DataRequest > DslDictionary::getSearchResults( QString const &
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ) bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr )
{ {
return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics, ftsThreadPoolPtr );
} }
} // anonymous namespace } // anonymous namespace

View file

@ -130,7 +130,8 @@ public:
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ); bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr );
virtual void getArticleText( uint32_t articleAddress, QString & headword, QString & text ); virtual void getArticleText( uint32_t articleAddress, QString & headword, QString & text );
virtual void makeFTSIndex(QAtomicInt & isCancelled, bool firstIteration ); virtual void makeFTSIndex(QAtomicInt & isCancelled, bool firstIteration );
@ -796,9 +797,10 @@ sptr< Dictionary::DataRequest > EpwingDictionary::getSearchResults( QString cons
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ) bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr )
{ {
return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics, ftsThreadPoolPtr );
} }
int EpwingDictionary::japaneseWriting( gd::wchar ch ) int EpwingDictionary::japaneseWriting( gd::wchar ch )

View file

@ -1149,6 +1149,12 @@ void FTSResultsRequest::fullSearch( QStringList & searchWords, QRegExp & regexp
void FTSResultsRequest::run() void FTSResultsRequest::run()
{ {
if( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;
}
if ( dict.ensureInitDone().size() ) if ( dict.ensureInitDone().size() )
{ {
setErrorString( QString::fromUtf8( dict.ensureInitDone().c_str() ) ); setErrorString( QString::fromUtf8( dict.ensureInitDone().c_str() ) );

View file

@ -129,7 +129,7 @@ public:
FTSResultsRequest( BtreeIndexing::BtreeDictionary & dict_, QString const & searchString_, FTSResultsRequest( BtreeIndexing::BtreeDictionary & dict_, QString const & searchString_,
int searchMode_, bool matchCase_, int distanceBetweenWords_, int maxResults_, int searchMode_, bool matchCase_, int distanceBetweenWords_, int maxResults_,
bool ignoreWordsOrder_, bool ignoreDiacritics_ ): bool ignoreWordsOrder_, bool ignoreDiacritics_, QThreadPool * ftsThreadPoolPtr ):
dict( dict_ ), dict( dict_ ),
searchString( searchString_ ), searchString( searchString_ ),
searchMode( searchMode_ ), searchMode( searchMode_ ),
@ -145,7 +145,7 @@ public:
searchString = gd::toQString( Folding::applyDiacriticsOnly( gd::toWString( searchString_ ) ) ); searchString = gd::toQString( Folding::applyDiacriticsOnly( gd::toWString( searchString_ ) ) );
foundHeadwords = new QList< FTS::FtsHeadword >; foundHeadwords = new QList< FTS::FtsHeadword >;
QThreadPool::globalInstance()->start( ftsThreadPoolPtr->start(
new FTSResultsRequestRunnable( *this, hasExited ), -100 ); new FTSResultsRequestRunnable( *this, hasExited ), -100 );
} }

View file

@ -138,11 +138,15 @@ FullTextSearchDialog::FullTextSearchDialog( QWidget * parent,
group( 0 ), group( 0 ),
ignoreWordsOrder( cfg_.preferences.fts.ignoreWordsOrder ), ignoreWordsOrder( cfg_.preferences.fts.ignoreWordsOrder ),
ignoreDiacritics( cfg_.preferences.fts.ignoreDiacritics ), ignoreDiacritics( cfg_.preferences.fts.ignoreDiacritics ),
ftsThreadPool( this ),
searchInProgress( false ),
ftsIdx( ftsidx ) ftsIdx( ftsidx )
, helpAction( this ) , helpAction( this )
{ {
ui.setupUi( this ); ui.setupUi( this );
ftsThreadPool.setExpiryTimeout( -1 );
setAttribute( Qt::WA_DeleteOnClose, false ); setAttribute( Qt::WA_DeleteOnClose, false );
setWindowFlags( windowFlags() & ~Qt::WindowContextHelpButtonHint ); setWindowFlags( windowFlags() & ~Qt::WindowContextHelpButtonHint );
@ -429,11 +433,13 @@ void FullTextSearchDialog::accept()
distanceBetweenWords, distanceBetweenWords,
maxResultsPerDict, maxResultsPerDict,
ignoreWordsOrder, ignoreWordsOrder,
ignoreDiacritics ignoreDiacritics,
&ftsThreadPool
); );
connect( req.get(), SIGNAL( finished() ), connect( req.get(), SIGNAL( finished() ),
this, SLOT( searchReqFinished() ), Qt::QueuedConnection ); this, SLOT( searchReqFinished() ), Qt::QueuedConnection );
searchInProgress = true;
searchReqs.push_back( req ); searchReqs.push_back( req );
} }
@ -486,8 +492,9 @@ void FullTextSearchDialog::searchReqFinished()
else else
break; break;
} }
if ( searchReqs.empty() ) if ( searchReqs.empty() && searchInProgress )
{ {
searchInProgress = false;
ui.searchProgressBar->hide(); ui.searchProgressBar->hide();
ui.OKButton->setEnabled( true ); ui.OKButton->setEnabled( true );
QApplication::beep(); QApplication::beep();

View file

@ -177,6 +177,8 @@ class FullTextSearchDialog : public QDialog
std::vector< sptr< Dictionary::Class > > activeDicts; std::vector< sptr< Dictionary::Class > > activeDicts;
bool ignoreWordsOrder; bool ignoreWordsOrder;
bool ignoreDiacritics; bool ignoreDiacritics;
QThreadPool ftsThreadPool;
bool searchInProgress;
std::list< sptr< Dictionary::DataRequest > > searchReqs; std::list< sptr< Dictionary::DataRequest > > searchReqs;

8
gls.cc
View file

@ -489,7 +489,8 @@ public:
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ); bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr );
virtual void getArticleText( uint32_t articleAddress, QString & headword, QString & text ); virtual void getArticleText( uint32_t articleAddress, QString & headword, QString & text );
@ -1559,9 +1560,10 @@ sptr< Dictionary::DataRequest > GlsDictionary::getSearchResults( QString const &
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ) bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr )
{ {
return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics, ftsThreadPoolPtr );
} }
} // anonymous namespace } // anonymous namespace

8
mdx.cc
View file

@ -257,7 +257,8 @@ public:
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ); bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr );
virtual void getArticleText( uint32_t articleAddress, QString & headword, QString & text ); virtual void getArticleText( uint32_t articleAddress, QString & headword, QString & text );
virtual void makeFTSIndex(QAtomicInt & isCancelled, bool firstIteration ); virtual void makeFTSIndex(QAtomicInt & isCancelled, bool firstIteration );
@ -536,9 +537,10 @@ sptr< Dictionary::DataRequest > MdxDictionary::getSearchResults( QString const &
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ) bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr )
{ {
return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics, ftsThreadPoolPtr );
} }
/// MdxDictionary::getArticle /// MdxDictionary::getArticle

View file

@ -174,7 +174,8 @@ class SdictDictionary: public BtreeIndexing::BtreeDictionary
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ); bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr );
virtual void getArticleText( uint32_t articleAddress, QString & headword, QString & text ); virtual void getArticleText( uint32_t articleAddress, QString & headword, QString & text );
virtual void makeFTSIndex(QAtomicInt & isCancelled, bool firstIteration ); virtual void makeFTSIndex(QAtomicInt & isCancelled, bool firstIteration );
@ -483,9 +484,10 @@ sptr< Dictionary::DataRequest > SdictDictionary::getSearchResults( QString const
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ) bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr )
{ {
return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics, ftsThreadPoolPtr );
} }
/// SdictDictionary::getArticle() /// SdictDictionary::getArticle()

View file

@ -623,7 +623,8 @@ class SlobDictionary: public BtreeIndexing::BtreeDictionary
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ); bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr );
virtual void getArticleText( uint32_t articleAddress, QString & headword, QString & text ); virtual void getArticleText( uint32_t articleAddress, QString & headword, QString & text );
quint64 getArticlePos(uint32_t articleNumber ); quint64 getArticlePos(uint32_t articleNumber );
@ -1344,9 +1345,10 @@ sptr< Dictionary::DataRequest > SlobDictionary::getSearchResults( QString const
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ) bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr )
{ {
return new FtsHelpers::FTSResultsRequest( *this, searchString, searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); return new FtsHelpers::FTSResultsRequest( *this, searchString, searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics, ftsThreadPoolPtr );
} }

View file

@ -192,7 +192,8 @@ public:
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ); bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr );
virtual void getArticleText( uint32_t articleAddress, QString & headword, QString & text ); virtual void getArticleText( uint32_t articleAddress, QString & headword, QString & text );
virtual void makeFTSIndex(QAtomicInt & isCancelled, bool firstIteration ); virtual void makeFTSIndex(QAtomicInt & isCancelled, bool firstIteration );
@ -1270,9 +1271,10 @@ sptr< Dictionary::DataRequest > StardictDictionary::getSearchResults( QString co
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ) bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr )
{ {
return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics, ftsThreadPoolPtr );
} }
/// StardictDictionary::findHeadwordsForSynonym() /// StardictDictionary::findHeadwordsForSynonym()

View file

@ -181,7 +181,8 @@ public:
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ); bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr );
virtual void getArticleText( uint32_t articleAddress, QString & headword, QString & text ); virtual void getArticleText( uint32_t articleAddress, QString & headword, QString & text );
virtual void makeFTSIndex(QAtomicInt & isCancelled, bool firstIteration ); virtual void makeFTSIndex(QAtomicInt & isCancelled, bool firstIteration );
@ -426,9 +427,10 @@ sptr< Dictionary::DataRequest > XdxfDictionary::getSearchResults( QString const
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ) bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr )
{ {
return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics, ftsThreadPoolPtr );
} }
/// XdxfDictionary::getArticle() /// XdxfDictionary::getArticle()

8
zim.cc
View file

@ -708,7 +708,8 @@ class ZimDictionary: public BtreeIndexing::BtreeDictionary
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ); bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr );
virtual void getArticleText( uint32_t articleAddress, QString & headword, QString & text ); virtual void getArticleText( uint32_t articleAddress, QString & headword, QString & text );
quint32 getArticleText( uint32_t articleAddress, QString & headword, QString & text, quint32 getArticleText( uint32_t articleAddress, QString & headword, QString & text,
@ -1288,9 +1289,10 @@ sptr< Dictionary::DataRequest > ZimDictionary::getSearchResults( QString const &
int distanceBetweenWords, int distanceBetweenWords,
int maxResults, int maxResults,
bool ignoreWordsOrder, bool ignoreWordsOrder,
bool ignoreDiacritics ) bool ignoreDiacritics,
QThreadPool * ftsThreadPoolPtr )
{ {
return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics ); return new FtsHelpers::FTSResultsRequest( *this, searchString,searchMode, matchCase, distanceBetweenWords, maxResults, ignoreWordsOrder, ignoreDiacritics, ftsThreadPoolPtr );
} }
/// ZimDictionary::getArticle() /// ZimDictionary::getArticle()