goldendict-ng/src/ftshelpers.hh

79 lines
1.7 KiB
C++
Raw Normal View History

2014-04-16 16:18:28 +00:00
#ifndef __FTSHELPERS_HH_INCLUDED__
#define __FTSHELPERS_HH_INCLUDED__
#include <QString>
2022-02-27 05:17:37 +00:00
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
2022-02-27 14:42:40 +00:00
#include <QtCore5Compat/QRegExp>
#else
#include <QRegExp>
2022-02-27 05:17:37 +00:00
#endif
2014-04-16 16:18:28 +00:00
#include <QList>
2022-06-19 12:24:34 +00:00
#include <QtConcurrent>
2014-04-16 16:18:28 +00:00
#include "dict/dictionary.hh"
2014-04-16 16:18:28 +00:00
#include "btreeidx.hh"
#include "fulltextsearch.hh"
#include "folding.hh"
#include "wstring_qt.hh"
2014-04-16 16:18:28 +00:00
namespace FtsHelpers
{
bool ftsIndexIsOldOrBad( BtreeIndexing::BtreeDictionary * dict );
2014-04-16 16:18:28 +00:00
void makeFTSIndex( BtreeIndexing::BtreeDictionary * dict, QAtomicInt & isCancelled );
2014-04-16 16:18:28 +00:00
class FTSResultsRequest : public Dictionary::DataRequest
{
BtreeIndexing::BtreeDictionary & dict;
QString searchString;
int searchMode;
bool matchCase;
QAtomicInt isCancelled;
2022-06-04 15:22:14 +00:00
QAtomicInt results;
2022-06-19 12:24:34 +00:00
QFuture< void > f;
2022-06-04 15:22:14 +00:00
2014-04-16 16:18:28 +00:00
QList< FTS::FtsHeadword > * foundHeadwords;
public:
FTSResultsRequest( BtreeIndexing::BtreeDictionary & dict_,
QString const & searchString_,
int searchMode_,
bool matchCase_,
bool ignoreDiacritics_ ):
2014-04-16 16:18:28 +00:00
dict( dict_ ),
searchString( searchString_ ),
searchMode( searchMode_ ),
matchCase( matchCase_ )
2014-04-16 16:18:28 +00:00
{
if( ignoreDiacritics_ )
2023-04-17 12:55:39 +00:00
searchString = QString::fromStdU32String( Folding::applyDiacriticsOnly( gd::removeTrailingZero( searchString_ ) ) );
2014-04-16 16:18:28 +00:00
foundHeadwords = new QList< FTS::FtsHeadword >;
2022-06-04 15:22:14 +00:00
results = 0;
2022-06-19 12:24:34 +00:00
f = QtConcurrent::run( [ this ]() { this->run(); } );
2014-04-16 16:18:28 +00:00
}
2022-05-30 12:21:44 +00:00
void run();
2014-04-16 16:18:28 +00:00
virtual void cancel()
{
isCancelled.ref();
}
~FTSResultsRequest()
{
isCancelled.ref();
2022-06-19 12:24:34 +00:00
f.waitForFinished();
delete foundHeadwords;
2014-04-16 16:18:28 +00:00
}
};
} // namespace
#endif // __FTSHELPERS_HH_INCLUDED__