Skip to content

Commit f859507

Browse files
committed
Merge pull request #36 from sopu/aggregationTweaks
Adds 'count' as an argument in aggregations API
2 parents 634b845 + b1c2d62 commit f859507

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

loklak.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def suggest(self, query=None, count=None, order=None, orderby=None,since=None, u
215215
return json.dumps(return_to_user)
216216

217217
def aggregations(self, query=None, since=None, until=None,
218-
fields=None, limit=None):
218+
fields=None, limit=6, count=0):
219219
"""Gives the aggregations of the application"""
220220
aggregations_application = 'api/search.json'
221221
url_to_give = self.baseUrl+aggregations_application
@@ -224,6 +224,7 @@ def aggregations(self, query=None, since=None, until=None,
224224
self.until = until
225225
self.fields = fields
226226
self.limit = limit
227+
self.count = count
227228
if query:
228229
params = {}
229230
params['query'] = self.query
@@ -232,16 +233,12 @@ def aggregations(self, query=None, since=None, until=None,
232233
if until:
233234
params['query'] = params['query']+' until:'+self.until
234235
if fields:
235-
field_string = ''
236-
for i in self.fields:
237-
field_string += i + ','
238-
params['fields'] = field_string
239-
if limit:
240-
params['limit'] = self.limit
241-
if limit is None:
242-
limit = 6
243-
params['limit'] = self.limit
244-
params['count'] = 0
236+
if isinstance(fields, list):
237+
params['fields'] = ','.join(self.fields)
238+
else:
239+
params['fields'] = self.fields
240+
241+
params['count'] = self.count
245242
params['source'] = 'cache'
246243
return_to_user = requests.get(url_to_give, params=params)
247244
if return_to_user.status_code == 200:

test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ def test_status(self):
1414
"""test status"""
1515
result = self.loklak.status()
1616

17-
self.assertTrue('index_sizes' in result)
17+
self.assertTrue('index' in result)
1818
result_properties = [
1919
'messages', 'mps', 'users', 'queries',
2020
'accounts', 'user', 'followers', 'following'
2121
]
2222
for prop in result_properties:
2323
self.assertTrue(
24-
prop in result['index_sizes'],
25-
msg='{} not found in index_sizes'.format(prop)
24+
prop in result['index'],
25+
msg='{} not found in index'.format(prop)
2626
)
2727

2828
def test_hello(self):

0 commit comments

Comments
 (0)