[Developers] Paging through result sets.
Kurt Bollacker
kurt at metaweb.com
Sun Jun 8 01:04:20 UTC 2008
On Sat, Jun 07, 2008 at 04:58:39PM -0700, Arthur van Hoff wrote:
> Hi Kendra,
>
> Currently you can only move forward, but you can keep all the old
> cursors and reuse them if you want to move back.
One trick that might work is to use reverse sorts.
If your query sorts the results (e.g. by timestamp), you could create
a "backward" page query by constraining on the the sorted value and
use a reverse sort on the page of results. For example, if you're getting
people sorted by their creation date in pages of size 10:
{"query":
[
{
"id" : null,
"limit" : 10,
"name" : null,
"sort" : "timestamp",
"timestamp" : null,
"type" : "/people/person"
}
],
"cursor":null}
If the timestamp of the first person of a page of results is:
"2008-06-07T15:16:05.0029Z", then the query:
{"query":
[
{
"id" : null,
"limit" : 10,
"name" : null,
"sort" : "-timestamp",
"timestamp" : null,
"timestamp<" : "2008-06-07T15:16:05.0029Z",
"type" : "/people/person"
}
],
"cursor":null}
would get the previous page. The only caveat is that you'd have to
reverse the order of display.
Hope this helps.. Kurt :-)
> I've asked if the cursor could include the current offset and an
> approximate result set size. It would be great if you could specify the
> cursor offset so that you can seek through the result set at random.
> This would allow you to move backwards more easily. Not sure if this
> will get implemented.
>
>
>
> From: developers-bounces at freebase.com
> [mailto:developers-bounces at freebase.com] On Behalf Of Kendra Kuhl
> Sent: Saturday, June 07, 2008 2:40 PM
> To: 'For discussions about MQL,Freebase API and apps built on Freebase'
> Subject: [Developers] Paging through result sets.
>
>
>
> I'm attempting to create some system of paging through result sets
> retrieved from Freebase. I am using a cursor to move forward through the
> result set, but can't figure out how to move backwards through the
> result set (without some difficulty). I've looked through the
> documentation and the mailing list archive and didn't find a solution.
> Does mql offer some kind of page, offset, skip parameter? Or a back /
> forward for the cursor? I saw the offset reserved keyword, but can't
> find any documentation on how to use it or figure out if it even does
> what I think it does.
>
>
>
> Thanks in advance,
>
>
>
> Kendra
>
> _______________________________________________
> Developers mailing list
> Developers at freebase.com
> http://lists.freebase.com/mailman/listinfo/developers
More information about the Developers
mailing list