mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-30 17:24:08 +00:00
opt: indexing dictionary in status bar does not disappear (#1234)
* opt: indexing dictionary name and progress * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
3a3541cd8a
commit
e8a2eadade
|
@ -403,6 +403,9 @@ public:
|
||||||
|
|
||||||
int getIndexingFtsProgress()
|
int getIndexingFtsProgress()
|
||||||
{
|
{
|
||||||
|
if ( haveFTSIndex() ) {
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
auto total = getArticleCount();
|
auto total = getArticleCount();
|
||||||
if ( total == 0 )
|
if ( total == 0 )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1067,14 +1067,15 @@ QString DslDictionary::getMainFilename()
|
||||||
void DslDictionary::makeFTSIndex( QAtomicInt & isCancelled, bool firstIteration )
|
void DslDictionary::makeFTSIndex( QAtomicInt & isCancelled, bool firstIteration )
|
||||||
{
|
{
|
||||||
if ( !( Dictionary::needToRebuildIndex( getDictionaryFilenames(), ftsIdxName )
|
if ( !( Dictionary::needToRebuildIndex( getDictionaryFilenames(), ftsIdxName )
|
||||||
|| FtsHelpers::ftsIndexIsOldOrBad( this ) ) )
|
|| FtsHelpers::ftsIndexIsOldOrBad( this ) ) ) {
|
||||||
FTS_index_completed.ref();
|
FTS_index_completed.ref();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if ( haveFTSIndex() )
|
if ( haveFTSIndex() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( ensureInitDone().size() )
|
if ( !ensureInitDone().empty() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( firstIteration && getArticleCount() > FTS::MaxDictionarySizeForFastSearch )
|
if ( firstIteration && getArticleCount() > FTS::MaxDictionarySizeForFastSearch )
|
||||||
|
|
|
@ -26,13 +26,15 @@ const static std::string finish_mark = std::string( "dehsinif" );
|
||||||
bool ftsIndexIsOldOrBad( BtreeIndexing::BtreeDictionary * dict )
|
bool ftsIndexIsOldOrBad( BtreeIndexing::BtreeDictionary * dict )
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Xapian::WritableDatabase db( dict->ftsIndexName() );
|
Xapian::WritableDatabase const db( dict->ftsIndexName() );
|
||||||
auto docid = db.get_lastdocid();
|
auto docid = db.get_lastdocid();
|
||||||
auto document = db.get_document( docid );
|
auto document = db.get_document( docid );
|
||||||
|
|
||||||
qDebug() << document.get_data().c_str();
|
string const lastDoc = document.get_data();
|
||||||
|
bool const notFinished = lastDoc != finish_mark;
|
||||||
|
qDebug() << dict->ftsIndexName().c_str() << document.get_data().c_str() << notFinished;
|
||||||
//use a special document to mark the end of the index.
|
//use a special document to mark the end of the index.
|
||||||
return document.get_data() != finish_mark;
|
return notFinished;
|
||||||
}
|
}
|
||||||
catch ( Xapian::Error & e ) {
|
catch ( Xapian::Error & e ) {
|
||||||
qWarning() << e.get_description().c_str();
|
qWarning() << e.get_description().c_str();
|
||||||
|
@ -47,7 +49,7 @@ bool ftsIndexIsOldOrBad( BtreeIndexing::BtreeDictionary * dict )
|
||||||
|
|
||||||
void makeFTSIndex( BtreeIndexing::BtreeDictionary * dict, QAtomicInt & isCancelled )
|
void makeFTSIndex( BtreeIndexing::BtreeDictionary * dict, QAtomicInt & isCancelled )
|
||||||
{
|
{
|
||||||
QMutexLocker _( &dict->getFtsMutex() );
|
QMutexLocker const _( &dict->getFtsMutex() );
|
||||||
|
|
||||||
//check the index again.
|
//check the index again.
|
||||||
if ( dict->haveFTSIndex() )
|
if ( dict->haveFTSIndex() )
|
||||||
|
|
|
@ -40,7 +40,9 @@ void Indexing::run()
|
||||||
sem.acquire();
|
sem.acquire();
|
||||||
QFuture< void > const f = QtConcurrent::run( [ this, &sem, &dictionary ]() {
|
QFuture< void > const f = QtConcurrent::run( [ this, &sem, &dictionary ]() {
|
||||||
QSemaphoreReleaser const _( sem );
|
QSemaphoreReleaser const _( sem );
|
||||||
emit sendNowIndexingName( QString::fromUtf8( dictionary->getName().c_str() ) );
|
const QString & dictionaryName = QString::fromUtf8( dictionary->getName().c_str() );
|
||||||
|
qDebug() << "[FULLTEXT] make fts for the dictionary:" << dictionaryName;
|
||||||
|
emit sendNowIndexingName( dictionaryName );
|
||||||
dictionary->makeFTSIndex( isCancelled, false );
|
dictionary->makeFTSIndex( isCancelled, false );
|
||||||
} );
|
} );
|
||||||
synchronizer.addFuture( f );
|
synchronizer.addFuture( f );
|
||||||
|
@ -60,18 +62,26 @@ void Indexing::run()
|
||||||
|
|
||||||
void Indexing::timeout()
|
void Indexing::timeout()
|
||||||
{
|
{
|
||||||
//display all the dictionary name in the following loop ,may result only one dictionary name been seen.
|
QString indexingDicts;
|
||||||
//as the interval is so small.
|
|
||||||
for ( const auto & dictionary : dictionaries ) {
|
for ( const auto & dictionary : dictionaries ) {
|
||||||
if ( Utils::AtomicInt::loadAcquire( isCancelled ) )
|
if ( Utils::AtomicInt::loadAcquire( isCancelled ) )
|
||||||
break;
|
break;
|
||||||
|
//Finished, clear the msg.
|
||||||
|
if ( dictionary->haveFTSIndex() ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
auto newProgress = dictionary->getIndexingFtsProgress();
|
auto newProgress = dictionary->getIndexingFtsProgress();
|
||||||
if ( newProgress > 0 && newProgress < 100 ) {
|
if ( newProgress > 0 && newProgress < 100 ) {
|
||||||
emit sendNowIndexingName(
|
if ( !indexingDicts.isEmpty() )
|
||||||
|
indexingDicts.append( "," );
|
||||||
|
indexingDicts.append(
|
||||||
QString( "%1......%%2" ).arg( QString::fromStdString( dictionary->getName() ) ).arg( newProgress ) );
|
QString( "%1......%%2" ).arg( QString::fromStdString( dictionary->getName() ) ).arg( newProgress ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !indexingDicts.isEmpty() ) {
|
||||||
|
emit sendNowIndexingName( indexingDicts );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FtsIndexing::FtsIndexing( std::vector< sptr< Dictionary::Class > > const & dicts ):
|
FtsIndexing::FtsIndexing( std::vector< sptr< Dictionary::Class > > const & dicts ):
|
||||||
|
|
Loading…
Reference in a new issue