Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
#71, esgf search additional fix, covered case where it's more than tw…
Browse files Browse the repository at this point in the history
…o responses
  • Loading branch information
Krzysztof (Chris) Bernat committed Dec 9, 2016
1 parent 90e7a14 commit 177c915
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cate/ds/esa_cci_odp.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,16 @@ def _fetch_solr_json(base_url, query_args, offset=0, limit=10000, timeout=10):
Return JSON value read from paginated Solr web-service.
"""
combined_json_dict = None
num_found = -1
while True:
paging_query_args = dict(query_args or {})
paging_query_args.update(offset=offset, limit=limit, format='application/solr+json')
url = base_url + '?' + urllib.parse.urlencode(paging_query_args)
with urllib.request.urlopen(url, timeout=timeout) as response:
json_text = response.read()
json_dict = json.loads(json_text.decode('utf-8'))
num_found = json_dict.get('response', {}).get('numFound', 0)
if num_found is -1:
num_found = json_dict.get('response', {}).get('numFound', 0)
if not combined_json_dict:
combined_json_dict = json_dict
if num_found < limit:
Expand All @@ -117,8 +119,6 @@ def _fetch_solr_json(base_url, query_args, offset=0, limit=10000, timeout=10):
docs = json_dict.get('response', {}).get('docs', [])
combined_json_dict.get('response', {}).get('docs', []).extend(docs)
if num_found < offset + limit:
break
else:
break
offset += limit
return combined_json_dict
Expand Down

0 comments on commit 177c915

Please sign in to comment.