Limit and offset
-
-
I figured enough that you can use "limit" reserved to get the first few results of a query,
say for some query
"limit" : 5
this fetches the first five ,
how do I fetch the next 5
-
You use cursors. Ask for cursor:null in your first query. It will come back with a token filled in; pass that back to get the next set of results and a new cursor.
-
Can you explain this a little further, please? I tried the query :
{
"cursor" : null,
"limit" : 5,
"name" : null,
"type" : "/music/artist"
}and I got an error saying that cursor was a reserved word.
Thanks
-
Wouldn't using the 'offset' reserved word be a more elegant (and intuitive for those with experience in databases) method of implementing this?
-
Sorry; the cursor needs to go in the query envelope, not the query itself. See §4.7 of the API doc:
{
"cursor":null,
"query" : {
"limit" : 5,
"name" : null,
"type" : "/music/artist"
}
}
The cursor is not the same as offset; we don’t currently have arbitrary offset support. The cursor must be sent back to the server to get the next page of results; a query can’t yet skip forward an arbitrary number of results.
-
Hi,
I'd like to use the cursors to paginate my result but I haven't found any good documentation/example about how to use them... The parameter I need are the convential 'page' and 'per_page',
for 'per_page' parameter I'm using use 'limit',
How can I use the cursor to fetch the right offset of result?
-
Marco: paginated results is a future feature which a lot of people have been asking for. I believe it requires changes to our underlying graph database (we do not use an RDBMS, it's something completely different). When it's done and released, you can bet we'll be publicising the fact broadly, so stay tuned. For now, cursors are the only way to handle this.
-
Thanks Skud for your fast replay!
Could you please show me an example or give me a link to a tutorial about how to handle this using cursors?
thanks!
-
Hi Macro79, recently our graph database got support for pages.
You just need to use the 'page' and 'limit' keywords in your mql query, here's the first page:
http://api.freebase.com/api/service/mqlread?query={"page":0,"query":[{"name":null,"type":"/music/artist","limit":5}]}
The new Query Editor supports pages in the 'envelope' options: http://www.freebase.com/app/queryeditor
-