~ubuntu-branches/ubuntu/lucid/kdebase-runtime/lucid

« back to all changes in this revision

Viewing changes to nepomuk/strigibackend/nepomukindexreader.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-03-29 18:14:36 UTC
  • mto: This revision was merged to the branch mainline in revision 109.
  • Revision ID: james.westby@ubuntu.com-20100329181436-fb4m27cpigph5apt
Tags: upstream-4.4.2
ImportĀ upstreamĀ versionĀ 4.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
  Copyright (C) 2007-2009 Sebastian Trueg <trueg@kde.org>
 
2
  Copyright (C) 2007-2010 Sebastian Trueg <trueg@kde.org>
3
3
 
4
4
  This library is free software; you can redistribute it and/or
5
5
  modify it under the terms of the GNU General Public License as
18
18
*/
19
19
 
20
20
#include "nepomukindexreader.h"
21
 
#include <strigi/query.h>
22
 
#include <strigi/queryparser.h>
23
 
#include <strigi/fieldtypes.h>
24
 
#include "util.h"
25
 
#include "nie.h"
26
 
 
27
 
#include <Soprano/Soprano>
28
 
#include <Soprano/Vocabulary/XMLSchema>
29
 
 
30
 
#include <map>
31
 
#include <utility>
32
 
#include <sstream>
33
 
 
34
 
#include <QtCore/QThread>
35
 
#include <QtCore/QDateTime>
36
 
#include <QtCore/QString>
37
 
#include <QtCore/QLatin1String>
38
 
#include <QtCore/QFile>
39
 
 
40
 
#include <KDebug>
41
21
 
42
22
using namespace Soprano;
43
23
using namespace std;
60
40
 
61
41
Strigi::NepomukIndexReader::~NepomukIndexReader()
62
42
{
63
 
    kDebug();
64
43
    delete d;
65
44
}
66
45
 
67
46
 
68
 
// an empty parent url is perfectly valid as strigi stores a parent url for everything
69
 
void Strigi::NepomukIndexReader::getChildren( const std::string& parent,
70
 
                                              std::map<std::string, time_t>& children )
 
47
// not implemented
 
48
void Strigi::NepomukIndexReader::getChildren( const std::string&,
 
49
                                              std::map<std::string, time_t>& )
71
50
{
72
 
    //
73
 
    // We are compatible with old Xesam data where the url was encoded as a string instead of a url,
74
 
    // thus the weird query
75
 
    //
76
 
    QString query = QString( "select distinct ?path ?mtime where { "
77
 
                             "{ ?r <http://strigi.sf.net/ontologies/0.9#parentUrl> %1 . } "
78
 
                             "UNION "
79
 
                             "{ ?r <http://strigi.sf.net/ontologies/0.9#parentUrl> %2 . } "
80
 
                             "UNION "
81
 
                             "{ ?r %3 ?parent . ?parent %7 %2 . } . "
82
 
                             "{ ?r %4 ?mtime . } UNION { ?r %5 ?mtime . } "
83
 
                             "{ ?r %6 ?path . } UNION { ?r %7 ?path . } "
84
 
                             "}")
85
 
                    .arg( Node::literalToN3( QString::fromUtf8( parent.c_str() ) ),
86
 
                          Node::resourceToN3( QUrl::fromLocalFile( QFile::decodeName( parent.c_str() ) ) ),
87
 
                          Node::resourceToN3( Nepomuk::Vocabulary::NIE::isPartOf() ),
88
 
                          Node::resourceToN3( Vocabulary::Xesam::sourceModified() ),
89
 
                          Node::resourceToN3( Nepomuk::Vocabulary::NIE::lastModified() ),
90
 
                          Node::resourceToN3( Vocabulary::Xesam::url() ),
91
 
                          Node::resourceToN3( Nepomuk::Vocabulary::NIE::url() ) );
92
 
 
93
 
//    kDebug() << "running getChildren query:" << query;
94
 
 
95
 
    QueryResultIterator result = d->repository->executeQuery( query, Soprano::Query::QueryLanguageSparql );
96
 
 
97
 
    while ( result.next() ) {
98
 
        Node pathNode = result.binding( "path" );
99
 
        Node mTimeNode = result.binding( "mtime" );
100
 
 
101
 
        // be backwards compatible in case there are paths left encoded as literals
102
 
        std::string path;
103
 
        if ( pathNode.isLiteral() )
104
 
            path = pathNode.toString().toUtf8().data();
105
 
        else
106
 
            path = QFile::encodeName( pathNode.uri().toLocalFile() ).data();
107
 
 
108
 
        // Sadly in Xesam sourceModified is not typed as DateTime but defaults to an int :( We try to be compatible
109
 
        if ( mTimeNode.literal().isDateTime() ) {
110
 
            children[path] = mTimeNode.literal().toDateTime().toTime_t();
111
 
        }
112
 
        else {
113
 
            children[path] = mTimeNode.literal().toUnsignedInt();
114
 
        }
115
 
    }
 
51
    // unused in Nepomuk
116
52
}
117
53
 
118
54
 
 
55
// not implemented
119
56
int64_t Strigi::NepomukIndexReader::indexSize()
120
57
{
121
 
    return d->repository->statementCount();
 
58
    return -1;
122
59
}
123
60
 
124
61
 
125
 
time_t Strigi::NepomukIndexReader::mTime( const std::string& path )
 
62
// not implemented
 
63
time_t Strigi::NepomukIndexReader::mTime( const std::string& )
126
64
{
127
 
    //
128
 
    // We are compatible with old Xesam data, thus the weird query
129
 
    //
130
 
    QString query = QString( "select ?mtime where { "
131
 
                             "{ ?r %1 %2 . } UNION { ?r %3 %4 . } "
132
 
                             "{ ?r %5 ?mtime . } UNION { ?r %6 ?mtime . } }" )
133
 
                    .arg( Node::resourceToN3( Vocabulary::Xesam::url() ),
134
 
                          Node::literalToN3( QString::fromUtf8( path.c_str() ) ),
135
 
                          Node::resourceToN3( Nepomuk::Vocabulary::NIE::url() ),
136
 
                          Node::resourceToN3( QUrl::fromLocalFile( QFile::decodeName( path.c_str() ) ) ),
137
 
                          Node::resourceToN3( Vocabulary::Xesam::sourceModified() ),
138
 
                          Node::resourceToN3( Nepomuk::Vocabulary::NIE::lastModified() ) );
139
 
 
140
 
//    kDebug() << "mTime( " << path.c_str() << ") query:" << query;
141
 
 
142
 
    QueryResultIterator it = d->repository->executeQuery( query, Soprano::Query::QueryLanguageSparql );
143
 
 
144
 
    time_t mtime = 0;
145
 
    if ( it.next() ) {
146
 
        Soprano::LiteralValue val = it.binding( "mtime" ).literal();
147
 
 
148
 
        // Sadly in Xesam sourceModified is not typed as DateTime but defaults to an int :( We try to be compatible
149
 
        if ( val.isDateTime() ) {
150
 
            mtime = val.toDateTime().toTime_t();
151
 
        }
152
 
        else {
153
 
            mtime = val.toUnsignedInt();
154
 
        }
155
 
    }
156
 
    return mtime;
 
65
    return -1;
157
66
}
158
67
 
159
68