mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19: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()
|
||||
{
|
||||
if ( haveFTSIndex() ) {
|
||||
return 100;
|
||||
}
|
||||
auto total = getArticleCount();
|
||||
if ( total == 0 )
|
||||
return 0;
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -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() )
|
||||
|
|
|
@ -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 ):
|
||||
|
|
Loading…
Reference in a new issue