2
* This file is part of the KDE Baloo Project
3
* Copyright (C) 2014 Vishesh Handa <me@vhanda.in>
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) version 3, or any
9
* later version accepted by the membership of KDE e.V. (or its
10
* successor approved by the membership of KDE e.V.), which shall
11
* act as a proxy defined in Section 6 of version 3 of the license.
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
24
#include <QTemporaryDir>
26
#include <QCoreApplication>
28
#include "fileextractor.h"
30
#include "../basicindexingqueue.h"
31
#include "../commitqueue.h"
32
#include "../database.h"
33
#include "../fileindexerconfig.h"
34
#include "../lib/filemapping.h"
36
int main(int argc, char** argv)
38
QTemporaryDir tempDir;
41
db.setPath(tempDir.path());
44
Baloo::FileIndexerConfig config;
45
QCoreApplication app(argc, argv);
47
Baloo::BasicIndexingQueue basicIQ(&db, &config);
48
QObject::connect(&basicIQ, SIGNAL(finishedIndexing()), &app, SLOT(quit()));
50
Baloo::CommitQueue commitQueue(&db);
51
QObject::connect(&basicIQ, SIGNAL(newDocument(uint,Xapian::Document)),
52
&commitQueue, SLOT(add(uint,Xapian::Document)));
54
basicIQ.enqueue(Baloo::FileMapping(QDir::homePath()));
59
// Now the file indexing
60
Xapian::Database* xdb = db.xapianDatabase()->db();
61
Xapian::Enquire enquire(*xdb);
62
enquire.set_query(Xapian::Query("Z1"));
64
Xapian::MSet mset = enquire.get_mset(0, 50000);
65
Xapian::MSetIterator it = mset.begin();
67
QHash<QString, int> m_timePerType;
68
QHash<QString, int> m_numPerType;
71
for (; it != mset.end(); ++it) {
72
Baloo::FileMapping fileMap(*it);
73
if (!fileMap.fetch(db.sqlDatabase()))
76
auto job = new Baloo::FileExtractor(fileMap.id(), fileMap.url());
77
job->setCustomPath(db.path());
80
qDebug() << fileMap.id() << fileMap.url() << job->mimeType() << job->elapsed();
81
totalTime += job->elapsed();
83
m_timePerType[job->mimeType()] += job->elapsed();
84
m_numPerType[job->mimeType()] += 1;
88
Q_FOREACH (const QString& type, m_timePerType.uniqueKeys()) {
89
double averageTime = m_timePerType.value(type) / m_numPerType.value(type);
90
qDebug() << type << averageTime;
92
qDebug() << "Total Elapsed:" << totalTime;