61
41
Strigi::NepomukIndexReader::~NepomukIndexReader()
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 )
48
void Strigi::NepomukIndexReader::getChildren( const std::string&,
49
std::map<std::string, time_t>& )
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
76
QString query = QString( "select distinct ?path ?mtime where { "
77
"{ ?r <http://strigi.sf.net/ontologies/0.9#parentUrl> %1 . } "
79
"{ ?r <http://strigi.sf.net/ontologies/0.9#parentUrl> %2 . } "
81
"{ ?r %3 ?parent . ?parent %7 %2 . } . "
82
"{ ?r %4 ?mtime . } UNION { ?r %5 ?mtime . } "
83
"{ ?r %6 ?path . } UNION { ?r %7 ?path . } "
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() ) );
93
// kDebug() << "running getChildren query:" << query;
95
QueryResultIterator result = d->repository->executeQuery( query, Soprano::Query::QueryLanguageSparql );
97
while ( result.next() ) {
98
Node pathNode = result.binding( "path" );
99
Node mTimeNode = result.binding( "mtime" );
101
// be backwards compatible in case there are paths left encoded as literals
103
if ( pathNode.isLiteral() )
104
path = pathNode.toString().toUtf8().data();
106
path = QFile::encodeName( pathNode.uri().toLocalFile() ).data();
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();
113
children[path] = mTimeNode.literal().toUnsignedInt();
119
56
int64_t Strigi::NepomukIndexReader::indexSize()
121
return d->repository->statementCount();
125
time_t Strigi::NepomukIndexReader::mTime( const std::string& path )
63
time_t Strigi::NepomukIndexReader::mTime( const std::string& )
128
// We are compatible with old Xesam data, thus the weird query
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() ) );
140
// kDebug() << "mTime( " << path.c_str() << ") query:" << query;
142
QueryResultIterator it = d->repository->executeQuery( query, Soprano::Query::QueryLanguageSparql );
146
Soprano::LiteralValue val = it.binding( "mtime" ).literal();
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();
153
mtime = val.toUnsignedInt();