2024-11-07 03:53:04 +00:00
|
|
|
#pragma once
|
2014-04-16 16:18:28 +00:00
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
#include <QList>
|
2024-11-21 13:06:17 +00:00
|
|
|
#include <QtConcurrentRun>
|
2023-04-17 20:55:34 +00:00
|
|
|
#include "dict/dictionary.hh"
|
2014-04-16 16:18:28 +00:00
|
|
|
#include "btreeidx.hh"
|
|
|
|
#include "fulltextsearch.hh"
|
2018-04-10 14:49:52 +00:00
|
|
|
#include "folding.hh"
|
2014-04-16 16:18:28 +00:00
|
|
|
|
|
|
|
namespace FtsHelpers {
|
|
|
|
|
2023-06-03 00:29:19 +00:00
|
|
|
bool ftsIndexIsOldOrBad( BtreeIndexing::BtreeDictionary * dict );
|
2014-04-16 16:18:28 +00:00
|
|
|
|
|
|
|
void makeFTSIndex( BtreeIndexing::BtreeDictionary * dict, QAtomicInt & isCancelled );
|
2014-05-08 12:38:00 +00:00
|
|
|
|
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:
|
|
|
|
|
2023-05-30 23:42:31 +00:00
|
|
|
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_ ),
|
2023-05-30 23:42:31 +00:00
|
|
|
matchCase( matchCase_ )
|
2014-04-16 16:18:28 +00:00
|
|
|
{
|
2018-04-10 14:49:52 +00:00
|
|
|
if ( ignoreDiacritics_ )
|
2023-04-17 12:55:39 +00:00
|
|
|
searchString =
|
|
|
|
QString::fromStdU32String( Folding::applyDiacriticsOnly( Text::removeTrailingZero( searchString_ ) ) );
|
2018-04-10 14:49:52 +00:00
|
|
|
|
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();
|
2023-05-30 23:42:31 +00:00
|
|
|
|
|
|
|
delete foundHeadwords;
|
2014-04-16 16:18:28 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace FtsHelpers
|