[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/runtime/nepomuk/strigibackend
From: Sebastian Trueg <sebastian () trueg ! de>
Date: 2009-07-21 18:27:35
Message-ID: 1248200855.893807.1080.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1000646 by trueg:
Fixed queries in getChildren and mTime to support both legacy Xesam data and new NIE \
data.
M +31 -30 sopranoindexreader.cpp
M +13 -29 sopranoindexwriter.cpp
--- trunk/KDE/kdebase/runtime/nepomuk/strigibackend/sopranoindexreader.cpp \
#1000645:1000646 @@ -23,6 +23,7 @@
#include <strigi/queryparser.h>
#include <strigi/fieldtypes.h>
#include "util.h"
+#include "nie.h"
#include <Soprano/Soprano>
#include <Soprano/Index/IndexFilterModel>
@@ -193,12 +194,6 @@
}
-static QString escapeLiteralForSparqlQuery( const QString& s )
-{
- return QString( s ).replace( '\\', "\\\\" ).replace( '\"', "\\\"" );
-}
-
-
class Strigi::Soprano::IndexReader::Private
{
public:
@@ -252,7 +247,6 @@
return true;
}
-// ::Soprano::Index::IndexFilterModel* repository;
::Soprano::Model* repository;
};
@@ -281,7 +275,6 @@
::Soprano::QueryResultIterator hits = d->repository->executeQuery( TString( \
q->toString(), true ),
\
::Soprano::Query::QueryLanguageUser,
\
QLatin1String( "lucene" ) );
-// Iterator< ::Soprano::Index::QueryHit> hits = d->repository->index()->search( q \
); int s = 0;
while ( hits.next() ) {
qDebug() << "Query hit:" << hits.binding( 0 );
@@ -303,7 +296,6 @@
::Soprano::QueryResultIterator hits = d->repository->executeQuery( TString( \
bq->toString(), true ),
\
::Soprano::Query::QueryLanguageUser,
\
QLatin1String( "lucene" ) );
-// Iterator< ::Soprano::Index::QueryHit> hits = d->repository->index()->search( \
bq );
int i = -1;
while ( hits.next() ) {
@@ -315,7 +307,6 @@
break;
}
-// ::Soprano::Index::QueryHit hit = *hits;
std::vector<Strigi::Variant> resultRow;
std::vector<std::string>::const_iterator fieldIt = fields.begin();
std::vector<Strigi::Variant::Type>::const_iterator typesIt = types.begin();
@@ -354,7 +345,6 @@
::Soprano::QueryResultIterator hits = d->repository->executeQuery( TString( \
bq->toString(), true ),
\
::Soprano::Query::QueryLanguageUser,
\
QLatin1String( "lucene" ) );
-// Iterator< ::Soprano::Index::QueryHit> hits = d->repository->index()->search( \
bq );
int i = -1;
while ( hits.next() ) {
@@ -367,7 +357,6 @@
}
IndexedDocument result;
-// ::Soprano::Index::QueryHit hit = *hits;
result.score = hits.binding( 1 ).literal().toDouble();
if ( d->createDocument( hits.binding( 0 ), result ) ) {
results.push_back( result );
@@ -385,27 +374,34 @@
void Strigi::Soprano::IndexReader::getChildren( const std::string& parent,
std::map<std::string, time_t>& \
children ) {
-// qDebug() << "IndexReader::getChildren in thread" << QThread::currentThread();
+ //
+ // We are compatible with old Xesam data, thus the weird query
+ //
QString query = QString( "select distinct ?path ?mtime where { "
- "{ { ?r <%1> \"%2\"^^<%3> . } UNION { ?r <%1> %6 . } } \
. "
- "?r <%4> ?mtime . "
- "?r <%5> ?path . "
+ "{ ?r <http://strigi.sf.net/ontologies/0.9#parentUrl> \
%1 . } " + "UNION "
+ "{ ?r <http://strigi.sf.net/ontologies/0.9#parentUrl> \
%2 . } " + "UNION "
+ "{ ?r %3 %2 . } . "
+ "{ ?r %4 ?mtime . } UNION { ?r %5 ?mtime . } "
+ "{ ?r %6 ?path . } UNION { ?r %7 ?path . } "
"}")
- .arg( Util::fieldUri( FieldRegister::parentLocationFieldName \
).toString(),
- escapeLiteralForSparqlQuery( QString::fromUtf8( \
parent.c_str() ) ),
- Vocabulary::XMLSchema::string().toString(),
- Util::fieldUri( FieldRegister::mtimeFieldName \
).toString(),
- Util::fieldUri( FieldRegister::pathFieldName ).toString(),
- Node( QUrl::fromLocalFile( QFile::decodeName( \
parent.c_str() ) ) ).toN3() ); + .arg( Node::literalToN3( \
QString::fromUtf8( parent.c_str() ) ), + Node::resourceToN3( \
QUrl::fromLocalFile( QFile::decodeName( parent.c_str() ) ) ), + \
Node::resourceToN3( Nepomuk::Vocabulary::NIE::isPartOf() ), + \
Node::resourceToN3( Vocabulary::Xesam::sourceModified() ), + \
Node::resourceToN3( Nepomuk::Vocabulary::NIE::lastModified() ), + \
Node::resourceToN3( Vocabulary::Xesam::url() ), + \
Node::resourceToN3( Nepomuk::Vocabulary::NIE::url() ) );
-// qDebug() << "running getChildren query:" << query;
+ qDebug() << "running getChildren query:" << query;
QueryResultIterator result = d->repository->executeQuery( query, \
::Soprano::Query::QueryLanguageSparql );
while ( result.next() ) {
Node pathNode = result.binding( "path" );
Node mTimeNode = result.binding( "mtime" );
-// qDebug() << "file in index: " << pathNode.toString() << "mtime:" << \
mTimeNode.literal().toDateTime() << "(" << \
mTimeNode.literal().toDateTime().toTime_t() << ")"; + qDebug() << "file in \
index: " << pathNode.toString() << "mtime:" << mTimeNode.literal().toDateTime() << \
"(" << mTimeNode.literal().toDateTime().toTime_t() << ")";
// be backwards compatible in case there are paths left encoded as literals
std::string path;
@@ -450,12 +446,17 @@
time_t Strigi::Soprano::IndexReader::mTime( const std::string& uri )
{
-// qDebug() << "IndexReader::mTime in thread" << QThread::currentThread();
- QString query = QString( "select ?mtime where { ?r <%2> \"%3\"^^<%4> . ?r <%1> \
?mtime . }" )
- .arg( Util::fieldUri( FieldRegister::mtimeFieldName \
).toString(),
- Util::fieldUri( FieldRegister::pathFieldName ).toString(),
- escapeLiteralForSparqlQuery( QString::fromUtf8( \
uri.c_str() ) ),
- Vocabulary::XMLSchema::string().toString() );
+ //
+ // We are compatible with old Xesam data, thus the weird query
+ //
+ QString query = QString( "select ?mtime where { "
+ "{ ?r %1 %2 . } UNION { ?r %3 %2 . } "
+ "{ ?r %4 ?mtime . } UNION { ?r %5 ?mtime . } }" )
+ .arg( Node::resourceToN3( Vocabulary::Xesam::url() ),
+ Node::resourceToN3( Nepomuk::Vocabulary::NIE::url() ),
+ Node::literalToN3( QString::fromUtf8( uri.c_str() ) ),
+ Node::resourceToN3( Vocabulary::Xesam::sourceModified() ),
+ Node::resourceToN3( \
Nepomuk::Vocabulary::NIE::lastModified() ) );
qDebug() << "mTime( " << uri.c_str() << ") query:" << query;
--- trunk/KDE/kdebase/runtime/nepomuk/strigibackend/sopranoindexwriter.cpp \
#1000645:1000646 @@ -234,11 +234,9 @@
Strigi::Soprano::IndexWriter::IndexWriter( ::Soprano::Model* model )
: Strigi::IndexWriter()
{
-// qDebug() << "IndexWriter::IndexWriter in thread" << QThread::currentThread();
d = new Private;
d->repository = model;
Util::storeStrigiMiniOntology( d->repository );
-// qDebug() << "IndexWriter::IndexWriter done in thread" << \
QThread::currentThread(); }
@@ -256,21 +254,21 @@
// delete all indexed data for the files listed in entries
void Strigi::Soprano::IndexWriter::deleteEntries( const std::vector<std::string>& \
entries ) {
-// qDebug() << "IndexWriter::deleteEntries in thread" << \
QThread::currentThread();
-
- QString systemLocationUri = Util::fieldUri( FieldRegister::pathFieldName \
).toString(); for ( unsigned int i = 0; i < entries.size(); ++i ) {
QString path = QString::fromUtf8( entries[i].c_str() );
QString query = QString( "select ?g ?mg where { "
- "{ { ?r <%1> \"%2\"^^<%3> . } UNION { ?r <%1> %6 . \
} } . "
- "?g <%4> ?r . "
- "OPTIONAL { ?mg <%5> ?g . } }" )
- .arg( systemLocationUri )
- .arg( path )
- .arg( Vocabulary::XMLSchema::string().toString() )
- .arg( Strigi::Ontology::indexGraphFor().toString() )
- .arg( Vocabulary::NRL::coreGraphMetadataFor().toString() )
- .arg( Node( QUrl::fromLocalFile( path ) ).toN3() );
+ "{ ?r \
<http://strigi.sf.net/ontologies/0.9#parentUrl> %1 . } " + \
"UNION " + "{ ?r \
<http://strigi.sf.net/ontologies/0.9#parentUrl> %2 . } " + \
"UNION " + "{ ?r %3 %2 . } . "
+ "?g %4 ?r . "
+ "OPTIONAL { ?mg %5 ?g . } }" )
+ .arg( Node::literalToN3( path ),
+ Node::resourceToN3( QUrl::fromLocalFile( path ) ),
+ Node::resourceToN3( \
Nepomuk::Vocabulary::NIE::isPartOf() ), + \
Node::resourceToN3( Strigi::Ontology::indexGraphFor() ), + \
Node::resourceToN3( Vocabulary::NRL::coreGraphMetadataFor() ) );
qDebug() << "deleteEntries query:" << query;
@@ -296,10 +294,8 @@
void Strigi::Soprano::IndexWriter::deleteAllEntries()
{
-// qDebug() << "IndexWriter::deleteAllEntries in thread" << \
QThread::currentThread();
-
// query all index graphs (FIXME: would a type derived from nrl:Graph be better \
than only the predicate?)
- QString query = QString( "select ?g where { ?g <%1> ?r . }" ).arg( \
Strigi::Ontology::indexGraphFor().toString() ); + QString query = QString( "select \
?g where { ?g %1 ?r . }" ).arg( Node::resourceToN3( Strigi::Ontology::indexGraphFor() \
) );
qDebug() << "deleteAllEntries query:" << query;
@@ -326,7 +322,6 @@
return;
}
-// qDebug() << "IndexWriter::startAnalysis in thread" << \
QThread::currentThread(); FileMetaData* data = new FileMetaData();
data->fileUri = createResourceUri( idx );
@@ -341,8 +336,6 @@
data->context = d->createUrn();
}
-// qDebug() << "Starting analysis for" << data->fileUri << "in thread" << \
QThread::currentThread();
-
idx->setWriterData( data );
d->currentResult = idx;
@@ -442,7 +435,6 @@
return;
}
-// qDebug() << "IndexWriter::addValue in thread" << QThread::currentThread();
FileMetaData* md = reinterpret_cast<FileMetaData*>( idx->writerData() );
RegisteredFieldData* rfd = reinterpret_cast<RegisteredFieldData*>( \
field->writerData() );
@@ -455,7 +447,6 @@
rfd->property,
val,
md->context) );
-// qDebug() << "IndexWriter::addValue done in thread" << \
QThread::currentThread(); }
@@ -467,7 +458,6 @@
return;
}
-// qDebug() << "IndexWriter::addValue in thread" << QThread::currentThread();
FileMetaData* md = reinterpret_cast<FileMetaData*>( idx->writerData() );
RegisteredFieldData* rfd = reinterpret_cast<RegisteredFieldData*>( \
field->writerData() );
@@ -475,7 +465,6 @@
rfd->property,
LiteralValue( value ),
md->context) );
-// qDebug() << "IndexWriter::addValue done in thread" << \
QThread::currentThread(); }
@@ -487,7 +476,6 @@
return;
}
-// qDebug() << "IndexWriter::addValue in thread" << QThread::currentThread();
FileMetaData* md = reinterpret_cast<FileMetaData*>( idx->writerData() );
RegisteredFieldData* rfd = reinterpret_cast<RegisteredFieldData*>( \
field->writerData() );
@@ -495,7 +483,6 @@
rfd->property,
LiteralValue( value ),
md->context) );
-// qDebug() << "IndexWriter::addValue done in thread" << \
QThread::currentThread(); }
@@ -532,7 +519,6 @@
return;
}
-// qDebug() << "IndexWriter::finishAnalysis in thread" << \
QThread::currentThread(); FileMetaData* md = static_cast<FileMetaData*>( \
idx->writerData() );
if ( md->content.length() > 0 ) {
@@ -585,8 +571,6 @@
// cleanup
delete md;
idx->setWriterData( 0 );
-
-// qDebug() << "IndexWriter::finishAnalysis done in thread" << \
QThread::currentThread(); }
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic