You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ponymail.apache.org by GitBox <gi...@apache.org> on 2021/09/18 23:55:55 UTC

[GitHub] [incubator-ponymail-foal] sebbASF commented on a change in pull request #60: Add in monthly activity in the search results

sebbASF commented on a change in pull request #60:
URL: https://github.com/apache/incubator-ponymail-foal/pull/60#discussion_r711657033



##########
File path: server/plugins/messages.py
##########
@@ -445,26 +445,36 @@ async def get_years(session, query_defuzzed):
             {"bool": {"should": [{"term": {"private": False}}, {"terms": {"list_raw": private_lists_accessible}}]}}
         ]
 
-    # Get oldest and youngest doc in single scan
+    # Get oldest and youngest doc in single scan, as well as a monthly histogram
     res = await session.database.search(
         index=session.database.dbs.mbox,
         size=0,
         body={"query": {"bool": query_defuzzed},
             "aggs": {
                 "first": {"min": {"field": "epoch"}},
                 "last": {"max": {"field": "epoch"}},
+                "active_months": {
+                    "date_histogram": {
+                        "field": "date",
+                        "calendar_interval": "month",
+                        "format": "yyyy-MM"
+                    }
+                }
             },
         }
     )
 
     oldest = datetime.datetime.fromtimestamp(0)
     youngest = datetime.datetime.fromtimestamp(0)
+    monthly_activity = {}
     if res["aggregations"]:
         aggs = res["aggregations"]
         oldest = datetime.datetime.fromtimestamp(aggs["first"]["value"] or 0)
         youngest = datetime.datetime.fromtimestamp(aggs["last"]["value"] or 0)
+        for bucket in aggs["active_months"].get("buckets", []):
+            monthly_activity[bucket["key_as_string"]] = bucket["doc_count"]

Review comment:
       Maybe skip buckets with 0 count?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@ponymail.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org