#pragma once #include #include #include #include #include #include #include "search_core.h" #include "search_cache.h" class SearchEngine final : public QObject { Q_OBJECT public: explicit SearchEngine(QObject *parent = nullptr, QString cachePath = {}) : QObject(parent), cache_(std::move(cachePath)) {} public slots: void stop() { cancelled_.store(true, std::memory_order_relaxed); } void clearCache() { cache_.clear(); emit cacheCleared(); } void search(const SearchOptions &o); signals: void progress(const QString &path, quint64 scanned); void phaseProgress(const QString &phase, quint64 completed, quint64 total); void cacheCleared(); void finished(const QVector &results, const QString &message); private: QByteArray cachedSampleSha256(const FileRecord &record); QByteArray cachedSha256(const FileRecord &record); bool cachedFileContains(const FileRecord &record, const SearchOptions &o); SearchCache cache_; std::atomic cacheHits_ = 0; std::atomic cacheMisses_ = 0; std::atomic_bool cancelled_ = false; bool cancelledByLimit_ = false; };