Skip to content

Commit

Permalink
Adjustments to Analyze User
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Aug 18, 2017
1 parent d7bc2b0 commit 09a96e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
24 changes: 10 additions & 14 deletions api/User.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,28 @@


class Analyze:
def on_get(self, req, resp):
def on_get(self, req, resp, author):
start = time.time()
params = req.params
searchURL = 'http://mars:9200/rc/comments/_search'
nested_dict = lambda: defaultdict(nested_dict)
q = nested_dict()
size = 25
size = 2500
sort_direction = 'desc'
q['query']['bool']['filter'] = []
q['size'] = size

if 'limit' in params:
params['size'] = params['limit']

if 'size' in params and params['size'] is not None and LooksLikeInt(params['size']):
size = 500 if int(params['size']) > 500 else int(params['size'])
q['size'] = size
else:
q['size'] = 25

if 'author' in params and params['author'] is not None:
if author is not None:
terms = nested_dict()
terms['terms']['author'] = [params['author'].lower()]
terms['terms']['author'] = [author.lower()]
q['query']['bool']['filter'].append(terms)

q['size'] = size
q['sort']['score'] = sort_direction
q['sort']['created_utc'] = sort_direction

q['aggs']['created_utc']['date_histogram']['field'] = 'created_utc'
q['aggs']['created_utc']['date_histogram']['interval'] = "day"
q['aggs']['created_utc']['date_histogram']['order']['_key'] = 'asc'

q['aggs']['subreddit']['terms']['field'] = 'subreddit.keyword'
q['aggs']['subreddit']['terms']['size'] = size
Expand Down
2 changes: 1 addition & 1 deletion api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
api.add_route('/reddit/search/comment', Comment.search())
api.add_route('/reddit/search/submission', Submission.search())
api.add_route('/reddit/submission/search', Submission.search())
api.add_route('/reddit/analyze/user', User.Analyze())
api.add_route('/reddit/analyze/user/{author}', User.Analyze())
api.add_route('/get/comment_ids/{submission_id}', Submission.getCommentIDs())
api.add_route('/reddit/submission/comment_ids/{submission_id}', Submission.getCommentIDs())

0 comments on commit 09a96e5

Please sign in to comment.