~ubuntu-branches/debian/sid/baloo-kf5/sid

« back to all changes in this revision

Viewing changes to src/file/tests/fileindexingqueuetest.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-07-10 21:13:07 UTC
  • Revision ID: package-import@ubuntu.com-20140710211307-iku0qs6vlplgn06m
Tags: upstream-5.0.0b
ImportĀ upstreamĀ versionĀ 5.0.0b

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of the KDE Baloo Project
 
3
 * Copyright (C) 2014  Vishesh Handa <me@vhanda.in>
 
4
 *
 
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.
 
12
 *
 
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.
 
17
 *
 
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/>.
 
20
 *
 
21
 */
 
22
 
 
23
#include <QDebug>
 
24
#include <QTemporaryDir>
 
25
#include <QTime>
 
26
#include <QCoreApplication>
 
27
 
 
28
#include "fileextractor.h"
 
29
 
 
30
#include "../basicindexingqueue.h"
 
31
#include "../commitqueue.h"
 
32
#include "../database.h"
 
33
#include "../fileindexerconfig.h"
 
34
#include "../lib/filemapping.h"
 
35
 
 
36
int main(int argc, char** argv)
 
37
{
 
38
    QTemporaryDir tempDir;
 
39
 
 
40
    Database db;
 
41
    db.setPath(tempDir.path());
 
42
    db.init();
 
43
 
 
44
    Baloo::FileIndexerConfig config;
 
45
    QCoreApplication app(argc, argv);
 
46
 
 
47
    Baloo::BasicIndexingQueue basicIQ(&db, &config);
 
48
    QObject::connect(&basicIQ, SIGNAL(finishedIndexing()), &app, SLOT(quit()));
 
49
 
 
50
    Baloo::CommitQueue commitQueue(&db);
 
51
    QObject::connect(&basicIQ, SIGNAL(newDocument(uint,Xapian::Document)),
 
52
                     &commitQueue, SLOT(add(uint,Xapian::Document)));
 
53
 
 
54
    basicIQ.enqueue(Baloo::FileMapping(QDir::homePath()));
 
55
    app.exec();
 
56
 
 
57
    commitQueue.commit();
 
58
 
 
59
    // Now the file indexing
 
60
    Xapian::Database* xdb = db.xapianDatabase()->db();
 
61
    Xapian::Enquire enquire(*xdb);
 
62
    enquire.set_query(Xapian::Query("Z1"));
 
63
 
 
64
    Xapian::MSet mset = enquire.get_mset(0, 50000);
 
65
    Xapian::MSetIterator it = mset.begin();
 
66
 
 
67
    QHash<QString, int> m_timePerType;
 
68
    QHash<QString, int> m_numPerType;
 
69
 
 
70
    uint totalTime = 0;
 
71
    for (; it != mset.end(); ++it) {
 
72
        Baloo::FileMapping fileMap(*it);
 
73
        if (!fileMap.fetch(db.sqlDatabase()))
 
74
            continue;
 
75
 
 
76
        auto job = new Baloo::FileExtractor(fileMap.id(), fileMap.url());
 
77
        job->setCustomPath(db.path());
 
78
        job->exec();
 
79
 
 
80
        qDebug() << fileMap.id() << fileMap.url() << job->mimeType() << job->elapsed();
 
81
        totalTime += job->elapsed();
 
82
 
 
83
        m_timePerType[job->mimeType()] += job->elapsed();
 
84
        m_numPerType[job->mimeType()] += 1;
 
85
    }
 
86
 
 
87
    qDebug() << "\n\n";
 
88
    Q_FOREACH (const QString& type, m_timePerType.uniqueKeys()) {
 
89
        double averageTime = m_timePerType.value(type) / m_numPerType.value(type);
 
90
        qDebug() << type << averageTime;
 
91
    }
 
92
    qDebug() << "Total Elapsed:" << totalTime;
 
93
    return 0;
 
94
}