File indexing completed on 2024-04-28 03:51:54

0001 /*
0002     This file is part of the KDE Baloo Project
0003     SPDX-FileCopyrightText: 2014-2015 Vishesh Handa <vhanda@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #include <QDebug>
0009 #include <QTemporaryDir>
0010 #include <QUuid>
0011 #include <QFileInfo>
0012 #include <QDir>
0013 #include <QCoreApplication>
0014 #include <QCommandLineParser>
0015 #include <QCommandLineOption>
0016 
0017 #include "database.h"
0018 #include "document.h"
0019 #include "transaction.h"
0020 #include "tests/file/util.h"
0021 
0022 int main(int argc, char** argv)
0023 {
0024     QCoreApplication app(argc, argv);
0025 
0026     QCommandLineParser parser;
0027     parser.addPositionalArgument(QStringLiteral("num"), QStringLiteral("The number of terms. Each term is of length 10"));
0028     parser.addOption(QCommandLineOption(QStringList () << QStringLiteral("p") << QStringLiteral("position"), QStringLiteral("Add positional information")));
0029     parser.addHelpOption();
0030     parser.process(app);
0031 
0032     QStringList args = parser.positionalArguments();
0033     if (args.size() != 1) {
0034         parser.showHelp(1);
0035     }
0036 
0037     QTemporaryDir tempDir;
0038     tempDir.setAutoRemove(false);
0039 
0040     Baloo::Database db(tempDir.path());
0041     db.open(Baloo::Database::CreateDatabase);
0042 
0043     qDebug() << tempDir.path();
0044     printIOUsage();
0045     qDebug() << "Creating the document";
0046 
0047     Baloo::Document doc;
0048     int size = args.first().toInt();
0049 
0050     for (int i = 0; i < size; i++) {
0051         QByteArray term = QUuid::createUuid().toByteArray().mid(1, 10);
0052 
0053         if (parser.isSet(QStringLiteral("p"))) {
0054             doc.addPositionTerm(term, i);
0055         }
0056         else {
0057             doc.addTerm(term);
0058         }
0059     }
0060     doc.setParentId(1);
0061     doc.setId(2);
0062 
0063     Baloo::Transaction tr(db, Baloo::Transaction::ReadWrite);
0064     tr.addDocument(doc);
0065     tr.commit();
0066 
0067     printIOUsage();
0068 
0069     int dbSize = 0;
0070     QDir dbDir(tempDir.path());
0071     for (const QFileInfo& file : dbDir.entryInfoList(QDir::Files)) {
0072         qDebug() << file.fileName() << file.size() / 1024 << "kb";
0073         dbSize += file.size();
0074 
0075     }
0076     qDebug() << "Database Size:" << dbSize / 1024 << "kb";
0077 }