Search code examples
apisearchlimitmediawiki-api

MediaWiki API: return less results from a generator than the default of 10


The following link returns information for 10 pages.

http://en.wikipedia.org/w/api.php?action=query&generator=search&gsrsearch=Skydive&format=json&gsrprop=snippet&prop=info&inprop=url&rawcontinue

How do I get this query to return information for just one page?

Setting ptlimit, cmlimit, ect ... to 1 give me the following error.

Unrecognized parameter ptlimit

The gsroffset defaults to 10. I tried putting this parameter into the query but it just added whatever number I put to 10.


Solution

  • You used generator=search, so you have to check the parameters in API:Search where you discover it's called srlimit; prefix a g because you use it as generator, that gives a gsrlimit=1.

    https://en.wikipedia.org/w/api.php?action=query&generator=search&gsrsearch=Skydive&format=json&gsrprop=snippet&prop=info&inprop=url&rawcontinue&gsrlimit=1

    {"query-continue":{"search":{"gsroffset":1}},"query":{"pages":{"19723982":{"pageid":19723982,"ns":0,"title":"Parachuting","index":1,"contentmodel":"wikitext","pagelanguage":"en","touched":"2015-07-21T16:28:32Z","lastrevid":670810888,"length":44466,"fullurl":"https://en.wikipedia.org/wiki/Parachuting","editurl":"https://en.wikipedia.org/w/index.php?title=Parachuting&action=edit","canonicalurl":"https://en.wikipedia.org/wiki/Parachuting"}}}}