[Nepomuk] Result sorting with Nepomuk Querylib
Vishesh Handa
handa.vish at gmail.com
Sun Sep 18 20:00:08 UTC 2011
On Mon, Sep 19, 2011 at 12:52 AM, Sebastian Trüg <trueg at kde.org> wrote:
> 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
>
:D
>
> This is what you do:
>
> ComparisonTerm term(NAO::lastModified(), Term());
> term.setSortWeight(1, Qt::DescendingOrder);
> Query query = ResourceTypeTerm(PIMO::Note()) && term;
>
>
Now, why would anybody in their right mind think of using a ComparisonTerm,
when one is not comparing anything?
It would be so much easier to have something like -
Query q( term );
q.addSortProperty( NAO::lastModified(), Qt::DescendingOrder ); // the weight
is optional
> 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
>
--
Vishesh Handa
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/nepomuk/attachments/20110919/f0a2df5b/attachment.html>
More information about the Nepomuk
mailing list