2023-05-22 22:13:42 -04:00
|
|
|
#ifndef DATABASE_H
|
|
|
|
#define DATABASE_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QtSql>
|
|
|
|
#include <QQueue>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QThread>
|
|
|
|
#include <QFileSystemWatcher>
|
|
|
|
|
|
|
|
struct DocumentInfo
|
|
|
|
{
|
|
|
|
int folder;
|
|
|
|
QFileInfo doc;
|
|
|
|
};
|
|
|
|
|
2023-05-24 14:49:43 -04:00
|
|
|
struct ResultInfo {
|
|
|
|
QString file; // [Required] The name of the file, but not the full path
|
|
|
|
QString title; // [Optional] The title of the document
|
|
|
|
QString author; // [Optional] The author of the document
|
|
|
|
QString date; // [Required] The creation or the last modification date whichever is latest
|
|
|
|
QString text; // [Required] The text actually used in the augmented context
|
|
|
|
int page = -1; // [Optional] The page where the text was found
|
|
|
|
int from = -1; // [Optional] The line number where the text begins
|
|
|
|
int to = -1; // [Optional] The line number where the text ends
|
|
|
|
};
|
|
|
|
|
2023-05-22 22:13:42 -04:00
|
|
|
struct CollectionItem {
|
|
|
|
QString collection;
|
|
|
|
QString folder_path;
|
|
|
|
int folder_id = -1;
|
2023-06-03 10:08:59 -04:00
|
|
|
bool installed = false;
|
2023-05-22 22:13:42 -04:00
|
|
|
};
|
|
|
|
Q_DECLARE_METATYPE(CollectionItem)
|
|
|
|
|
|
|
|
class Database : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2023-05-23 20:26:31 -04:00
|
|
|
Database(int chunkSize);
|
2023-05-22 22:13:42 -04:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void scanQueue();
|
|
|
|
void scanDocuments(int folder_id, const QString &folder_path);
|
|
|
|
void addFolder(const QString &collection, const QString &path);
|
|
|
|
void removeFolder(const QString &collection, const QString &path);
|
2023-06-01 14:13:12 -04:00
|
|
|
void retrieveFromDB(const QList<QString> &collections, const QString &text, int retrievalSize, QList<ResultInfo> *results);
|
2023-05-22 22:13:42 -04:00
|
|
|
void cleanDB();
|
2023-05-23 20:26:31 -04:00
|
|
|
void changeChunkSize(int chunkSize);
|
2023-05-22 22:13:42 -04:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void docsToScanChanged();
|
|
|
|
void collectionListUpdated(const QList<CollectionItem> &collectionList);
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void start();
|
|
|
|
void directoryChanged(const QString &path);
|
|
|
|
bool addFolderToWatch(const QString &path);
|
|
|
|
bool removeFolderFromWatch(const QString &path);
|
|
|
|
void addCurrentFolders();
|
|
|
|
void updateCollectionList();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void removeFolderInternal(const QString &collection, int folder_id, const QString &path);
|
2023-05-24 14:49:43 -04:00
|
|
|
void chunkStream(QTextStream &stream, int document_id, const QString &file,
|
|
|
|
const QString &title, const QString &author, const QString &subject, const QString &keywords, int page);
|
2023-05-22 22:13:42 -04:00
|
|
|
void handleDocumentErrorAndScheduleNext(const QString &errorMessage,
|
|
|
|
int document_id, const QString &document_path, const QSqlError &error);
|
|
|
|
|
|
|
|
private:
|
2023-05-23 20:26:31 -04:00
|
|
|
int m_chunkSize;
|
2023-05-22 22:13:42 -04:00
|
|
|
QQueue<DocumentInfo> m_docsToScan;
|
2023-05-24 14:49:43 -04:00
|
|
|
QList<ResultInfo> m_retrieve;
|
2023-05-22 22:13:42 -04:00
|
|
|
QThread m_dbThread;
|
|
|
|
QFileSystemWatcher *m_watcher;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DATABASE_H
|