From 2bb79128d62441fe5d7ba607fba097ee9e8564db Mon Sep 17 00:00:00 2001
From: cariaso <cariaso@promethease.com>
Date: Thu, 11 Aug 2016 06:57:45 +0000
Subject: [PATCH] Cope with .ask() having more than 50 results

---
 mwclient/client.py | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/mwclient/client.py b/mwclient/client.py
index 9349d70..7d39ac4 100644
--- a/mwclient/client.py
+++ b/mwclient/client.py
@@ -908,9 +908,19 @@ class Site(object):
         Ask a query against Semantic MediaWiki.
 
         API doc: https://semantic-mediawiki.org/wiki/Ask_API
+
+        Returns:
+            Generator for retrieving all search results
         """
         kwargs = {}
         if title is None:
             kwargs['title'] = title
-        result = self.raw_api('ask', query=query, **kwargs)
-        return result['query']['results']
+
+        offset = 0
+        while offset is not None:
+            results = self.raw_api('ask', query='{query}|offset={offset}'.format(
+                query=query, offset=offset), **kwargs)
+
+            offset = results.get('query-continue-offset')
+            for result in results['query']['results']:
+                yield result
-- 
GitLab