Skip to content

Commit

Permalink
Adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
LLkaia committed May 25, 2024
1 parent 9454fce commit 246a892
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions server/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,27 @@ async def retrieve_search_result_by_id(id_: str):
return


async def delete_search_result_by_id(id_: str):
"""Delete concrete article in a database by ID"""
try:
result = await search_results_collection.delete_one({"_id": ObjectId(id_)})
if result:
return True
except InvalidId:
pass
return False


async def retrieve_authors_count_of_articles():
"""Retrieve count of articles for each author"""
group_by_author = {"$group": {"_id": "$author", "count_of_articles": {"$sum": 1}}}
sort_by_count_desc = {"$sort": {"count_of_articles": -1}}
pipeline = [group_by_author, sort_by_count_desc]
articles_count = search_results_collection.aggregate(pipeline)
articles_count = await articles_count.to_list(length=None)
return articles_count


async def retrieve_search_results_by_tags(tags: list[str], page: int, limit: int, period: Period):
"""Find articles by tags
Expand Down

0 comments on commit 246a892

Please sign in to comment.