[Nepomuk] Result sorting with Nepomuk Querylib
Sebastian Trüg
trueg at kde.org
Sun Sep 18 19:22:37 UTC 2011
On 09/18/2011 07:36 PM, Vishesh Handa wrote:
> Hey Sebastian
>
> I was working on my note taking application, and I want all the
> resources which are notes. So, I did this -
>
> Nepomuk::Query::ResourceTypeTerm typeTerm( Nepomuk::Types::Class(
> PIMO::Note() ) );
> Nepomuk::Query::Query query( typeTerm );
>
> which was fine. Then I realized that I wanted the notes to be sorted
> according to the last modification date.
>
> Currently, I'm doing this -
>
> Nepomuk::Query::ResourceTypeTerm typeTerm( Nepomuk::Types::Class(
> PIMO::Note() ) );
> Nepomuk::Query::Query query( typeTerm );
>
> Nepomuk::Query::Query::RequestProperty rp( NAO::lastModified(), false );
> query.addRequestProperty( rp );
>
> QString sparql = query.toSparqlQuery() + " order by desc(?reqProp1)";
Ahhhhhh, my eyes, I think I am blind!!!!!! :P
This is what you do:
ComparisonTerm term(NAO::lastModified(), Term());
term.setSortWeight(1, Qt::DescendingOrder);
Query query = ResourceTypeTerm(PIMO::Note()) && term;
and if you want the value of the date simply add:
term.setVariableName(QLatin1String("date"));
and fetch it through Result::additionalBindings.
Actually you can read it here:
http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk/html/classNepomuk_1_1Query_1_1ComparisonTerm.html#_details
Cheers,
Sebastian
> client->sparqlQuery( sparql );
>
> Is it possible that you forgot to implement sorting in the query lib?
> Cause I can't seem to find how to do it.
>
> --
> Vishesh Handa
More information about the Nepomuk
mailing list