[Developers] cursors, limits, MJT and chocolates
Darin Wilson
darin at metaweb.com
Mon Jul 9 19:23:12 UTC 2007
> Extra Belgian chocolates if somebody has an example of using the
> cursor feature with MJT.
That's some good incentive. ;-)
Below is a crude example. Cursors aren't in the official MJT docs, so
I discovered this method by looking at the mjt source. Some of the
implementation details could change (and Nix please correct me if
this is not the right way to do this).
Note the "mjt.if='q.result.length > 0'" in the "ready" block.
Normally, "next_cursor" will be null if there are no more results to
read, but there is currently a known bug that prevents this from
working correctly. Getting an empty result is the only way to be sure
you've reached the end.
I hope this helps,
Darin
-----------------------------------------------------------
(headers omitted for brevity)
<body onload="mjt.run()" style="display:none">
<div mjt.script="" mjt.strip="1">
var query = {
'id':null,
'name':null,
'type':'/music/artist',
'limit':20
}
var query_args = {}
if (mjt.urlquery.cursor != null) {
// use the cursor returned in the previous result
query_args.cursor = mjt.urlquery.cursor
}
</div>
<div mjt.task="q">
mjt.mqlread([query], query_args)
</div>
<div mjt.choose="q.state">
<div mjt.when="ready">
<div mjt.if="q.result.length > 0">
<h4>music artists in freebase:</h4>
<ul>
<li mjt.for="artist in q.result">
$artist.name
</li>
</ul>
<a href="?cursor=$q.next_cursor">next --></a>
</div>
<div mjt.else="">
end of result set
</div>
</div>
<div mjt.when="wait">
loading...
</div>
<div mjt.when="error">
error:
<div mjt.for="msg in q.messages">
$msg.message
</div>
</div>
</div>
</body>
More information about the Developers
mailing list