opt: full text index compact

This commit is contained in:
YiFang Xiao 2023-08-05 10:57:20 +08:00
parent 623cc83c39
commit a8c3207a76
3 changed files with 26 additions and 1 deletions

View file

@ -68,4 +68,23 @@ std::string basename( std::string const & str )
return std::string( str, x + 1 ); return std::string( str, x + 1 );
} }
void removeDirectory( QString const & directory )
{
QDir dir( directory );
Q_FOREACH ( QFileInfo info,
dir.entryInfoList( QDir::NoDotAndDotDot | QDir::AllDirs | QDir::Files, QDir::DirsFirst ) ) {
if ( info.isDir() )
removeDirectory( info.absoluteFilePath() );
else
QFile::remove( info.absoluteFilePath() );
}
dir.rmdir( directory );
}
void removeDirectory( string const & directory )
{
removeDirectory( QString::fromStdString( directory ) );
}
} // namespace Utils::Fs } // namespace Utils::Fs

View file

@ -332,7 +332,9 @@ char separator();
/// Returns the name part of the given filename. /// Returns the name part of the given filename.
string basename( string const & ); string basename( string const & );
void removeDirectory( QString const & directory );
void removeDirectory( string const & directory );
} // namespace Fs } // namespace Fs
} // namespace Utils } // namespace Utils

View file

@ -105,7 +105,7 @@ void makeFTSIndex( BtreeIndexing::BtreeDictionary * dict, QAtomicInt & isCancell
throw exUserAbort(); throw exUserAbort();
// Open the database for update, creating a new database if necessary. // Open the database for update, creating a new database if necessary.
Xapian::WritableDatabase db( dict->ftsIndexName(), Xapian::DB_CREATE_OR_OPEN ); Xapian::WritableDatabase db( dict->ftsIndexName() + "_temp", Xapian::DB_CREATE_OR_OPEN );
Xapian::TermGenerator indexer; Xapian::TermGenerator indexer;
// Xapian::Stem stemmer("english"); // Xapian::Stem stemmer("english");
@ -206,6 +206,10 @@ void makeFTSIndex( BtreeIndexing::BtreeDictionary * dict, QAtomicInt & isCancell
offsets.clear(); offsets.clear();
db.commit(); db.commit();
db.compact( dict->ftsIndexName() );
Utils::Fs::removeDirectory( dict->ftsIndexName() + "_temp" );
} }
catch ( Xapian::Error & e ) { catch ( Xapian::Error & e ) {
qWarning() << "create xapian index:" << QString::fromStdString( e.get_description() ); qWarning() << "create xapian index:" << QString::fromStdString( e.get_description() );