diff --git a/src/dict/dictionary.hh b/src/dict/dictionary.hh index a1ebd7d6..010429ff 100644 --- a/src/dict/dictionary.hh +++ b/src/dict/dictionary.hh @@ -403,6 +403,9 @@ public: int getIndexingFtsProgress() { + if ( haveFTSIndex() ) { + return 100; + } auto total = getArticleCount(); if ( total == 0 ) return 0; diff --git a/src/dict/dsl.cc b/src/dict/dsl.cc index 8a7342ec..01cc75aa 100644 --- a/src/dict/dsl.cc +++ b/src/dict/dsl.cc @@ -1067,14 +1067,15 @@ QString DslDictionary::getMainFilename() void DslDictionary::makeFTSIndex( QAtomicInt & isCancelled, bool firstIteration ) { if ( !( Dictionary::needToRebuildIndex( getDictionaryFilenames(), ftsIdxName ) - || FtsHelpers::ftsIndexIsOldOrBad( this ) ) ) + || FtsHelpers::ftsIndexIsOldOrBad( this ) ) ) { FTS_index_completed.ref(); + } if ( haveFTSIndex() ) return; - if ( ensureInitDone().size() ) + if ( !ensureInitDone().empty() ) return; if ( firstIteration && getArticleCount() > FTS::MaxDictionarySizeForFastSearch ) diff --git a/src/ftshelpers.cc b/src/ftshelpers.cc index a7dee3d4..4d6affd1 100644 --- a/src/ftshelpers.cc +++ b/src/ftshelpers.cc @@ -26,13 +26,15 @@ const static std::string finish_mark = std::string( "dehsinif" ); bool ftsIndexIsOldOrBad( BtreeIndexing::BtreeDictionary * dict ) { try { - Xapian::WritableDatabase db( dict->ftsIndexName() ); + Xapian::WritableDatabase const db( dict->ftsIndexName() ); auto docid = db.get_lastdocid(); 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. - return document.get_data() != finish_mark; + return notFinished; } catch ( Xapian::Error & e ) { qWarning() << e.get_description().c_str(); @@ -47,7 +49,7 @@ bool ftsIndexIsOldOrBad( BtreeIndexing::BtreeDictionary * dict ) void makeFTSIndex( BtreeIndexing::BtreeDictionary * dict, QAtomicInt & isCancelled ) { - QMutexLocker _( &dict->getFtsMutex() ); + QMutexLocker const _( &dict->getFtsMutex() ); //check the index again. if ( dict->haveFTSIndex() ) diff --git a/src/fulltextsearch.cc b/src/fulltextsearch.cc index 06d1f48a..a2ae7051 100644 --- a/src/fulltextsearch.cc +++ b/src/fulltextsearch.cc @@ -40,7 +40,9 @@ void Indexing::run() sem.acquire(); QFuture< void > const f = QtConcurrent::run( [ this, &sem, &dictionary ]() { 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 ); } ); synchronizer.addFuture( f ); @@ -60,18 +62,26 @@ void Indexing::run() void Indexing::timeout() { - //display all the dictionary name in the following loop ,may result only one dictionary name been seen. - //as the interval is so small. + QString indexingDicts; for ( const auto & dictionary : dictionaries ) { if ( Utils::AtomicInt::loadAcquire( isCancelled ) ) break; - + //Finished, clear the msg. + if ( dictionary->haveFTSIndex() ) { + continue; + } auto newProgress = dictionary->getIndexingFtsProgress(); if ( newProgress > 0 && newProgress < 100 ) { - emit sendNowIndexingName( + if ( !indexingDicts.isEmpty() ) + indexingDicts.append( "," ); + indexingDicts.append( 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 ):