From 09a96e5cd94086c49911ad4dcdc277eb34e78123 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 18 Aug 2017 04:01:16 -0400 Subject: [PATCH] Adjustments to Analyze User --- api/User.py | 24 ++++++++++-------------- api/api.py | 2 +- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/api/User.py b/api/User.py index cb799a8..e3aefd6 100644 --- a/api/User.py +++ b/api/User.py @@ -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 diff --git a/api/api.py b/api/api.py index 4d5a62f..8089ab8 100755 --- a/api/api.py +++ b/api/api.py @@ -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())