File indexing completed on 2024-12-22 04:53:02

0001 /*
0002  * This file is part of the KDE Akonadi Search Project
0003  * SPDX-FileCopyrightText: 2014 Vishesh Handa <me@vhanda.in>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006  *
0007  */
0008 
0009 #include <QCommandLineOption>
0010 #include <QCommandLineParser>
0011 #include <QCoreApplication>
0012 #include <QDebug>
0013 #include <QUuid>
0014 
0015 #include "xapiandocument.h"
0016 
0017 int main(int argc, char **argv)
0018 {
0019     QCoreApplication app(argc, argv);
0020 
0021     QCommandLineParser parser;
0022     parser.addPositionalArgument(QStringLiteral("num"), QStringLiteral("The number of terms. Each term is of length 10"));
0023     parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("p") << QStringLiteral("position"), QStringLiteral("Add positional information")));
0024     parser.addHelpOption();
0025     parser.process(app);
0026 
0027     QStringList args = parser.positionalArguments();
0028     if (args.size() != 1) {
0029         parser.showHelp(1);
0030     }
0031 
0032     Akonadi::Search::XapianDocument doc;
0033     const int size = args.first().toInt();
0034 
0035     for (int i = 0; i < size; i++) {
0036         QByteArray term = QUuid::createUuid().toByteArray().mid(1, 10);
0037 
0038         if (parser.isSet(QStringLiteral("p"))) {
0039             const std::string stdString(term.constData(), term.length());
0040             doc.doc().add_posting(stdString, i);
0041         } else {
0042             doc.addTerm(QString::fromUtf8(term));
0043         }
0044     }
0045 
0046     qDebug() << "Added" << size << "terms";
0047     if (parser.isSet(QStringLiteral("p"))) {
0048         qDebug() << "With Positional Information";
0049     }
0050     return app.exec();
0051 }